public ActionResult BodySearch(int?workid, int?cityid, string key, List <string> selectcategory, List <string> selectlocation, List <string> selectkill, int?minsalary, int?maxsalary, int?level, int?page) { var result = db.DangTinViecLams.Where(x => x.Tinhtrang == 1 && x.Trangthai == 1 && (x.Vieclamtotnhat == 1 || x.Vieclamgoiy == 1)).OrderByDescending(x => x.Ngaydang).ToList(); var datasearch = db.DangTinViecLams.Where(x => x.Tinhtrang == 1 && x.Trangthai == 1 && x.Vieclamgoiy != 1 && x.Vieclamtotnhat != 1).OrderByDescending(x => x.Ngaydang).ToList(); result.AddRange(datasearch); if (workid != null && workid != -1) { result = result.Where(x => x.Manghanh1 == workid || x.Manghanh2 == workid || x.Manghanh3 == workid).ToList(); var skill = db.SkillWorks.Where(x => x.MAN == workid).ToList(); List <KyNang> listkn = new List <KyNang>(); foreach (var item in skill) { KyNang kn = new KyNang(); kn.TenKN = db.KyNangs.Where(x => x.MAKN == item.MAKN).Select(x => x.TenKN).FirstOrDefault(); listkn.Add(kn); } ViewBag.Skill = listkn; ViewData["workid"] = workid; } if (cityid != null && cityid != -1) { result = result.Where(x => x.MaTP1 == cityid || x.MaTP2 == cityid || x.MaTP3 == cityid).ToList(); } if (key != null && key != "") { string keynot = RemoveUnicode2(key); keynot = keynot.Trim(); string[] keylist = keynot.Split(new char[] { ' ', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in result) { int count = 0; foreach (string i in keylist) { if (RemoveUnicode2(item.TenCV).IndexOf(i) > -1) { count += 1; item.Maxkinhnghiem = count; } if (item.Tags1 != null && RemoveUnicode2(item.Tags1).IndexOf(i) > -1) { count += 1; item.Maxkinhnghiem = count; } if (item.Tags2 != null && RemoveUnicode2(item.Tags2).IndexOf(i) > -1) { count += 1; item.Maxkinhnghiem = count; } if (item.Tags3 != null && RemoveUnicode2(item.Tags3).IndexOf(i) > -1) { count += 1; item.Maxkinhnghiem = count; } if (item.Capbac != null && RemoveUnicode2(item.Capbac).IndexOf(i) > -1) { count += 1; item.Maxkinhnghiem = count; } if (RemoveUnicode2(item.CongTy.Tencongty).IndexOf(i) > -1) { count += 1; item.Maxkinhnghiem = count; } } } int keylenght = keylist.Count(); if (keylist.Count() >= 4) { keylenght = 4; } result = (from re in result where re.Maxkinhnghiem >= keylenght orderby re.Maxkinhnghiem descending, re.MACV descending select re).ToList(); //result = result.Where(x =>(x.TenCV!=null&&x.TenCV.IndexOf(key)>-1) || (x.Tags1 != null && x.Tags1.Contains(key)) || (x.Tags2 != null && x.Tags2.Contains(key)) || (x.Tags3!=null&&x.Tags3.Contains(key)) || (x.Capbac!=null&&x.Capbac.Contains(key))).ToList(); } if (maxsalary != null && minsalary == null) { result = result.Where(x => x.Maxluong >= maxsalary).ToList(); } else if (maxsalary != null && minsalary != null) { result = result.Where(x => x.Minluong >= minsalary && x.Maxluong <= maxsalary).ToList(); } if (level != null) { result = result.Where(x => x.MACB == level).ToList(); } if (selectcategory != null) { List <JobCategory> listcate = new List <JobCategory>(); foreach (string item in selectcategory) { JobCategory ca = new JobCategory(); int categoryid = Int32.Parse(item); result = result.Where(x => x.Manghanh1 == categoryid || x.Manghanh2 == categoryid || x.Manghanh3 == categoryid).ToList(); ca.Id = categoryid; listcate.Add(ca); } Session["Listcategory"] = listcate; } else { Session["Listcategory"] = null; } if (selectlocation != null) { List <JobCity> listcate = new List <JobCity>(); foreach (string item in selectlocation) { JobCity ca = new JobCity(); int categoryid = Int32.Parse(item); result = result.Where(x => x.MaTP1 == categoryid || x.MaTP2 == categoryid || x.MaTP3 == categoryid).ToList(); ca.Id = categoryid; listcate.Add(ca); } Session["Listcity"] = listcate; } else { Session["Listcity"] = null; } if (selectkill != null) { List <JobSkill> listskill = new List <JobSkill>(); foreach (string item in selectkill) { JobSkill sk = new JobSkill(); result = result.Where(x => x.Tags1 == item || x.Tags2 == item || x.Tags3 == item).ToList(); sk.Name = item; listskill.Add(sk); } Session["Listskill"] = listskill; } else { Session["Listskill"] = null; } int pagenumber; string htmlleft = ""; string htmlcity = ""; string htmlskill = ""; //duyet danh sach nghanh nghe , thanh pho , skill, cap bac if (page == null) { List <JobCategory> listnghe = new List <JobCategory>(); List <JobCity> listcity = new List <JobCity>(); List <JobSkill> listskill = new List <JobSkill>(); foreach (var item in result) { if (item.Manghanh1 != null) { if (!listnghe.Exists(x => x.Id == item.Manghanh1)) { JobCategory nn = new JobCategory(); nn.Id = int.Parse(item.Manghanh1.ToString()); nn.Count = result.Where(x => x.Manghanh1 == nn.Id || x.Manghanh2 == nn.Id || x.Manghanh3 == nn.Id).Count(); listnghe.Add(nn); } } if (item.Manghanh2 != null) { if (!listnghe.Exists(x => x.Id == item.Manghanh2)) { JobCategory nn = new JobCategory(); nn.Id = int.Parse(item.Manghanh2.ToString()); nn.Count = result.Where(x => x.Manghanh1 == nn.Id || x.Manghanh2 == nn.Id || x.Manghanh3 == nn.Id).Count(); listnghe.Add(nn); } } if (item.Manghanh3 != null) { if (!listnghe.Exists(x => x.Id == item.Manghanh3)) { JobCategory nn = new JobCategory(); nn.Id = int.Parse(item.Manghanh3.ToString()); nn.Count = result.Where(x => x.Manghanh1 == nn.Id || x.Manghanh2 == nn.Id || x.Manghanh3 == nn.Id).Count(); listnghe.Add(nn); } } if (item.MaTP1 != null) { if (!listcity.Exists(x => x.Id == item.MaTP1)) { JobCity ct = new JobCity(); ct.Id = int.Parse(item.MaTP1.ToString()); ct.Count = result.Where(x => x.MaTP1 == ct.Id || x.MaTP2 == ct.Id || x.MaTP3 == ct.Id).Count(); listcity.Add(ct); } } if (item.MaTP2 != null) { if (!listcity.Exists(x => x.Id == item.MaTP2)) { JobCity ct = new JobCity(); ct.Id = int.Parse(item.MaTP2.ToString()); ct.Count = result.Where(x => x.MaTP1 == ct.Id || x.MaTP2 == ct.Id || x.MaTP3 == ct.Id).Count(); listcity.Add(ct); } } if (item.MaTP3 != null) { if (!listcity.Exists(x => x.Id == item.MaTP3)) { JobCity ct = new JobCity(); ct.Id = int.Parse(item.MaTP3.ToString()); ct.Count = result.Where(x => x.MaTP1 == ct.Id || x.MaTP2 == ct.Id || x.MaTP3 == ct.Id).Count(); listcity.Add(ct); } } if (item.Tags1 != null) { if (!listskill.Exists(x => x.Name == item.Tags1)) { JobSkill ct = new JobSkill(); ct.Name = item.Tags1; ct.Count = result.Where(x => x.Tags1 == ct.Name || x.Tags2 == ct.Name || x.Tags3 == ct.Name).Count(); listskill.Add(ct); } } if (item.Tags2 != null) { if (!listskill.Exists(x => x.Name == item.Tags2)) { JobSkill ct = new JobSkill(); ct.Name = item.Tags2; ct.Count = result.Where(x => x.Tags1 == ct.Name || x.Tags2 == ct.Name || x.Tags3 == ct.Name).Count(); listskill.Add(ct); } } if (item.Tags3 != null) { if (!listskill.Exists(x => x.Name == item.Tags3)) { JobSkill ct = new JobSkill(); ct.Name = item.Tags3; ct.Count = result.Where(x => x.Tags1 == ct.Name || x.Tags2 == ct.Name || x.Tags3 == ct.Name).Count(); listskill.Add(ct); } } } ViewBag.ListSkill = listskill.OrderByDescending(x => x.Count).ToList(); htmlskill = RenderPartialViewToString(this, "_Skill", result); ViewBag.CityId = listcity.OrderByDescending(x => x.Count).ToList(); ViewBag.WorkId = listnghe.OrderByDescending(x => x.Count).ToList(); htmlcity = RenderPartialViewToString(this, "_Location", result); htmlleft = RenderPartialViewToString(this, "_Category", result); page = 1; pagenumber = 0; } else { string pagen = page.ToString(); pagenumber = (Convert.ToInt32(pagen) * 40) - 40; } int c = result.Count(); int pageajax = c / 40; if (c % 40 != 0) { pageajax++; } if (workid != null) { ViewData["workid"] = workid; } ViewData["page"] = pageajax; ViewData["curentpage"] = page; int totaljob = result.Count(); result = result.Skip(pagenumber).Take(40).ToList(); string html = RenderPartialViewToString(this, "_Searchpartial", result); return(Json(new { html = html, htmlleft = htmlleft, htmlcity = htmlcity, total = totaljob, htmlskill = htmlskill })); }
public ActionResult ShowSearch(int?workid, int?cityid, string key) { ViewBag.City = db.cities.ToList(); ViewBag.Work = db.NghanhNghes.Where(x => x.Tinhtrang == 1 && x.Idnghanhcha != 0).ToList(); var result = db.DangTinViecLams.Where(x => x.Tinhtrang == 1 && x.Trangthai == 1).ToList(); if (workid != null && workid != -1) { result = result.Where(x => x.Manghanh1 == workid || x.Manghanh2 == workid || x.Manghanh3 == workid).ToList(); var skill = db.SkillWorks.Where(x => x.MAN == workid).ToList(); List <KyNang> listkn = new List <KyNang>(); foreach (var item in skill) { KyNang kn = new KyNang(); kn.TenKN = db.KyNangs.Where(x => x.MAKN == item.MAKN).Select(x => x.TenKN).FirstOrDefault(); listkn.Add(kn); } ViewBag.Skill = listkn; } else { ViewBag.Skill = db.KyNangs.Where(x => x.Manghanh != null).Take(10); } if (cityid != null && cityid != -1) { result = result.Where(x => x.MaTP1 == cityid || x.MaTP2 == cityid || x.MaTP3 == cityid).ToList(); } if (key != null && key != "") { result = result.Where(x => (x.TenCV != null && x.TenCV.Contains(key)) || (x.Tags1 != null && x.Tags1.Contains(key)) || (x.Tags2 != null && x.Tags2.Contains(key)) || (x.Tags3 != null && x.Tags3.Contains(key)) || (x.Capbac != null && x.Capbac.Contains(key))).ToList(); } List <JobCategory> listnghe = new List <JobCategory>(); foreach (var item in result) { if (item.Manghanh1 != null) { if (!listnghe.Exists(x => x.Id == item.Manghanh1)) { JobCategory nn = new JobCategory(); nn.Id = int.Parse(item.Manghanh1.ToString()); nn.Count = result.Where(x => x.Manghanh1 == nn.Id || x.Manghanh2 == nn.Id || x.Manghanh3 == nn.Id).Count(); listnghe.Add(nn); } } if (item.Manghanh2 != null) { if (!listnghe.Exists(x => x.Id == item.Manghanh2)) { JobCategory nn = new JobCategory(); nn.Id = int.Parse(item.Manghanh2.ToString()); nn.Count = result.Where(x => x.Manghanh1 == nn.Id || x.Manghanh2 == nn.Id || x.Manghanh3 == nn.Id).Count(); listnghe.Add(nn); } } if (item.Manghanh3 != null) { if (!listnghe.Exists(x => x.Id == item.Manghanh3)) { JobCategory nn = new JobCategory(); nn.Id = int.Parse(item.Manghanh3.ToString()); nn.Count = result.Where(x => x.Manghanh1 == nn.Id || x.Manghanh2 == nn.Id || x.Manghanh3 == nn.Id).Count(); listnghe.Add(nn); } } } List <JobCity> listcity = new List <JobCity>(); foreach (var item in result) { if (item.MaTP1 != null) { if (!listcity.Exists(x => x.Id == item.MaTP1)) { JobCity ct = new JobCity(); ct.Id = int.Parse(item.MaTP1.ToString()); ct.Count = result.Where(x => x.MaTP1 == ct.Id || x.MaTP2 == ct.Id || x.MaTP3 == ct.Id).Count(); listcity.Add(ct); } } if (item.MaTP2 != null) { if (!listcity.Exists(x => x.Id == item.MaTP2)) { JobCity ct = new JobCity(); ct.Id = int.Parse(item.MaTP2.ToString()); ct.Count = result.Where(x => x.MaTP1 == ct.Id || x.MaTP2 == ct.Id || x.MaTP3 == ct.Id).Count(); listcity.Add(ct); } } if (item.MaTP3 != null) { if (!listcity.Exists(x => x.Id == item.MaTP3)) { JobCity ct = new JobCity(); ct.Id = int.Parse(item.MaTP3.ToString()); ct.Count = result.Where(x => x.MaTP1 == ct.Id || x.MaTP2 == ct.Id || x.MaTP3 == ct.Id).Count(); listcity.Add(ct); } } } if (workid == null) { ViewData["categoryid"] = 0; } else { ViewData["categoryid"] = workid; } if (cityid == null) { ViewData["locationid"] = 0; } else { ViewData["locationid"] = cityid; } ViewBag.WorkId = listnghe.OrderByDescending(x => x.Count).ToList(); ViewBag.CityId = listcity.OrderByDescending(x => x.Count).ToList(); return(View(result)); }
//Create new job public bool UpdateJob(Job job, int[] citiesidlist, int[] categoriesidlist, string skill1, string skill2, string skill3, string recruiterID) { if (job != null && job.JobID > 0 && citiesidlist != null && categoriesidlist != null && recruiterID != null && job.RecruiterID == recruiterID) { Job oldJob = this.JobRepository.GetByID(job.JobID); if (oldJob != null) { oldJob.JobTitle = job.JobTitle; oldJob.MinSalary = job.MinSalary; oldJob.MaxSalary = job.MaxSalary; oldJob.JobDescription = job.JobDescription; oldJob.JobRequirement = job.JobRequirement; oldJob.JobLevel_ID = job.JobLevel_ID; oldJob.MinSchoolLevel_ID = job.MinSchoolLevel_ID; this.JobRepository.Update(oldJob); this.Save(); //Add city IEnumerable<JobCity> oldJobcities = this.JobCityRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable(); foreach (JobCity item in oldJobcities) { this.JobCityRepository.Delete(item); } this.Save(); foreach (int index in citiesidlist) { JobCity item = new JobCity(); item.JobID = oldJob.JobID; item.CityID = index; this.JobCityRepository.Insert(item); this.Save(); } //Add category IEnumerable<JobCategory> oldJobcategories = this.JobCategoryRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable(); foreach (JobCategory item in oldJobcategories) { this.JobCategoryRepository.Delete(item); } this.Save(); foreach (int index in categoriesidlist) { JobCategory item = new JobCategory(); item.JobID = oldJob.JobID; item.CategoryID = index; this.JobCategoryRepository.Insert(item); this.Save(); } //Skill part IEnumerable<JobSkill> oldJobSkill = this.JobSkillRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable(); foreach (JobSkill item in oldJobSkill) { this.JobSkillRepository.Delete(item); } this.Save(); if (!String.IsNullOrEmpty(skill1)) { Skill s1 = this.SkillRepository.Get(skill => skill.SkillTag == skill1).SingleOrDefault(); if (s1 != null) { JobSkill tempjs1 = new JobSkill(); tempjs1.JobID = oldJob.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 = oldJob.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 = oldJob.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 = oldJob.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 = oldJob.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 = oldJob.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; } else { return false; } } else { return false; } }
//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; //} }
//Create new job public bool UpdateJob(Job job, int[] citiesidlist, int[] categoriesidlist, string skill1, string skill2, string skill3, string recruiterID) { if (job != null && job.JobID > 0 && citiesidlist != null && categoriesidlist != null && recruiterID != null && job.RecruiterID == recruiterID) { Job oldJob = this.JobRepository.GetByID(job.JobID); if (oldJob != null) { oldJob.JobTitle = job.JobTitle; oldJob.MinSalary = job.MinSalary; oldJob.MaxSalary = job.MaxSalary; oldJob.JobDescription = job.JobDescription; oldJob.JobRequirement = job.JobRequirement; oldJob.JobLevel_ID = job.JobLevel_ID; oldJob.MinSchoolLevel_ID = job.MinSchoolLevel_ID; this.JobRepository.Update(oldJob); this.Save(); //Add city IEnumerable <JobCity> oldJobcities = this.JobCityRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable(); foreach (JobCity item in oldJobcities) { this.JobCityRepository.Delete(item); } this.Save(); foreach (int index in citiesidlist) { JobCity item = new JobCity(); item.JobID = oldJob.JobID; item.CityID = index; this.JobCityRepository.Insert(item); this.Save(); } //Add category IEnumerable <JobCategory> oldJobcategories = this.JobCategoryRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable(); foreach (JobCategory item in oldJobcategories) { this.JobCategoryRepository.Delete(item); } this.Save(); foreach (int index in categoriesidlist) { JobCategory item = new JobCategory(); item.JobID = oldJob.JobID; item.CategoryID = index; this.JobCategoryRepository.Insert(item); this.Save(); } //Skill part IEnumerable <JobSkill> oldJobSkill = this.JobSkillRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable(); foreach (JobSkill item in oldJobSkill) { this.JobSkillRepository.Delete(item); } this.Save(); if (!String.IsNullOrEmpty(skill1)) { Skill s1 = this.SkillRepository.Get(skill => skill.SkillTag == skill1).SingleOrDefault(); if (s1 != null) { JobSkill tempjs1 = new JobSkill(); tempjs1.JobID = oldJob.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 = oldJob.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 = oldJob.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 = oldJob.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 = oldJob.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 = oldJob.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); } else { return(false); } } else { return(false); } }
//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 bool SaveJob(string url, string jobTitle, int page) { bool returnValue = true; try { var data = unitOfWork.Repository <Job>().FirstOrDefault(x => x.BotLink == url); if (data == null) { Uri uri = new Uri(url); WebClient client = new WebClient(); var htmlData = client.DownloadData(uri); var html = Encoding.UTF8.GetString(htmlData); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(html); Job job = new Job(); string htmlDate = doc.DocumentNode.SelectSingleNode("//div[@class='pull-left hidden-xs ml-5']").InnerHtml.Trim(); if (htmlDate != null) { htmlDate = Helper.Helper.clearHtml(htmlDate); if (htmlDate.Contains("Bugün")) { job.ReleaseDate = DateTime.Now; } else if (htmlDate.Contains("Dün")) { job.ReleaseDate = DateTime.Now.AddDays(-1); } else { returnValue = false; } } if (returnValue) { List <JobCity> jobCityList = new List <JobCity>(); HtmlNodeCollection htmlCompanyLink = doc.DocumentNode.SelectNodes("//div[@class='col-lg-10 col-xs-12']"); if (htmlCompanyLink != null) { var botLink = htmlCompanyLink.FirstOrDefault().SelectSingleNode(".//a").Attributes["href"].Value; var checkData = unitOfWork.Repository <Company>().FirstOrDefault(x => x.BotLink == botLink); if (checkData != null) { job.CompanyID = checkData.ID; } else { Company company = new Company(); company.BotLink = botLink; string htmlCompany = doc.DocumentNode.SelectSingleNode("//h6[@class='mb-5']").InnerHtml.Trim(); if (htmlCompany != null) { company.Name = Helper.Helper.clearHtml(htmlCompany); company.Link = Helper.Helper.editCharacter(company.Name); } var resultData = unitOfWork.Repository <Company>().Insert(company); unitOfWork.SaveChanges(); job.CompanyID = resultData.ID; } } HtmlNodeCollection htmlDetailData = doc.DocumentNode.SelectNodes("//ul[@class='ilan_bilgi_ozet']//li"); if (htmlDetailData != null) { foreach (var item in htmlDetailData.Where(x => x.InnerHtml.Contains("Kategori"))) { Category category = new Category(); category.Name = Helper.Helper.clearHtml(item.SelectSingleNode(".//dt").InnerHtml); category.Link = Helper.Helper.editCharacter(category.Name); category.SimilarName = category.Name; category.SimilarNameLink = category.Link; var checkData = unitOfWork.Repository <Category>().FirstOrDefault(x => x.Link == category.Link); if (checkData != null) { job.CategoryID = checkData.ID; } else { var resultData = unitOfWork.Repository <Category>().Insert(category); unitOfWork.SaveChanges(); job.CategoryID = resultData.ID; } } foreach (var item in htmlDetailData.Where(x => x.InnerHtml.Contains("Şehir / İlçe"))) { HtmlAgilityPack.HtmlDocument docCityData = new HtmlAgilityPack.HtmlDocument(); docCityData.LoadHtml(item.InnerHtml); HtmlNodeCollection htmlCityData = docCityData.DocumentNode.SelectNodes(".//dt//li"); if (htmlCityData != null) { int Counter = 0; foreach (var itemCity in htmlCityData) { JobCity jobCity = new JobCity(); var cityFullName = Helper.Helper.clearHtml(itemCity.InnerHtml); var cityName = cityFullName; var districtName = ""; if (cityFullName.Contains("-")) { string[] path = cityFullName.Split('-'); if (path != null) { cityName = path[0].ToString().Trim(); districtName = path[1].ToString().Trim(); } } if (cityName.Contains("İst.")) { cityName = cityName.Replace("İst.", "İstanbul"); } City city = new City(); city.Name = Helper.Helper.clearHtml(cityName); city.Link = Helper.Helper.editCharacter(city.Name); var CityID = 0; var DistrictID = 0; var checkData = unitOfWork.Repository <City>().FirstOrDefault(x => x.Link == city.Link); if (checkData != null) { CityID = checkData.ID; } else { var resultData = unitOfWork.Repository <City>().Insert(city); unitOfWork.SaveChanges(); CityID = resultData.ID; } District district = new District(); district.CityID = job.CityID; district.Name = Helper.Helper.clearHtml(districtName); district.Link = Helper.Helper.editCharacter(district.Name); var checkDataDistrict = unitOfWork.Repository <District>().FirstOrDefault(x => x.Link == district.Link); if (checkDataDistrict != null) { DistrictID = checkDataDistrict.ID; } else { var resultData = unitOfWork.Repository <District>().Insert(district); unitOfWork.SaveChanges(); DistrictID = resultData.ID; } if (Counter > 0) { jobCityList.Add(jobCity); } else { job.CityID = CityID; job.DistrictID = DistrictID; } Counter++; } } } foreach (var item in htmlDetailData.Where(x => x.InnerHtml.Contains("Çalışma Şekli"))) { WorkingWay workingWay = new WorkingWay(); workingWay.Name = Helper.Helper.clearHtml(item.SelectSingleNode(".//dt").InnerHtml); workingWay.Link = Helper.Helper.editCharacter(workingWay.Name); var checkData = unitOfWork.Repository <WorkingWay>().FirstOrDefault(x => x.Link == workingWay.Link); if (checkData != null) { job.WorkingWayID = checkData.ID; } else { var resultData = unitOfWork.Repository <WorkingWay>().Insert(workingWay); unitOfWork.SaveChanges(); job.WorkingWayID = resultData.ID; } } foreach (var item in htmlDetailData.Where(x => x.InnerHtml.Contains("Cinsiyet"))) { Gender gender = new Gender(); gender.Name = Helper.Helper.clearHtml(item.SelectSingleNode(".//dt").InnerHtml); gender.Link = Helper.Helper.editCharacter(gender.Name); var checkData = unitOfWork.Repository <Gender>().FirstOrDefault(x => x.Link == gender.Link); if (checkData != null) { job.GenderID = checkData.ID; } else { var resultData = unitOfWork.Repository <Gender>().Insert(gender); unitOfWork.SaveChanges(); job.GenderID = resultData.ID; } } foreach (var item in htmlDetailData.Where(x => x.InnerHtml.Contains("Yaş"))) { var ageFullName = item.SelectSingleNode(".//dt").InnerHtml; if (ageFullName.Contains("-")) { string[] path = ageFullName.Split('-'); if (path != null) { job.Age1 = Convert.ToInt32(path[0].ToString().Trim()); job.Age2 = Convert.ToInt32(path[1].ToString().Trim()); } } else { job.Age1 = Convert.ToInt32(ageFullName.ToString().Trim()); } } foreach (var item in htmlDetailData.Where(x => x.InnerHtml.Contains("Alınacak Kişi Sayısı"))) { job.CountOfPersons = Convert.ToInt32(item.SelectSingleNode(".//dt").InnerHtml); } } job.Name = jobTitle; job.Link = Helper.Helper.editCharacter(job.Name) + "-is-ilani"; job.BotLink = url; job.BotPageLink = "https://www.elemanonline.com.tr/is_ilanlari.php?sy=" + page; string htmlDetail = doc.DocumentNode.SelectSingleNode("//div[@id='ilan_metni']").InnerHtml.Trim(); if (htmlDetail != null) { job.Detail = htmlDetail; } var resultDataJob = unitOfWork.Repository <Job>().Insert(job); unitOfWork.SaveChanges(); job.Link = Helper.Helper.editCharacter(job.Name) + "-is-ilani-" + resultDataJob.ID; unitOfWork.Repository <Job>().Update(job); unitOfWork.SaveChanges(); if (jobCityList.Any()) { foreach (var item in jobCityList) { item.JobID = resultDataJob.ID; unitOfWork.Repository <JobCity>().Insert(item); } } } } } catch (Exception ex) { ex.ToString(); } return(returnValue); }