public ActionResult Create(EmploymentViewModel employmentViewModel) { var organisationId = UserOrganisationId; if (employmentViewModel.Employment.StartDate <= employmentViewModel.PreviousEmploymentEndDate) { ModelState.AddModelError("EmploymentError", "Employment start date should be greater than previous employment End Date"); } if (ModelState.IsValid) { HRBusinessService.CreateEmployment(organisationId, employmentViewModel.Employment, employmentViewModel.WorkingPatternDays.ToList(), employmentViewModel.SelectedDepartmentIds, employmentViewModel.SelectedTeamIds); return(RedirectToAction("Profile", "personnel", new { id = employmentViewModel.Employment.PersonnelId })); } var previousEmployment = HRBusinessService.RetrievePersonnelCurrentEmployment(organisationId, employmentViewModel.Employment.PersonnelId); var absencePolices = HRBusinessService.RetrieveAbsencePolices(organisationId); var publicHolidayPolices = HRBusinessService.RetrievePublicHolidayPolices(organisationId); var companyBuilding = HRBusinessService.RetrieveEmploymentCompanyBuilding(organisationId).ToList(); var employmentTypes = HRBusinessService.RetrieveEmploymentTypes(organisationId); var jobTitleJobgrades = HRBusinessService.RetrieveJobTitleJobGrade(organisationId).ToList(); var defaultSelectedJobTitleJobgrades = previousEmployment == null?jobTitleJobgrades.FirstOrDefault() : jobTitleJobgrades.FirstOrDefault(e => e.JobTitleId == employmentViewModel.PreviousEmployment.JobTitleId && e.JobGradeId == employmentViewModel.PreviousEmployment.JobGradeId); var viewModel = new EmploymentViewModel { EmploymentCompanyBuildinglist = companyBuilding, SelectedBuildingId = employmentViewModel.Employment.BuildingId.ToString(), SelectedCompanyId = employmentViewModel.Employment.CompanyId.ToString(), SelectedDepartmentIds = employmentViewModel.SelectedDepartmentIds, SelectedTeamIds = employmentViewModel.SelectedTeamIds, ReportsTo = new SelectList(HRBusinessService.RetrieveReportsToPersonnel(organisationId, employmentViewModel.Employment.PersonnelId), "PersonnelId", "Fullname"), EmploymentType = new SelectList(employmentTypes, "EmploymentTypeId", "Name"), AbsencePolicy = new SelectList(absencePolices, "AbsencePolicyId", "Name", previousEmployment.AbsencePolicyId), PublicHolidayPolicy = new SelectList(publicHolidayPolices, "PublicHolidayPolicyId", "Name", previousEmployment.PublicHolidayPolicyId), Employment = employmentViewModel.Employment, PreviousEmployment = previousEmployment, WorkingPatternDays = employmentViewModel.WorkingPatternDays, JobTitleJobGrades = jobTitleJobgrades, SelectedJobTitleId = defaultSelectedJobTitleJobgrades.JobTitle.JobTitleId.ToString(), SelectedJobGradeId = defaultSelectedJobTitleJobgrades.JobGrade.JobGradeId.ToString(), }; return(View(viewModel)); }