public ActionResult Create() { JobCreateModel jobCreateModel = new JobCreateModel(); string UserID = jobUnitOfWork.AspNetUserRepository.Get(s => s.UserName == User.Identity.Name).FirstOrDefault().Id; if (jobUnitOfWork.CompanyInfoRepository.GetByID(UserID) == null) { TempData["warningmessage"] = "Xin hãy cập nhật thông tin công ty trước khi đăng tuyển!"; return RedirectToAction("Update", "CompanyInfo"); } if (!jobUnitOfWork.CheckIfCanPostJob(UserID)) { TempData["jobpackagemessage"] = "Bạn cần mua gói công việc!"; return RedirectToAction("OwnList"); } jobCreateModel.JobLevelList = jobUnitOfWork.JobLevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(s => s.LevelNum); jobCreateModel.SchoolLevelList = jobUnitOfWork.SchoolLevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(s => s.LevelNum); jobCreateModel.CityList = jobUnitOfWork.CityRepository.Get(filter: city => city.IsDeleted == false).OrderBy(s => s.Name); jobCreateModel.CategoryList = jobUnitOfWork.CategoryRepository.Get(category => category.IsDeleted == false).OrderBy(s => s.Name); jobCreateModel.SkillList = jobUnitOfWork.SkillRepository.Get(skill => skill.IsDeleted == false); jobCreateModel.JobInfo.RecruiterID = UserID; jobCreateModel.JobPackageItemSelectItemList = (from p in jobUnitOfWork.PurchaseJobPackageRepository.Get() join j in jobUnitOfWork.JobPackageRepository.Get() on p.JobPackageID equals j.JobPackageID where p.RecruiterID == UserID && p.IsApproved == true && p.IsDeleted == false && j.IsDeleted == false select new JobPackageSelectItem() { JobPackageName = j.Name, RemainJobNumber = j.JobNumber - (from jo in jobUnitOfWork.JobRepository.Get() where jo.PurchaseJobPackageId == p.PurchaseJobPackageID select jo).Count() }) .GroupBy(s => s.JobPackageName) .Select(s => new JobPackageSelectItem { JobPackageName = s.Key, RemainJobNumber = s.Sum(g => g.RemainJobNumber) }) .Where(s => s.RemainJobNumber > 0) .AsEnumerable(); return View(jobCreateModel); }
//Change model information into Topic class public Job Model_Job(JobCreateModel model, int PurchaseJobPackageId) { Job temp = new Job(); temp.RecruiterID = model.JobInfo.RecruiterID; temp.JobTitle = model.JobInfo.JobTitle; //temp.Company = model.JobInfo.Company; //temp.Address = model.JobInfo.Address; temp.MinSalary = model.JobInfo.MinSalary; temp.MaxSalary = model.JobInfo.MaxSalary; temp.JobDescription = model.JobInfo.JobDescription; temp.JobRequirement = model.JobInfo.JobRequirement; temp.JobLevel_ID = model.JobInfo.JobLevel_ID; temp.MinSchoolLevel_ID = model.JobInfo.MinSchoolLevel_ID; temp.JobView = model.JobInfo.JobView; temp.StartedDate = DateTime.Now; temp.EndedDate = DateTime.Now.AddDays(30); temp.IsPublic = model.JobInfo.IsPublic; temp.PurchaseJobPackageId = PurchaseJobPackageId; return temp; }
//Create new job public bool CreateJob(JobCreateModel model, string JobPackageName, string skill1, string skill2, string skill3, string recruiterID) { //try //{ JobPackage jobPackage = this.JobPackageRepository.Get(s => s.Name == JobPackageName).FirstOrDefault(); if (jobPackage == null) { return false; } PurchaseJobPackage purchaseJobPackage = (from p in this.PurchaseJobPackageRepository.Get() join j in this.JobPackageRepository.Get() on p.JobPackageID equals j.JobPackageID where p.RecruiterID == recruiterID && p.IsApproved == true && p.IsDeleted == false && p.JobPackageID == jobPackage.JobPackageID && (from jo in this.JobRepository.Get() where jo.PurchaseJobPackageId == p.PurchaseJobPackageID select jo).Count() < j.JobNumber select p) .AsEnumerable().FirstOrDefault(); if (purchaseJobPackage == null) { return false; } this.JobRepository.Insert(Model_Job(model, purchaseJobPackage.PurchaseJobPackageID)); this.Save(); Job temp = this.JobRepository.Get(job => job.RecruiterID == model.JobInfo.RecruiterID && job.JobTitle == model.JobInfo.JobTitle).Last(); //Add city foreach (int index in model.CitySelectList) { JobCity item = new JobCity(); item.JobID = temp.JobID; item.CityID = index; this.JobCityRepository.Insert(item); this.Save(); } //Add category foreach (int index in model.CategorySelectList) { JobCategory item = new JobCategory(); item.JobID = temp.JobID; item.CategoryID = index; this.JobCategoryRepository.Insert(item); this.Save(); } //Skill part if (!String.IsNullOrEmpty(skill1)) { Skill s1 = this.SkillRepository.Get(skill => skill.SkillTag == skill1).SingleOrDefault(); if (s1 != null) { JobSkill tempjs1 = new JobSkill(); tempjs1.JobID = temp.JobID; tempjs1.Skill_ID = s1.Skill_ID; tempjs1.IsDeleted = false; this.JobSkillRepository.Insert(tempjs1); this.Save(); } else { Skill temps1 = new Skill(); temps1.SkillTag = skill1; temps1.IsDeleted = false; this.SkillRepository.Insert(temps1); this.Save(); JobSkill tempjs1 = new JobSkill(); tempjs1.JobID = temp.JobID; tempjs1.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps1.SkillTag).LastOrDefault().Skill_ID; tempjs1.IsDeleted = false; this.JobSkillRepository.Insert(tempjs1); this.Save(); } } if (!String.IsNullOrEmpty(skill2)) { Skill s2 = this.SkillRepository.Get(skill => skill.SkillTag == skill2).SingleOrDefault(); if (s2 != null) { JobSkill tempjs2 = new JobSkill(); tempjs2.JobID = temp.JobID; tempjs2.Skill_ID = s2.Skill_ID; tempjs2.IsDeleted = false; this.JobSkillRepository.Insert(tempjs2); this.Save(); } else { Skill temps2 = new Skill(); temps2.SkillTag = skill2; temps2.IsDeleted = false; this.SkillRepository.Insert(temps2); this.Save(); JobSkill tempjs2 = new JobSkill(); tempjs2.JobID = temp.JobID; tempjs2.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps2.SkillTag).LastOrDefault().Skill_ID; tempjs2.IsDeleted = false; this.JobSkillRepository.Insert(tempjs2); this.Save(); } } if (!String.IsNullOrEmpty(skill3)) { Skill s3 = this.SkillRepository.Get(skill => skill.SkillTag == skill3).SingleOrDefault(); if (s3 != null) { JobSkill tempjs3 = new JobSkill(); tempjs3.JobID = temp.JobID; tempjs3.Skill_ID = s3.Skill_ID; tempjs3.IsDeleted = false; this.JobSkillRepository.Insert(tempjs3); this.Save(); } else { Skill temps3 = new Skill(); temps3.SkillTag = skill3; temps3.IsDeleted = false; this.SkillRepository.Insert(temps3); this.Save(); JobSkill tempjs3 = new JobSkill(); tempjs3.JobID = temp.JobID; tempjs3.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps3.SkillTag).LastOrDefault().Skill_ID; tempjs3.IsDeleted = false; this.JobSkillRepository.Insert(tempjs3); this.Save(); } } return true; //} //catch //{ // return false; //} }
public ActionResult Create(JobCreateModel model, string JobPackageName, string skill1, string skill2, string skill3) { string UserID = jobUnitOfWork.AspNetUserRepository.Get(s => s.UserName == User.Identity.Name).FirstOrDefault().Id; if (jobUnitOfWork.CreateJob(model, JobPackageName, skill1, skill2, skill3, UserID)) { TempData["successmessage"] = "Tạo đăng tuyển thành công."; } else { TempData["errormessage"] = "Tạo đăng tuyển thất bại!"; } return RedirectToAction("OwnList"); }