|
@ -13,144 +13,151 @@ using System.Web; |
|
|
|
|
|
|
|
|
namespace Sevomin.WebFrontend.Controllers |
|
|
namespace Sevomin.WebFrontend.Controllers |
|
|
{ |
|
|
{ |
|
|
public class JobController : AuthorizedController |
|
|
|
|
|
{ |
|
|
|
|
|
IJobRepository _JobRepository; |
|
|
|
|
|
public SevominUserManager UserManager { get; private set; } |
|
|
|
|
|
private HttpContextBase _httpContext; |
|
|
|
|
|
|
|
|
public class JobController : AuthorizedController |
|
|
|
|
|
{ |
|
|
|
|
|
IJobRepository _JobRepository; |
|
|
|
|
|
public SevominUserManager UserManager { get; private set; } |
|
|
|
|
|
private HttpContextBase _httpContext; |
|
|
|
|
|
|
|
|
public JobController() |
|
|
|
|
|
: this(JobRepository.Current, |
|
|
|
|
|
new SevominUserManager(new UserStore<User>(SevominDbContext.Current)), null) |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public JobController() |
|
|
|
|
|
: this(JobRepository.Current, |
|
|
|
|
|
new SevominUserManager(new UserStore<User>(SevominDbContext.Current)), null) |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected override void Initialize(System.Web.Routing.RequestContext requestContext) |
|
|
|
|
|
{ |
|
|
|
|
|
base.Initialize(requestContext); |
|
|
|
|
|
_httpContext = requestContext.HttpContext; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected override void Initialize(System.Web.Routing.RequestContext requestContext) |
|
|
|
|
|
{ |
|
|
|
|
|
base.Initialize(requestContext); |
|
|
|
|
|
_httpContext = requestContext.HttpContext; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public JobController(IJobRepository jobRepository, SevominUserManager userManager, HttpContextBase httpContext) |
|
|
|
|
|
{ |
|
|
|
|
|
_JobRepository = jobRepository; |
|
|
|
|
|
UserManager = userManager; |
|
|
|
|
|
_httpContext = httpContext; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public JobController(IJobRepository jobRepository, SevominUserManager userManager, HttpContextBase httpContext) |
|
|
|
|
|
{ |
|
|
|
|
|
_JobRepository = jobRepository; |
|
|
|
|
|
UserManager = userManager; |
|
|
|
|
|
_httpContext = httpContext; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async Task<Job> GetEmptyJob() |
|
|
|
|
|
{ |
|
|
|
|
|
User u = await UserManager.FindByNameAsync(User.Identity.Name); |
|
|
|
|
|
if (u == null) |
|
|
|
|
|
throw new InvalidOperationException("شما خیلی هنرمندی! به ما هم بگو چجوری!"); |
|
|
|
|
|
Avalin avalin = u as Avalin; |
|
|
|
|
|
if (avalin == null) |
|
|
|
|
|
throw new InvalidOperationException("جای شما که اینجا نیست!"); |
|
|
|
|
|
Job job = _JobRepository.GetEmptyJobFor(avalin); |
|
|
|
|
|
return job; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async Task<Job> GetEmptyJob() |
|
|
|
|
|
{ |
|
|
|
|
|
User u = await UserManager.FindByNameAsync(User.Identity.Name); |
|
|
|
|
|
if (u == null) |
|
|
|
|
|
throw new InvalidOperationException("شما خیلی هنرمندی! به ما هم بگو چجوری!"); |
|
|
|
|
|
Avalin avalin = u as Avalin; |
|
|
|
|
|
if (avalin == null) |
|
|
|
|
|
throw new InvalidOperationException("جای شما که اینجا نیست!"); |
|
|
|
|
|
Job job = _JobRepository.GetEmptyJobFor(avalin); |
|
|
|
|
|
return job; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public async Task<ActionResult> NewJob() |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await GetEmptyJob(); |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public async Task<ActionResult> NewJob() |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await GetEmptyJob(); |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<ActionResult> NewJob(string JalaliExpireDate, string ContactPersonName, |
|
|
|
|
|
string ContactPersonPhone, string ContactPersonEMail, bool IsFullTime, |
|
|
|
|
|
bool ShowCompanyName, string Description, bool ShowCompanyLogo, FormCollection form) |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await GetEmptyJob(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
UpdateFields(JalaliExpireDate, ContactPersonName, ContactPersonPhone, |
|
|
|
|
|
ContactPersonEMail, IsFullTime, ShowCompanyName, |
|
|
|
|
|
Description, ShowCompanyLogo, form, job); |
|
|
|
|
|
JobRepository.Current.Save(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception) |
|
|
|
|
|
{ |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
return Content("boogh: " + job.Id.ToString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<ActionResult> NewJob(string JalaliExpireDate, string ContactPersonName, |
|
|
|
|
|
string ContactPersonPhone, string ContactPersonEMail, bool IsFullTime, |
|
|
|
|
|
bool ShowCompanyName, string Description, bool ShowCompanyLogo, FormCollection form) |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await GetEmptyJob(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
UpdateFields(JalaliExpireDate, ContactPersonName, ContactPersonPhone, |
|
|
|
|
|
ContactPersonEMail, IsFullTime, ShowCompanyName, |
|
|
|
|
|
Description, ShowCompanyLogo, form, job); |
|
|
|
|
|
JobRepository.Current.Save(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception) |
|
|
|
|
|
{ |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
return Content("boogh: " + job.Id.ToString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async Task<Job> FetchJob(long id) |
|
|
|
|
|
{ |
|
|
|
|
|
User u = await UserManager.FindByNameAsync(User.Identity.Name); |
|
|
|
|
|
if (u == null) |
|
|
|
|
|
throw new InvalidOperationException("شما خیلی هنرمندی! به ما هم بگو چجوری!"); |
|
|
|
|
|
Avalin avalin = (Avalin)u; |
|
|
|
|
|
Job job = _JobRepository.Find(id); |
|
|
|
|
|
if (job == null || job.AvalinId != avalin.Id) |
|
|
|
|
|
throw new InvalidOperationException("شماره آگهی استخدام مورد نظر معتبر نیست"); |
|
|
|
|
|
return job; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async Task<Job> FetchJob(long id) |
|
|
|
|
|
{ |
|
|
|
|
|
User u = await UserManager.FindByNameAsync(User.Identity.Name); |
|
|
|
|
|
if (u == null) |
|
|
|
|
|
throw new InvalidOperationException("شما خیلی هنرمندی! به ما هم بگو چجوری!"); |
|
|
|
|
|
Avalin avalin = (Avalin)u; |
|
|
|
|
|
Job job = _JobRepository.Find(id); |
|
|
|
|
|
if (job == null || job.AvalinId != avalin.Id) |
|
|
|
|
|
throw new InvalidOperationException("شماره آگهی استخدام مورد نظر معتبر نیست"); |
|
|
|
|
|
return job; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public async Task<ActionResult> Edit(long id) |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await FetchJob(id); |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public async Task<ActionResult> Edit(long id) |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await FetchJob(id); |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<ActionResult> Edit(long id, string JalaliExpireDate, string ContactPersonName, |
|
|
|
|
|
string ContactPersonPhone, string ContactPersonEMail, bool IsFullTime, |
|
|
|
|
|
bool ShowCompanyName, string Description, bool ShowCompanyLogo, FormCollection form) |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await FetchJob(id); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
UpdateFields(JalaliExpireDate, ContactPersonName, ContactPersonPhone, |
|
|
|
|
|
ContactPersonEMail, IsFullTime, ShowCompanyName, |
|
|
|
|
|
Description, ShowCompanyLogo, form, job); |
|
|
|
|
|
JobRepository.Current.Save(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception) |
|
|
|
|
|
{ |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
return Content("boogh: " + job.Id.ToString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public PartialViewResult LatestJobList(int count) |
|
|
|
|
|
{ |
|
|
|
|
|
return PartialView("JobList", JobRepository.Current.ListAll() |
|
|
|
|
|
.Where(d => d.ExpireDate > DateTime.Now) |
|
|
|
|
|
.OrderByDescending(d => d.CreateDate) |
|
|
|
|
|
.Take(count) |
|
|
|
|
|
.ToList() |
|
|
|
|
|
.Select(j => new JobMiniViewModel(j)).ToList()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<ActionResult> Edit(long id, string JalaliExpireDate, string ContactPersonName, |
|
|
|
|
|
string ContactPersonPhone, string ContactPersonEMail, bool IsFullTime, |
|
|
|
|
|
bool ShowCompanyName, string Description, bool ShowCompanyLogo, FormCollection form) |
|
|
|
|
|
{ |
|
|
|
|
|
Job job = await FetchJob(id); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
UpdateFields(JalaliExpireDate, ContactPersonName, ContactPersonPhone, |
|
|
|
|
|
ContactPersonEMail, IsFullTime, ShowCompanyName, |
|
|
|
|
|
Description, ShowCompanyLogo, form, job); |
|
|
|
|
|
JobRepository.Current.Save(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception) |
|
|
|
|
|
{ |
|
|
|
|
|
JobViewModel jvm = new JobViewModel(job); |
|
|
|
|
|
return View(jvm); |
|
|
|
|
|
} |
|
|
|
|
|
return Content("boogh: " + job.Id.ToString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public PartialViewResult LatestJobList(int count) |
|
|
|
|
|
{ |
|
|
|
|
|
return PartialView("JobList", JobRepository.Current.ListAll() |
|
|
|
|
|
.Where(d => d.ExpireDate >= DateTime.Now) |
|
|
|
|
|
.OrderBy(d => d.ExpireDate) |
|
|
|
|
|
.Take(count) |
|
|
|
|
|
.ToList() |
|
|
|
|
|
.Select(j => new JobMiniViewModel(j)).ToList()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void UpdateFields(string JalaliExpireDate, string ContactPersonName, string ContactPersonPhone, string ContactPersonEMail, bool IsFullTime, bool ShowCompanyName, string Description, bool ShowCompanyLogo, FormCollection form, Job job) |
|
|
|
|
|
{ |
|
|
|
|
|
job.ExpireDate = DateAssist.ToMiladi(JalaliExpireDate); |
|
|
|
|
|
job.ContactPersonEMail = ContactPersonEMail; |
|
|
|
|
|
job.ContactPersonName = ContactPersonName; |
|
|
|
|
|
job.ContactPersonPhone = ContactPersonPhone; |
|
|
|
|
|
job.Description = Description; |
|
|
|
|
|
job.IsFullTime = IsFullTime; |
|
|
|
|
|
job.ShowCompanyLogo = ShowCompanyLogo; |
|
|
|
|
|
job.ShowCompanyName = ShowCompanyName; |
|
|
|
|
|
foreach (var jp in job.JobParameters) |
|
|
|
|
|
{ |
|
|
|
|
|
string value = form[string.Format("value-{0}", jp.Parameter.Id)]; |
|
|
|
|
|
byte moscow = 0; |
|
|
|
|
|
byte.TryParse(form[string.Format("moscow-{0}", jp.Parameter.Id)], out moscow); |
|
|
|
|
|
jp.SetValue(value); |
|
|
|
|
|
if (string.IsNullOrWhiteSpace(jp.StringValue)) |
|
|
|
|
|
jp.Moscow = 0; |
|
|
|
|
|
|
|
|
private static void UpdateFields(string JalaliExpireDate, string ContactPersonName, string ContactPersonPhone, string ContactPersonEMail, bool IsFullTime, bool ShowCompanyName, string Description, bool ShowCompanyLogo, FormCollection form, Job job) |
|
|
|
|
|
{ |
|
|
|
|
|
job.ExpireDate = DateAssist.ToMiladi(JalaliExpireDate); |
|
|
|
|
|
job.ContactPersonEMail = ContactPersonEMail; |
|
|
|
|
|
job.ContactPersonName = ContactPersonName; |
|
|
|
|
|
job.ContactPersonPhone = ContactPersonPhone; |
|
|
|
|
|
job.Description = Description; |
|
|
|
|
|
job.IsFullTime = IsFullTime; |
|
|
|
|
|
job.ShowCompanyLogo = ShowCompanyLogo; |
|
|
|
|
|
job.ShowCompanyName = ShowCompanyName; |
|
|
|
|
|
foreach (var jp in job.JobParameters) |
|
|
|
|
|
{ |
|
|
|
|
|
string value = form[string.Format("value-{0}", jp.Parameter.Id)]; |
|
|
|
|
|
byte moscow = 0; |
|
|
|
|
|
byte.TryParse(form[string.Format("moscow-{0}", jp.Parameter.Id)], out moscow); |
|
|
|
|
|
jp.SetValue(value); |
|
|
|
|
|
if (jp.Parameter.Moscow) |
|
|
|
|
|
{ |
|
|
|
|
|
if (string.IsNullOrWhiteSpace(jp.StringValue)) |
|
|
|
|
|
jp.Moscow = 0; |
|
|
|
|
|
else |
|
|
|
|
|
jp.Moscow = moscow; |
|
|
|
|
|
} |
|
|
else |
|
|
else |
|
|
jp.Moscow = moscow; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
jp.Moscow = 4; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |