Exemplo n.º 1
0
 public ActionResult CanApproveAbsence(int personnelId, int id)
 {
     try
     {
         var organisationId = UserOrganisationId;
         var isAdmin        = User.IsInAnyRoles("Admin");
         return(this.JsonNet(HRBusinessService.CanApproveAbsence(organisationId, id, isAdmin, ApplicationUser.Id)));
     }
     catch (Exception ex)
     {
         return(this.JsonNet(ex));
     }
 }
Exemplo n.º 2
0
        // GET: Absence/Edit/5
        //[AuthorizePersonnel(Roles = "Admin,User")]
        public ActionResult Edit(int personnelId, int id)
        {
            var  organisationId    = UserOrganisationId;
            var  personnel         = HRBusinessService.RetrievePersonnel(organisationId, personnelId);
            var  absence           = HRBusinessService.RetrieveAbsenceRange(organisationId, id);
            bool canApproveAbsence = HRBusinessService.CanApproveAbsence(organisationId, id, User.IsInRole("Admin"), ApplicationUser.Id);

            absence.CanApproveAbsence = canApproveAbsence;
            if (absence == null)
            {
                return(HttpNotFound());
            }

            var personnelAbsenceEntitlement = HRBusinessService.RetrievePersonnelAbsenceEntitlement(organisationId, personnelId, absence.PersonnelAbsenceEntitlementId);

            if (personnelAbsenceEntitlement == null)
            {
                throw new Exception("Absence entitlements may not been correctly configured, please contact your HR administrator.");
            }

            personnelAbsenceEntitlement.Personnel = personnel;
            var periodDates = HRBusinessService.RetrieveAbsencePolicyAbsencePeriods(organisationId,
                                                                                    personnelAbsenceEntitlement.AbsencePolicyPeriod.AbsencePolicyId, null, null);
            var periodsBeginDate    = periodDates.Items.Min(a => a.AbsencePeriod.StartDate).Date;
            var periodsEndDate      = periodDates.Items.Max(a => a.AbsencePeriod.EndDate).Date;
            var employmentStartDate = HRBusinessService.RetrievePersonnelEmployments(organisationId, personnelId).Min(e => e.StartDate);
            var employmentEndDate   = HRBusinessService.RetrievePersonnelAbsencePeriods(organisationId, personnelId).Max(e => e.EndDate);
            var viewModel           = new AbsenceViewModel
            {
                BeginDate    = periodsBeginDate,
                EndDate      = periodsEndDate,
                Period       = personnelAbsenceEntitlement.Period,
                Absence      = absence,
                AbsenceTypes = new SelectList(HRBusinessService.RetrieveAbsencePolicyEntitlements(organisationId, personnelAbsenceEntitlement.AbsencePolicyPeriod.AbsencePolicyId).Items.Select(s => s.AbsenceType).ToList(), "AbsenceTypeId", "Name", absence.AbsenceTypeId),
                PersonnelAbsenceEntitlement = personnelAbsenceEntitlement,
                Permissions = HRBusinessService.RetrievePersonnelPermissions(User.IsInRole("Admin"), organisationId, UserPersonnelId, personnelId),

                EmploymentBeginDate = employmentStartDate,
                EmploymentEndDate   = employmentEndDate,
                PersonnelId         = personnelId,
            };

            return(View(viewModel));
        }