public ActionResult Detail(string profileID) { ProDetailViewModel model = new ProDetailViewModel(); if (!String.IsNullOrEmpty(profileID)) { int profileIDNum = 0; try { profileIDNum = Int32.Parse(profileID); } catch (Exception) { TempData["errormessage"] = "Lỗi dữ liệu!"; return(RedirectToAction("Index", "Home")); } model.profile = profileUnitOfWork.ProfileRepository.GetByID(profileIDNum); if (model.profile != null && model.profile.IsDeleted == false) { AspNetUser recruiter = profileUnitOfWork.AspNetUserRepository.Get(ss => ss.UserName == User.Identity.Name).FirstOrDefault(); ViewProfile viewProfile = profileUnitOfWork.ViewProfileRepository.Get(s => s.RecruiterID == recruiter.Id && s.ProfileID == profileIDNum).FirstOrDefault(); if (viewProfile == null) { ViewProfile newViewProfile = new ViewProfile(); newViewProfile.RecruiterID = recruiter.Id; newViewProfile.ProfileID = profileIDNum; newViewProfile.ViewedDate = DateTime.Now; profileUnitOfWork.ViewProfileRepository.Insert(newViewProfile); profileUnitOfWork.Save(); } else { viewProfile.ViewedDate = DateTime.Now; profileUnitOfWork.ViewProfileRepository.Update(viewProfile); profileUnitOfWork.Save(); } model.cities = profileUnitOfWork.CityRepository.Get(filter: d => d.IsDeleted == false).OrderBy(d => d.Name).AsEnumerable(); model.schoolLevels = profileUnitOfWork.SchoolLevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(d => d.LevelNum).AsEnumerable(); model.languages = profileUnitOfWork.LanguageRepository.Get(filter: d => d.IsDeleted == false).OrderBy(d => d.Name).AsEnumerable(); model.levels = profileUnitOfWork.LevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(d => d.LevelNum).AsEnumerable(); model.jobLevels = profileUnitOfWork.JobLevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(d => d.LevelNum).AsEnumerable(); model.categories = profileUnitOfWork.CategoryRepository.Get(filter: d => d.IsDeleted == false).OrderBy(d => d.Name).AsEnumerable(); ExpectedCity expectedCity = profileUnitOfWork.ExpectedCityRepository.Get(filter: d => d.ProfileID == profileIDNum && d.IsDeleted == false).FirstOrDefault(); if (expectedCity != null) { model.expectedCity = expectedCity.CityID; } ExpectedCategory expectedCategory = profileUnitOfWork.ExpectedCategoryRepository.Get(filter: d => d.ProfileID == profileIDNum && d.IsDeleted == false).FirstOrDefault(); if (expectedCategory != null) { model.categoryID = expectedCategory.CategoryID; } model.contact = profileUnitOfWork.ContactRepository.GetByID(model.profile.JobSeekerID); model.employmentHistory = profileUnitOfWork.EmploymentHistoryRepository.Get(s => s.ProfileID == profileIDNum && s.IsDeleted == false).LastOrDefault(); model.educationHistory = profileUnitOfWork.EducationHistoryRepository.Get(s => s.ProfileID == profileIDNum && s.IsDeleted == false).LastOrDefault(); model.referencePerson = profileUnitOfWork.ReferencePersonRepository.Get(s => s.ProfileID == profileIDNum && s.IsDeleted == false).LastOrDefault(); return(View(model)); } else { TempData["errormessage"] = "Không tìm thấy thông tin hồ sơ!"; return(RedirectToAction("Index", "Home")); } } else { TempData["errormessage"] = "Dữ liệu không hợp lệ!"; return(RedirectToAction("Index", "Home")); } }
public bool UpdateCommonInfo(Profile profile, int expectedCityNum, int categoryID) { Jobseeker jobseeker = this.JobseekerRepository.GetByID(profile.JobSeekerID); if (jobseeker == null) { return false; } if (jobseeker.IsDeleted == true) { return false; } try { if (this.ProfileRepository.Get(filter: d => d.Name == profile.Name && d.JobSeekerID == profile.JobSeekerID).FirstOrDefault() == null) { // Add new this.ProfileRepository.Insert(profile); this.Save(); Profile insertedProfile = this.ProfileRepository.Get(filter: d => d.Name == profile.Name).LastOrDefault(); if (insertedProfile == null) { return false; } City city = this.CityRepository.GetByID(expectedCityNum); if (city != null) { ExpectedCity expectedCity = new ExpectedCity(); expectedCity.ProfileID = insertedProfile.ProfileID; expectedCity.CityID = city.CityID; expectedCity.IsDeleted = false; this.ExpectedCityRepository.Insert(expectedCity); this.Save(); } Category category = this.CategoryRepository.GetByID(categoryID); if (category != null) { ExpectedCategory expectedCategory = new ExpectedCategory(); expectedCategory.ProfileID = insertedProfile.ProfileID; expectedCategory.CategoryID = category.CategoryID; expectedCategory.IsDeleted = false; this.ExpectedCategoryRepository.Insert(expectedCategory); this.Save(); } } else { // Update Profile profileToUpdate = this.ProfileRepository.Get(filter: d => d.Name == profile.Name && d.JobSeekerID == profile.JobSeekerID).FirstOrDefault(); profileToUpdate.YearOfExperience = profile.YearOfExperience; profileToUpdate.HighestSchoolLevel_ID = profile.HighestSchoolLevel_ID; profileToUpdate.LanguageID = profile.LanguageID; profileToUpdate.Level_ID = profile.Level_ID; profileToUpdate.MostRecentCompany = profile.MostRecentCompany; profileToUpdate.MostRecentPosition = profile.MostRecentPosition; profileToUpdate.CurrentJobLevel_ID = profile.CurrentJobLevel_ID; profileToUpdate.ExpectedPosition = profile.ExpectedPosition; profileToUpdate.ExpectedJobLevel_ID = profile.ExpectedJobLevel_ID; profileToUpdate.ExpectedSalary = profile.ExpectedSalary; profileToUpdate.UpdatedTime = DateTime.Now; profileToUpdate.Objectives = profile.Objectives; profileToUpdate.JobSeekerID = profile.JobSeekerID; profileToUpdate.IsActive = profile.IsActive; profileToUpdate.IsDeleted = false; this.ProfileRepository.Update(profileToUpdate); this.Save(); IEnumerable<ExpectedCity> oldExpectedCities = this.ExpectedCityRepository.Get(filter: d => d.ProfileID == profileToUpdate.ProfileID).AsEnumerable(); foreach (ExpectedCity item in oldExpectedCities) { if (item.IsDeleted == false) { item.IsDeleted = true; this.ExpectedCityRepository.Update(item); this.Save(); } } ExpectedCity expectedCity = this.ExpectedCityRepository.Get(s => s.ProfileID == profileToUpdate.ProfileID && s.CityID == expectedCityNum).FirstOrDefault(); if (expectedCity != null) { expectedCity.IsDeleted = false; this.ExpectedCityRepository.Update(expectedCity); this.Save(); } else { City city = this.CityRepository.GetByID(expectedCityNum); if (city != null) { ExpectedCity newExpectedCity = new ExpectedCity(); newExpectedCity.ProfileID = profileToUpdate.ProfileID; newExpectedCity.CityID = city.CityID; newExpectedCity.IsDeleted = false; this.ExpectedCityRepository.Insert(newExpectedCity); this.Save(); } } IEnumerable<ExpectedCategory> oldExpectedCategories = this.ExpectedCategoryRepository.Get(filter: d => d.ProfileID == profileToUpdate.ProfileID).AsEnumerable(); foreach (ExpectedCategory item in oldExpectedCategories) { if (item.IsDeleted == false) { item.IsDeleted = true; this.ExpectedCategoryRepository.Update(item); this.Save(); } } ExpectedCategory expectedCategory = this.ExpectedCategoryRepository.Get(s => s.ProfileID == profileToUpdate.ProfileID && s.CategoryID == categoryID).FirstOrDefault(); if (expectedCategory != null) { expectedCategory.IsDeleted = false; this.ExpectedCategoryRepository.Update(expectedCategory); this.Save(); } else { Category category = this.CategoryRepository.GetByID(categoryID); if (category != null) { ExpectedCategory newExpectedCategory = new ExpectedCategory(); newExpectedCategory.ProfileID = profileToUpdate.ProfileID; newExpectedCategory.CategoryID = category.CategoryID; newExpectedCategory.IsDeleted = false; this.ExpectedCategoryRepository.Insert(newExpectedCategory); this.Save(); } } } } catch (DataException) { return false; } return true; }
public ActionResult Update(string profileID, string mode) { AspNetUser user = profileUnitOfWork.AspNetUserRepository.Get(s => s.UserName == User.Identity.Name).FirstOrDefault(); if ("create".Equals(mode)) { IEnumerable <Profile> profiles = profileUnitOfWork.ProfileRepository.Get(s => s.JobSeekerID == user.Id && s.IsDeleted == false).AsEnumerable(); if (profiles.Count() >= 5) { TempData["warningmessage"] = "Bạn chỉ được tạo tối đa 5 hồ sơ!"; return(RedirectToAction("List")); } } ProUpdateViewModel proUpdateViewModel = new ProUpdateViewModel(); proUpdateViewModel.cities = profileUnitOfWork.CityRepository.Get(filter: d => d.IsDeleted == false).OrderBy(d => d.Name).AsEnumerable(); proUpdateViewModel.schoolLevels = profileUnitOfWork.SchoolLevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(d => d.LevelNum).AsEnumerable(); proUpdateViewModel.languages = profileUnitOfWork.LanguageRepository.Get(filter: d => d.IsDeleted == false).OrderBy(d => d.Name).AsEnumerable(); proUpdateViewModel.levels = profileUnitOfWork.LevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(d => d.LevelNum).AsEnumerable(); proUpdateViewModel.jobLevels = profileUnitOfWork.JobLevelRepository.Get(filter: d => d.IsDeleted == false).OrderByDescending(d => d.LevelNum).AsEnumerable(); proUpdateViewModel.categories = profileUnitOfWork.CategoryRepository.Get(filter: d => d.IsDeleted == false).OrderBy(d => d.Name).AsEnumerable(); proUpdateViewModel.contact = profileUnitOfWork.ContactRepository.GetByID(profileUnitOfWork.AspNetUserRepository.Get(s => s.UserName == User.Identity.Name).FirstOrDefault().Id); if (proUpdateViewModel.contact == null) { proUpdateViewModel.contact = new Contact(); proUpdateViewModel.contact.DateofBirth = DateTime.Now; } IEnumerable <OwnSkill> ownSkillList = profileUnitOfWork.OwnSkillRepository.Get(s => s.JobSeekerID == user.Id).AsEnumerable(); proUpdateViewModel.ownSkills = ""; for (int i = 0; i < ownSkillList.Count(); i++) { if (i == 0) { proUpdateViewModel.ownSkills = profileUnitOfWork.SkillRepository.GetByID(ownSkillList.ElementAt(i).Skill_ID).SkillTag; } else { proUpdateViewModel.ownSkills += "," + profileUnitOfWork.SkillRepository.GetByID(ownSkillList.ElementAt(i).Skill_ID).SkillTag; } } proUpdateViewModel.commonInfoItem = new ProCommonInfoItem(); if (!String.IsNullOrEmpty(profileID)) { ViewBag.ButtonName = "Cập nhật"; int profileIDNum = 0; try { profileIDNum = Int32.Parse(profileID); } catch (Exception) { TempData["warningmessage"] = "Lỗi dữ liệu!"; return(RedirectToAction("List")); } Profile profile = profileUnitOfWork.ProfileRepository.GetByID(profileIDNum); if (profile != null) { if (profile.JobSeekerID != user.Id) { TempData["warningmessage"] = "Bạn không có quyền sửa hồ sơ này!"; return(RedirectToAction("List")); } ViewBag.ButtonName = "Cập nhật"; proUpdateViewModel.commonInfoItem.profile = profile; ExpectedCity expectedCity = profileUnitOfWork.ExpectedCityRepository.Get(filter: d => d.ProfileID == profileIDNum && d.IsDeleted == false).FirstOrDefault(); if (expectedCity != null) { proUpdateViewModel.commonInfoItem.expectedCity = expectedCity.CityID; } ExpectedCategory expectedCategory = profileUnitOfWork.ExpectedCategoryRepository.Get(filter: d => d.ProfileID == profileIDNum && d.IsDeleted == false).FirstOrDefault(); if (expectedCategory != null) { proUpdateViewModel.commonInfoItem.categoryID = expectedCategory.CategoryID; } EmploymentHistory employmentHistory = profileUnitOfWork.EmploymentHistoryRepository.Get(s => s.ProfileID == profileIDNum && s.IsDeleted == false).FirstOrDefault(); if (employmentHistory != null) { proUpdateViewModel.employmentHistory = employmentHistory; } else { proUpdateViewModel.employmentHistory = new EmploymentHistory(); proUpdateViewModel.employmentHistory.EmploymentHistoryID = -1; } EducationHistory educationHistory = profileUnitOfWork.EducationHistoryRepository.Get(s => s.ProfileID == profileIDNum && s.IsDeleted == false).FirstOrDefault(); if (educationHistory != null) { proUpdateViewModel.educationHistory = educationHistory; } else { proUpdateViewModel.educationHistory = new EducationHistory(); proUpdateViewModel.educationHistory.EducationHistoryID = -1; } ReferencePerson referencePerson = profileUnitOfWork.ReferencePersonRepository.Get(s => s.ProfileID == profileIDNum && s.IsDeleted == false).FirstOrDefault(); if (referencePerson != null) { proUpdateViewModel.referencePerson = referencePerson; } else { proUpdateViewModel.referencePerson = new ReferencePerson(); proUpdateViewModel.referencePerson.ReferencePersonID = -1; } } else { ViewBag.ButtonName = "Tạo mới"; proUpdateViewModel.employmentHistory = new EmploymentHistory(); proUpdateViewModel.employmentHistory.EmploymentHistoryID = -1; proUpdateViewModel.educationHistory = new EducationHistory(); proUpdateViewModel.educationHistory.EducationHistoryID = -1; proUpdateViewModel.referencePerson = new ReferencePerson(); proUpdateViewModel.referencePerson.ReferencePersonID = -1; } } else { ViewBag.ButtonName = "Tạo mới"; proUpdateViewModel.employmentHistory = new EmploymentHistory(); proUpdateViewModel.employmentHistory.EmploymentHistoryID = -1; proUpdateViewModel.educationHistory = new EducationHistory(); proUpdateViewModel.educationHistory.EducationHistoryID = -1; proUpdateViewModel.referencePerson = new ReferencePerson(); proUpdateViewModel.referencePerson.ReferencePersonID = -1; } return(View(proUpdateViewModel)); }
public bool UpdateCommonInfo(Profile profile, int expectedCityNum, int categoryID) { Jobseeker jobseeker = this.JobseekerRepository.GetByID(profile.JobSeekerID); if (jobseeker == null) { return(false); } if (jobseeker.IsDeleted == true) { return(false); } try { if (this.ProfileRepository.Get(filter: d => d.Name == profile.Name && d.JobSeekerID == profile.JobSeekerID).FirstOrDefault() == null) { // Add new this.ProfileRepository.Insert(profile); this.Save(); Profile insertedProfile = this.ProfileRepository.Get(filter: d => d.Name == profile.Name).LastOrDefault(); if (insertedProfile == null) { return(false); } City city = this.CityRepository.GetByID(expectedCityNum); if (city != null) { ExpectedCity expectedCity = new ExpectedCity(); expectedCity.ProfileID = insertedProfile.ProfileID; expectedCity.CityID = city.CityID; expectedCity.IsDeleted = false; this.ExpectedCityRepository.Insert(expectedCity); this.Save(); } Category category = this.CategoryRepository.GetByID(categoryID); if (category != null) { ExpectedCategory expectedCategory = new ExpectedCategory(); expectedCategory.ProfileID = insertedProfile.ProfileID; expectedCategory.CategoryID = category.CategoryID; expectedCategory.IsDeleted = false; this.ExpectedCategoryRepository.Insert(expectedCategory); this.Save(); } } else { // Update Profile profileToUpdate = this.ProfileRepository.Get(filter: d => d.Name == profile.Name && d.JobSeekerID == profile.JobSeekerID).FirstOrDefault(); profileToUpdate.YearOfExperience = profile.YearOfExperience; profileToUpdate.HighestSchoolLevel_ID = profile.HighestSchoolLevel_ID; profileToUpdate.LanguageID = profile.LanguageID; profileToUpdate.Level_ID = profile.Level_ID; profileToUpdate.MostRecentCompany = profile.MostRecentCompany; profileToUpdate.MostRecentPosition = profile.MostRecentPosition; profileToUpdate.CurrentJobLevel_ID = profile.CurrentJobLevel_ID; profileToUpdate.ExpectedPosition = profile.ExpectedPosition; profileToUpdate.ExpectedJobLevel_ID = profile.ExpectedJobLevel_ID; profileToUpdate.ExpectedSalary = profile.ExpectedSalary; profileToUpdate.UpdatedTime = DateTime.Now; profileToUpdate.Objectives = profile.Objectives; profileToUpdate.JobSeekerID = profile.JobSeekerID; profileToUpdate.IsActive = profile.IsActive; profileToUpdate.IsDeleted = false; this.ProfileRepository.Update(profileToUpdate); this.Save(); IEnumerable <ExpectedCity> oldExpectedCities = this.ExpectedCityRepository.Get(filter: d => d.ProfileID == profileToUpdate.ProfileID).AsEnumerable(); foreach (ExpectedCity item in oldExpectedCities) { if (item.IsDeleted == false) { item.IsDeleted = true; this.ExpectedCityRepository.Update(item); this.Save(); } } ExpectedCity expectedCity = this.ExpectedCityRepository.Get(s => s.ProfileID == profileToUpdate.ProfileID && s.CityID == expectedCityNum).FirstOrDefault(); if (expectedCity != null) { expectedCity.IsDeleted = false; this.ExpectedCityRepository.Update(expectedCity); this.Save(); } else { City city = this.CityRepository.GetByID(expectedCityNum); if (city != null) { ExpectedCity newExpectedCity = new ExpectedCity(); newExpectedCity.ProfileID = profileToUpdate.ProfileID; newExpectedCity.CityID = city.CityID; newExpectedCity.IsDeleted = false; this.ExpectedCityRepository.Insert(newExpectedCity); this.Save(); } } IEnumerable <ExpectedCategory> oldExpectedCategories = this.ExpectedCategoryRepository.Get(filter: d => d.ProfileID == profileToUpdate.ProfileID).AsEnumerable(); foreach (ExpectedCategory item in oldExpectedCategories) { if (item.IsDeleted == false) { item.IsDeleted = true; this.ExpectedCategoryRepository.Update(item); this.Save(); } } ExpectedCategory expectedCategory = this.ExpectedCategoryRepository.Get(s => s.ProfileID == profileToUpdate.ProfileID && s.CategoryID == categoryID).FirstOrDefault(); if (expectedCategory != null) { expectedCategory.IsDeleted = false; this.ExpectedCategoryRepository.Update(expectedCategory); this.Save(); } else { Category category = this.CategoryRepository.GetByID(categoryID); if (category != null) { ExpectedCategory newExpectedCategory = new ExpectedCategory(); newExpectedCategory.ProfileID = profileToUpdate.ProfileID; newExpectedCategory.CategoryID = category.CategoryID; newExpectedCategory.IsDeleted = false; this.ExpectedCategoryRepository.Insert(newExpectedCategory); this.Save(); } } } } catch (DataException) { return(false); } return(true); }