|
|
@ -38,15 +38,103 @@ namespace Sevomin.WebFrontend.Controllers |
|
|
|
_httpContext = httpContext; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<ActionResult> NewJob() |
|
|
|
private async Task<Job> GetEmptyJob() |
|
|
|
{ |
|
|
|
User u = await UserManager.FindByNameAsync(User.Identity.Name); |
|
|
|
if (u == null) |
|
|
|
throw new InvalidOperationException("شما خیلی هنرمندی! به ما هم بگو چجوری!"); |
|
|
|
Avalin avalin = (Avalin)u; |
|
|
|
Job job = _JobRepository.GetEmptyJobFor(avalin); |
|
|
|
return job; |
|
|
|
} |
|
|
|
|
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
[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()); |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
jp.Moscow = moscow; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |