Beispiel #1
0
        public ActionResult Edit(int personnelId, int?employmentId)
        {
            int organisationId = UserOrganisationId;

            if (employmentId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var employment = HRBusinessService.RetrievePersonnelEmployment(organisationId, personnelId, employmentId.Value);

            if (employment == null)
            {
                return(HttpNotFound());
            }
            var workingPatternDays               = HRBusinessService.RetrieveWorkingPattern(UserOrganisationId, employment.WorkingPatternId.Value)?.WorkingPatternDays.ToList();
            var absencePolices                   = HRBusinessService.RetrieveAbsencePolices(organisationId);
            var publicHolidayPolices             = HRBusinessService.RetrievePublicHolidayPolices(organisationId);
            var companyBuilding                  = HRBusinessService.RetrieveEmploymentCompanyBuilding(organisationId);
            var employmentTypes                  = HRBusinessService.RetrieveEmploymentTypes(organisationId);
            var jobTitleJobgrades                = HRBusinessService.RetrieveJobTitleJobGrade(organisationId).ToList();
            var defaultSelectedJobTitleJobgrades = jobTitleJobgrades.FirstOrDefault(e => e.JobTitleId == employment.JobTitleId && e.JobGradeId == employment.JobGradeId);
            var viewModel = new EmploymentViewModel
            {
                AbsencePolicyName             = absencePolices.FirstOrDefault(s => s.AbsencePolicyId == employment.AbsencePolicyId).Name,
                AbsencePolicy                 = new SelectList(absencePolices, "AbsencePolicyId", "Name", employment.AbsencePolicyId),
                PublicHolidayPolicy           = new SelectList(publicHolidayPolices, "PublicHolidayPolicyId", "Name", employment.PublicHolidayPolicyId),
                EmploymentType                = new SelectList(employmentTypes, "EmploymentTypeId", "Name", employment.EmploymentTypeId),
                ReportsTo                     = new SelectList(HRBusinessService.RetrieveReportsToPersonnel(organisationId, employment.PersonnelId), "PersonnelId", "Fullname", employment.ReportsToPersonnelId),
                Employment                    = employment,
                SelectedDepartmentIds         = employment.EmploymentDepartments.Select(d => d.DepartmentId).ToList(),
                SelectedTeamIds               = employment.EmploymentTeams.Select(t => t.TeamId).ToList(),
                SelectedCompanyId             = employment.CompanyId.ToString(),
                SelectedBuildingId            = employment.BuildingId.ToString(),
                EmploymentCompanyBuildinglist = companyBuilding,
                WorkingPatternDays            = workingPatternDays,
                PreviousEmployment            = HRBusinessService.RetrievePersonnelCurrentEmployment(organisationId, employment.PersonnelId),
                AbsencePolicyHasAbsence       = HRBusinessService.AbsencePolicyPersonnelEmploymentHasAbsences(organisationId, employment.EmploymentId, employment.AbsencePolicyId),
                JobTitleJobGrades             = jobTitleJobgrades,
                SelectedJobTitleId            = defaultSelectedJobTitleJobgrades.JobTitle.JobTitleId.ToString(),
                SelectedJobGradeId            = defaultSelectedJobTitleJobgrades.JobGrade.JobGradeId.ToString(),
                PreviousAbsencePolicyId       = employment.AbsencePolicyId
            };

            return(View(viewModel));
        }
Beispiel #2
0
        public ActionResult Edit(EmploymentViewModel employmentViewModel)
        {
            var organisationId = UserOrganisationId;

            if (ModelState.IsValid)
            {
                employmentViewModel.Employment = HRBusinessService.UpdateEmployment(organisationId, employmentViewModel.Employment, employmentViewModel.PreviousAbsencePolicyId, employmentViewModel.WorkingPatternDays, employmentViewModel.SelectedDepartmentIds,
                                                                                    employmentViewModel.SelectedTeamIds);
                return(RedirectToAction("Profile", "Personnel", new { id = employmentViewModel.Employment.PersonnelId }));
            }
            var employment = HRBusinessService.RetrievePersonnelEmployment(organisationId, employmentViewModel.Employment.PersonnelId, employmentViewModel.Employment.EmploymentId);

            employmentViewModel.Employment.Personnel = employment.Personnel;
            var absencePolices                   = HRBusinessService.RetrieveAbsencePolices(organisationId);
            var publicHolidayPolices             = HRBusinessService.RetrievePublicHolidayPolices(organisationId);
            var companyBuilding                  = HRBusinessService.RetrieveEmploymentCompanyBuilding(organisationId);
            var employmentTypes                  = HRBusinessService.RetrieveEmploymentTypes(organisationId);
            var jobTitleJobgrades                = HRBusinessService.RetrieveJobTitleJobGrade(organisationId).ToList();
            var defaultSelectedJobTitleJobgrades = jobTitleJobgrades.FirstOrDefault(e => e.JobTitleId == employmentViewModel.Employment.JobTitleId && e.JobGradeId == employmentViewModel.Employment.JobGradeId);
            var viewModel = new EmploymentViewModel
            {
                AbsencePolicyName             = absencePolices.FirstOrDefault(s => s.AbsencePolicyId == employmentViewModel.Employment.AbsencePolicyId).Name,
                EmploymentCompanyBuildinglist = companyBuilding,
                SelectedBuildingId            = employment.BuildingId.ToString(),
                SelectedCompanyId             = employment.CompanyId.ToString(),
                AbsencePolicy           = new SelectList(absencePolices, "AbsencePolicyId", "Name", employmentViewModel.Employment.AbsencePolicyId),
                PublicHolidayPolicy     = new SelectList(publicHolidayPolices, "PublicHolidayPolicyId", "Name", employmentViewModel.Employment.PublicHolidayPolicyId),
                ReportsTo               = new SelectList(HRBusinessService.RetrieveReportsToPersonnel(organisationId, employmentViewModel.Employment.PersonnelId), "PersonnelId", "Fullname", employmentViewModel.Employment.ReportsToPersonnelId),
                EmploymentType          = new SelectList(employmentTypes, "EmploymentTypeId", "Name", employment.EmploymentTypeId),
                Employment              = employmentViewModel.Employment,
                SelectedDepartmentIds   = employmentViewModel.SelectedDepartmentIds,
                SelectedTeamIds         = employmentViewModel.SelectedTeamIds,
                WorkingPatternDays      = employmentViewModel.WorkingPatternDays,
                AbsencePolicyHasAbsence = HRBusinessService.AbsencePolicyPersonnelEmploymentHasAbsences(organisationId, employmentViewModel.Employment.EmploymentId, employment.AbsencePolicyId),
                JobTitleJobGrades       = jobTitleJobgrades,
                SelectedJobTitleId      = defaultSelectedJobTitleJobgrades.JobTitle.JobTitleId.ToString(),
                SelectedJobGradeId      = defaultSelectedJobTitleJobgrades.JobGrade.JobGradeId.ToString(),
            };

            return(View(viewModel));
        }