Browse Source

DovominJob

confirmation-email
J 11 years ago
parent
commit
899004c10e
8 changed files with 233 additions and 128 deletions
  1. +1
    -0
      Sevomin.Models/Dovomin.cs
  2. +92
    -0
      Sevomin.Models/DovominJob.cs
  3. +1
    -0
      Sevomin.Models/DovominParameter.cs
  4. +1
    -0
      Sevomin.Models/Job.cs
  5. +1
    -1
      Sevomin.Models/JobMiniViewModel.cs
  6. +2
    -0
      Sevomin.Models/JobParameter.cs
  7. +1
    -0
      Sevomin.Models/Sevomin.Models.csproj
  8. +134
    -127
      Sevomin.WebFrontend.Controllers/JobController.cs

+ 1
- 0
Sevomin.Models/Dovomin.cs View File

@ -18,6 +18,7 @@ namespace Sevomin.Models
public string PersianResume { get; set; }
public virtual ICollection<DovominParameter> DovominParameters { get; set; }
public virtual ICollection<DovominJob> DovominJobs { get; set; }
public Dovomin()
{


+ 92
- 0
Sevomin.Models/DovominJob.cs View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sevomin.Models
{
public class DovominJob
{
[Key]
public long Id { get; set; }
[Index("IX_DovominJobUniqueIndex", Order = 1, IsUnique = true)]
[Required]
[StringLength(128)]
public string DovominId { get; set; }
[Index]
[Index("IX_DovominJobUniqueIndex", Order = 2, IsUnique = true)]
[Required]
public long JobId { get; set; }
[Required]
public DateTime ApplyDate { get; set; }
[Required]
public string CoverLetter { get; set; }
public decimal Affinity { get; set; }
public bool MinimumRequirement { get; set; }
public DateTime? AvalinSeen { get; set; }
public string AvalinComment { get; set; }
public bool AvalinDelete { get; set; }
public virtual Dovomin Dovomin { get; set; }
public virtual Job Job { get; set; }
public DovominJob(Dovomin dovomin, Job job)
{
this.Dovomin = dovomin;
this.Job = job;
CalculateAffinity();
}
private void CalculateAffinity()
{
MinimumRequirement = true;
decimal sum = 0;
decimal count = 0;
Affinity = 0;
foreach (var jp in
Job.JobParameters.Where(x=>x.Moscow != 0 && !string.IsNullOrWhiteSpace(x.StringValue) ))
{
DovominParameter dp = Dovomin.DovominParameters.SingleOrDefault(x=>x.ParameterId == jp.ParameterId);
if (jp.Moscow == 4)
{
if (dp == null)
MinimumRequirement = false;
if ((jp.StringValue != dp.StringValue && jp.NumericValue == 0) ||
(jp.NumericValue > 0 && jp.NumericValue > dp.NumericValue))
{
MinimumRequirement = false;
}
}
count++;
decimal? dpv = dp.NumericValue;
decimal? jpv = jp.NumericValue;
decimal m = jp.Moscow / 4;
if (jpv == null)
{
if (jp.StringValue == dp.StringValue)
sum += m;
continue;
}
if (dpv == null)
continue;
if (jpv > dpv)
sum += m;
else
sum += m * ((jpv.Value - dpv.Value) / jpv.Value);
}
}
}
}

+ 1
- 0
Sevomin.Models/DovominParameter.cs View File

@ -55,5 +55,6 @@ namespace Sevomin.Models
StringValue = value;
}
}
}
}

+ 1
- 0
Sevomin.Models/Job.cs View File

@ -35,6 +35,7 @@ namespace Sevomin.Models
public bool IsFullTime { get; set; }
public virtual ICollection<JobParameter> JobParameters { get; set; }
public virtual ICollection<DovominJob> Applications { get; set; }
}
}

+ 1
- 1
Sevomin.Models/JobMiniViewModel.cs View File

@ -56,7 +56,7 @@ namespace Sevomin.Models
Parameters = new List<Tuple<string,string>>();
var jpz = job.JobParameters.Where(x=>x.NumericValue != null).OrderByDescending(x=>x.Moscow).Take(Math.Min(MaxNumberOfMiniParams * 3, job.JobParameters.Count()))
var jpz = job.JobParameters.Where(x=>!string.IsNullOrWhiteSpace(x.StringValue)).OrderByDescending(x=>x.Moscow).Take(Math.Min(MaxNumberOfMiniParams * 3, job.JobParameters.Count()))
.OrderBy(x => x.Parameter.GroupName).ThenByDescending(x => x.Moscow).Take((int)(MaxNumberOfMiniParams*1.5)).ToList();
for (int i = 0; i < jpz.Count(); i++)


+ 2
- 0
Sevomin.Models/JobParameter.cs View File

@ -57,5 +57,7 @@ namespace Sevomin.Models
StringValue = value;
}
}
}
}

+ 1
- 0
Sevomin.Models/Sevomin.Models.csproj View File

@ -62,6 +62,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Avalin.cs" />
<Compile Include="DovominJob.cs" />
<Compile Include="DovominParameterViewModel.cs" />
<Compile Include="DovominViewModel.cs" />
<Compile Include="DovominParameter.cs" />


+ 134
- 127
Sevomin.WebFrontend.Controllers/JobController.cs View File

@ -13,144 +13,151 @@ using System.Web;
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
jp.Moscow = moscow;
}
}
{
jp.Moscow = 4;
}
}
}
}
}
}

Loading…
Cancel
Save