Beispiel #1
0
        public ActionResult Edit(int?id, AbsencePolicyViewModel absencePolicyViewModel)
        {
            var organisationId = UserOrganisationId;
            var absencePolicy  =
                HRBusinessService.RetrieveAbsencePolicies(organisationId, null, null)
                .Items.FirstOrDefault(e => e.AbsencePolicyId == id);


            ValidationResult <WorkingPattern> result = null;

            absencePolicyViewModel.AbsencePolicy.OrganisationId = organisationId;
            if (absencePolicy.WorkingPatternId == null)
            {
                result = HRBusinessService.CreateAbsencePolicyWorkingPattern(organisationId, absencePolicyViewModel.AbsencePolicy, absencePolicyViewModel.WorkingPatternDays);
            }
            else
            {
                result = HRBusinessService.UpdateAbsencePolicy(organisationId, absencePolicyViewModel.AbsencePolicy, absencePolicyViewModel.WorkingPatternDays);
            }

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError("", error);
            }

            var viewModel = new AbsencePolicyViewModel
            {
                Frequencies              = new SelectList(EnumHelper.GetSelectList(typeof(Frequency.FrequencyType)), "Value", "Text", Frequency.FrequencyType.Yearly),
                AbsencePolicy            = absencePolicy,
                WorkingPatternDays       = absencePolicyViewModel.WorkingPatternDays.ToList(),
                AbsenceTypes             = absencePolicyViewModel.AbsenceTypes,
                AbsencePeriods           = absencePolicyViewModel.AbsencePeriods,
                SumOfDuration            = absencePolicyViewModel.SumOfDuration,
                AbsencePolicyEntitlement = new AbsencePolicyEntitlement()
            };

            return(View(viewModel));
        }