diff --git a/Sevomin.Models/AdViewModel.cs b/Sevomin.Models/AdViewModel.cs index d82e6f3..5fee342 100644 --- a/Sevomin.Models/AdViewModel.cs +++ b/Sevomin.Models/AdViewModel.cs @@ -1,12 +1,7 @@ using System; -using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Sevomin.Models.Helpers; namespace Sevomin.Models { diff --git a/Sevomin.Models/Repositories/AdRepository.cs b/Sevomin.Models/Repositories/AdRepository.cs index cb196d0..ff0aefc 100644 --- a/Sevomin.Models/Repositories/AdRepository.cs +++ b/Sevomin.Models/Repositories/AdRepository.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System.Collections; +using System.Collections.Generic; +using System.Linq; namespace Sevomin.Models.Repositories { @@ -57,18 +59,23 @@ namespace Sevomin.Models.Repositories SevominDbContext.Current.SaveChanges(); } - public void ChangeDays(Ad ad, int duration) + public void ChangeDays(long id, int duration) { - SevominDbContext.Current.Ads.Find(ad).Duration = duration; + Find(id).Duration = duration; Save(); } - public void ToggleActive(Ad ad) + public void ToggleActive(long id) { - SevominDbContext.Current.Ads.Find(ad).Active = !SevominDbContext.Current.Ads.Find(ad).Active; + Find(id).Active = !Find(id).Active; Save(); } + public IEnumerable GetAds() + { + return ListAll().AsEnumerable().Where(m => m.Active && m.Expired == false); + } + #endregion } } diff --git a/Sevomin.Models/Repositories/IRepository.cs b/Sevomin.Models/Repositories/IRepository.cs index e0408d5..e325d1b 100644 --- a/Sevomin.Models/Repositories/IRepository.cs +++ b/Sevomin.Models/Repositories/IRepository.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; namespace Sevomin.Models.Repositories { @@ -31,8 +32,9 @@ namespace Sevomin.Models.Repositories public interface IAdRepository : IRepository { - void ChangeDays(Ad ad, int duration); - void ToggleActive(Ad ad); + void ChangeDays(long id, int duration); + void ToggleActive(long id); IQueryable ListAll(); + IEnumerable GetAds(); } } \ No newline at end of file diff --git a/Sevomin.WebFrontend.Controllers/AccountController.cs b/Sevomin.WebFrontend.Controllers/AccountController.cs index af6dad9..def2bdc 100644 --- a/Sevomin.WebFrontend.Controllers/AccountController.cs +++ b/Sevomin.WebFrontend.Controllers/AccountController.cs @@ -108,8 +108,8 @@ namespace Sevomin.WebFrontend.Controllers if (Request.IsAuthenticated && User.Identity.Name.ToLower() != user.UserName.ToLower()) { ViewBag.Result = new PostResultViewModel(false, - string.Format("شما با نام کاربری {0} در سایت وارد شده اید. نمی توانید حساب کاربری {1} را تایید نمایید.", - User.Identity.Name, user.UserName)); + string.Format("شما نمیتوانید با حساب کاربری {0} حساب دیگری را فعال کنید", + User.Identity.Name)); return View(); } diff --git a/Sevomin.WebFrontend.Controllers/AdsController.cs b/Sevomin.WebFrontend.Controllers/AdsController.cs deleted file mode 100644 index d91a33f..0000000 --- a/Sevomin.WebFrontend.Controllers/AdsController.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Linq; -using System.Web.Mvc; -using Sevomin.Models.Repositories; - -namespace Sevomin.WebFrontend.Controllers -{ - class AdsController : Controller - { - IAdRepository _adRepository; - public AdsController() : this(AdRepository.Current) - { - } - - public AdsController(IAdRepository adRepository) - { - _adRepository = adRepository; - } - - public ActionResult Ads(int id) - { - var ad = _adRepository.ListAll().SingleOrDefault(m => m.Id == id); - if (ad == null) - { - return HttpNotFound(); - } - return Redirect(ad.Link); - } - } -} diff --git a/Sevomin.WebFrontend.Controllers/GodController.cs b/Sevomin.WebFrontend.Controllers/GodController.cs index 785efd5..640ad46 100644 --- a/Sevomin.WebFrontend.Controllers/GodController.cs +++ b/Sevomin.WebFrontend.Controllers/GodController.cs @@ -82,6 +82,14 @@ namespace Sevomin.WebFrontend.Controllers } } + [Authorize(Roles = "God")] + public ActionResult AddAd(int duration, string link, string title, string description) + { + var ad = new Ad { Active = true, CreatedDate = DateTime.Now, Description = description, Link = link, Duration = duration, Title = title }; + _adRepository.Add(ad); + return RedirectToAction("Index"); + } + [Authorize(Roles = "God")] public ActionResult AdManagementPanel() { @@ -89,29 +97,29 @@ namespace Sevomin.WebFrontend.Controllers return View(model); } + [HttpPost] [Authorize(Roles = "God")] - public ActionResult ChangeDays(long id, FormCollection form) + public ActionResult ChangeDays(long id, int days) { - var ad = _adRepository.ListAll().SingleOrDefault(m => m.Id == id); + var ad = _adRepository.Find(id); if (ad == null) { throw new NullReferenceException(); } - _adRepository.ChangeDays(ad, Convert.ToInt32(form["ChangeDays"])); - return RedirectToAction("Index"); + _adRepository.ChangeDays(id, days); + return RedirectToAction("Index", "God"); } [Authorize(Roles = "God")] public ActionResult ToggleAd(long id) { - var ad = _adRepository.ListAll().SingleOrDefault(m => m.Id == id); + var ad = _adRepository.Find(id); if (ad == null) { throw new NullReferenceException(); } - _adRepository.ToggleActive(ad); - return RedirectToAction("Index"); + _adRepository.ToggleActive(id); + return RedirectToAction("Index", "God"); } - } } \ No newline at end of file diff --git a/Sevomin.WebFrontend.Controllers/HomeController.cs b/Sevomin.WebFrontend.Controllers/HomeController.cs index ca94798..1869a98 100644 --- a/Sevomin.WebFrontend.Controllers/HomeController.cs +++ b/Sevomin.WebFrontend.Controllers/HomeController.cs @@ -1,20 +1,25 @@ -using Microsoft.AspNet.Identity.EntityFramework; +using System.Linq; +using Microsoft.AspNet.Identity.EntityFramework; using Sevomin.Models; using Sevomin.Models.Helpers; using System.Threading.Tasks; using System.Web.Mvc; +using Sevomin.Models.Repositories; namespace Sevomin.WebFrontend.Controllers { public class HomeController : BaseController { + IAdRepository _adRepository; + public HomeController() - : this(new SevominUserManager(new UserStore(SevominDbContext.Current))) + : this(AdRepository.Current, new SevominUserManager(new UserStore(SevominDbContext.Current))) { } - public HomeController(SevominUserManager userManager) + public HomeController(IAdRepository adRepositry, SevominUserManager userManager) { + _adRepository = adRepositry; UserManager = userManager; } @@ -24,17 +29,23 @@ namespace Sevomin.WebFrontend.Controllers { if (!Request.IsAuthenticated) return View("Intro"); - else - { - User user = await UserManager.FindByNameAsync(User.Identity.Name); - if (user is Avalin) - return View("AvalinIndex"); - else if (user is Dovomin) - return View("DovominIndex"); - else - return RedirectToAction("Index", "God"); - } + User user = await UserManager.FindByNameAsync(User.Identity.Name); + if (user is Avalin) + return View("AvalinIndex"); + if (user is Dovomin) + return View("DovominIndex"); + return RedirectToAction("Index", "God"); } - + + public ActionResult Ads(int id) + { + var ad = _adRepository.ListAll().SingleOrDefault(m => m.Id == id); + if (ad == null) + { + return HttpNotFound(); + } + ad.ClickCount++; + return Redirect(ad.Link); + } } } \ No newline at end of file diff --git a/Sevomin.WebFrontend.Controllers/JobController.cs b/Sevomin.WebFrontend.Controllers/JobController.cs index 16618c8..953032b 100644 --- a/Sevomin.WebFrontend.Controllers/JobController.cs +++ b/Sevomin.WebFrontend.Controllers/JobController.cs @@ -19,11 +19,12 @@ namespace Sevomin.WebFrontend.Controllers { public class JobController : AuthorizedController { + IAdRepository _adRepository; IJobRepository _jobRepository; private HttpContextBase _httpContext; public JobController() - : this(JobRepository.Current, + : this(AdRepository.Current, JobRepository.Current, new SevominUserManager(new UserStore(SevominDbContext.Current)), null) { } @@ -34,8 +35,9 @@ namespace Sevomin.WebFrontend.Controllers _httpContext = requestContext.HttpContext; } - public JobController(IJobRepository jobRepository, SevominUserManager userManager, HttpContextBase httpContext) : base(userManager) + public JobController(IAdRepository adRepository, IJobRepository jobRepository, SevominUserManager userManager, HttpContextBase httpContext) : base(userManager) { + _adRepository = adRepository; _jobRepository = jobRepository; _httpContext = httpContext; } @@ -179,6 +181,7 @@ namespace Sevomin.WebFrontend.Controllers [AllowAnonymous] public ActionResult RecentJobs() { + ViewBag.Ads = _adRepository.GetAds(); return View(_jobRepository.ListAll() .Where(d => d.ExpireDate >= DateTime.UtcNow) .OrderByDescending(d => d.CreateDate).ThenByDescending(d => d.ExpireDate) @@ -188,7 +191,8 @@ namespace Sevomin.WebFrontend.Controllers [AllowAnonymous] public PartialViewResult LatestJobList(int count) - { + { + ViewBag.Ads = _adRepository.GetAds(); return PartialView("JobList", _jobRepository.ListAll() .Where(d => d.ExpireDate >= DateTime.UtcNow) .OrderByDescending(d => d.CreateDate) diff --git a/Sevomin.WebFrontend.Controllers/Sevomin.WebFrontend.Controllers.csproj b/Sevomin.WebFrontend.Controllers/Sevomin.WebFrontend.Controllers.csproj index f43a1da..d44c2cb 100644 --- a/Sevomin.WebFrontend.Controllers/Sevomin.WebFrontend.Controllers.csproj +++ b/Sevomin.WebFrontend.Controllers/Sevomin.WebFrontend.Controllers.csproj @@ -97,7 +97,6 @@ - diff --git a/Sevomin.WebFrontend/App_Start/RouteConfig.cs b/Sevomin.WebFrontend/App_Start/RouteConfig.cs index 522c3e1..d90bb37 100644 --- a/Sevomin.WebFrontend/App_Start/RouteConfig.cs +++ b/Sevomin.WebFrontend/App_Start/RouteConfig.cs @@ -142,11 +142,12 @@ namespace Sevomin.WebFrontend #endregion #region God Mode + routes.MapRoute( name: "TurnOnGodMode", url: "god-mode/{action}", - defaults: new { controller = "God", action = "Index" } - ); + defaults: new {controller = "God", action = "Index"} + ); #endregion routes.MapRoute( diff --git a/Sevomin.WebFrontend/Views/God/AdManagementPanel.cshtml b/Sevomin.WebFrontend/Views/God/AdManagementPanel.cshtml index 1015362..9ea8961 100644 --- a/Sevomin.WebFrontend/Views/God/AdManagementPanel.cshtml +++ b/Sevomin.WebFrontend/Views/God/AdManagementPanel.cshtml @@ -1,4 +1,5 @@ -@model IQueryable +@using Sevomin.Models.Helpers +@model IQueryable @if (Model.Any()) { @@ -6,7 +7,7 @@
@@ -16,26 +17,45 @@
-
    +
      @foreach (var ad in Model.Where(m => m.Active)) {
    • -
      - @ad.Title -
      -
      - -
      - - + @using (Html.BeginForm("ChangeDays", "God", FormMethod.Post)) + { +
      +
      + @DateAssist.GetFullPersianDate(ad.CreatedDate) +
      +
      + @ad.Description +
      +
      + @ad.Title +
      +
      +
      + +
      + +
      + +
      + +
      +
      + تعداد کلیک ها: @ad.ClickCount +
      +
      + روز: @ad.Duration +
      +
      + @ad.Link +
      +
      + }
    • }
    @@ -46,20 +66,18 @@
-
    +
      @foreach (var ad in Model.Where(m => !m.Active)) {
    • -
      - @ad.Title +
      @ad.Description
      -
      - +
      + @ad.Title
    • } diff --git a/Sevomin.WebFrontend/Views/God/Index.cshtml b/Sevomin.WebFrontend/Views/God/Index.cshtml index 23fe76f..3949157 100644 --- a/Sevomin.WebFrontend/Views/God/Index.cshtml +++ b/Sevomin.WebFrontend/Views/God/Index.cshtml @@ -51,7 +51,7 @@
-

برای تست: @(HttpContext.Current.Application["ApplicationStart"] == null ? "اجرا نشده" : (DateTime.Now - (DateTime) HttpContext.Current.Application["ApplicationStart"]).Minutes.ToString())

+

برای تست: @(HttpContext.Current.Application["ApplicationStart"] == null ? "اجرا نشده" : (DateTime.Now - (DateTime)HttpContext.Current.Application["ApplicationStart"]).Minutes.ToString())

@@ -78,41 +78,43 @@
-
+
-
-
-
-
- - -
-
- - -
-
-
-
- - +
+ -
-
- - +
+
+ +
+
-
- +
+
+ +
+
+ +
+
+ +
+
-
+ }
@@ -131,25 +133,25 @@
- - - - - + + + + + - - - - - - + + + + + +
پارامترتوضیح اولینتوضیح دومین
پارامترتوضیح اولینتوضیح دومین
@param.Name -
@param.CommentAvalin
-
-
@param.CommentDovomin
-
- -
@param.Name +
@param.CommentAvalin
+
+
@param.CommentDovomin
+
+ +
@@ -167,58 +169,58 @@ .Where(a => a.Jobs != null && a.Jobs.Any(j => j.ExpireDate.Date >= DateTime.Now.Date)) .OrderByDescending(a => a.Jobs.OrderByDescending(j => j.CreateDate).First().CreateDate) .ToList()) - { - if (avalin.Jobs.Count == 0) - { - continue; - } -
- - @foreach (var job in avalin.Jobs.OrderByDescending(a => a.CreateDate)) { - if (job.Applications.Count == 0) + if (avalin.Jobs.Count == 0) { continue; } -
-
-

@((new Sevomin.Models.JobMiniViewModel(job)).JobSummary) @Html.ActionLink("مشاهده آگهی", "SingleJob", "Job", new {jobId = job.Id}, null)

-
- اطلاعات فرد پاسخگو به این آگهی: (@(string.IsNullOrWhiteSpace(job.ContactPersonName) ? "نام وارد نشده" : job.ContactPersonName) - @((string.IsNullOrWhiteSpace(job.ContactPersonEMail) ? "ایمیل وارد نشده" : job.ContactPersonEMail)) - @((string.IsNullOrWhiteSpace(job.ContactPersonPhone) ? "تلفن وارد نشده" : job.ContactPersonPhone))) -
-
- @foreach (var application in job.Applications.OrderByDescending(a => a.ApplyDate)) +
+ + @foreach (var job in avalin.Jobs.OrderByDescending(a => a.CreateDate)) { - Sevomin.Models.JobApplicationViewModel apply = new Sevomin.Models.JobApplicationViewModel(application); -
- از طرف @apply.DovominDisplayName - @if (!string.IsNullOrWhiteSpace(apply.CoverLetter)) + if (job.Applications.Count == 0) + { + continue; + } +
+
+

@((new Sevomin.Models.JobMiniViewModel(job)).JobSummary) @Html.ActionLink("مشاهده آگهی", "SingleJob", "Job", new { jobId = job.Id }, null)

+
+ اطلاعات فرد پاسخگو به این آگهی: (@(string.IsNullOrWhiteSpace(job.ContactPersonName) ? "نام وارد نشده" : job.ContactPersonName) + @((string.IsNullOrWhiteSpace(job.ContactPersonEMail) ? "ایمیل وارد نشده" : job.ContactPersonEMail)) + @((string.IsNullOrWhiteSpace(job.ContactPersonPhone) ? "تلفن وارد نشده" : job.ContactPersonPhone))) +
+
+ @foreach (var application in job.Applications.OrderByDescending(a => a.ApplyDate)) { -
پیغام متخصص:
-
@apply.CoverLetter
+ Sevomin.Models.JobApplicationViewModel apply = new Sevomin.Models.JobApplicationViewModel(application); +
+ از طرف @apply.DovominDisplayName + @if (!string.IsNullOrWhiteSpace(apply.CoverLetter)) + { +
پیغام متخصص:
+
@apply.CoverLetter
+ } + @if (apply.MinimumRequirement) + { +

این متخصص تمامی مهارت های الزامی برای این فرصت شغلی را دارد. همچنین میزان مطابقت ایشان با این فرصت شغلی، @apply.Affinity درصد است.

+ } + else + { +

این متخصص برخی مهارت های الزامی برای این فرصت شغلی را ندارد. همچنین میزان مطابقت ایشان با این فرصت شغلی، @apply.Affinity درصد است.

+ } +
} - @if (apply.MinimumRequirement) - { -

این متخصص تمامی مهارت های الزامی برای این فرصت شغلی را دارد. همچنین میزان مطابقت ایشان با این فرصت شغلی، @apply.Affinity درصد است.

- } - else - { -

این متخصص برخی مهارت های الزامی برای این فرصت شغلی را ندارد. همچنین میزان مطابقت ایشان با این فرصت شغلی، @apply.Affinity درصد است.

- } -
+
} -
+
} -
- }
@@ -248,12 +250,22 @@ commentDovomin = $(obj).text(); }); $.post('@Url.Action("UpdateParam", "God")', { paramId: paramId, commentAvalin: commentAvalin, commentDovomin: commentDovomin }) - .success(function () { - console.log('done'); - }); + .success(function () { + console.log('done'); + }); + }); + + $('#preview').on('click', function () { + $('#preview-box').remove(); + var url = $('#link-input').val(); + var title = $('#title-input').val(); + var desc = $('#description-input').val(); + $('#advertisement-panel').append('

' + title + '

' + desc + '

مشاهده سایت
'); }); }); + + diff --git a/Sevomin.WebFrontend/Views/Job/JobList.cshtml b/Sevomin.WebFrontend/Views/Job/JobList.cshtml index f67ce78..760e39a 100644 --- a/Sevomin.WebFrontend/Views/Job/JobList.cshtml +++ b/Sevomin.WebFrontend/Views/Job/JobList.cshtml @@ -1,5 +1,31 @@ -@model IList -
+@using Sevomin.Models +@model IList + +@{ + IEnumerable ads = ViewBag.Ads; + var adsExist = (ads != null && ads.Any()); +} +@if (adsExist) +{ +
+ @foreach (var ad in ads) + { +
+
+

+ @ad.Title +

+

+ @ad.Description +

+ مشاهده سایت +
+
+ } +
+} + +
@if (User.IsInRole("Avalin") && Model.Count == 0) {