예제 #1
0
        public JsonResult Save(EmployeeLeaveRequestModel employeeLeaveRequest, bool isInsert)
        {
            var leaveBalanceInformation = _employeeLeaveInformationService.GetEmployeeLeaveBalanceInformation(employeeLeaveRequest.EmployeeId);

            if (leaveBalanceInformation.Any())
            {
                var requestedLeaveTypeBalance = leaveBalanceInformation.FirstOrDefault(s => s.LeaveTypeId == employeeLeaveRequest.LeaveTypeId);
                if (requestedLeaveTypeBalance != null && requestedLeaveTypeBalance.RemainingDays > 0)
                {
                    employeeLeaveRequest.RequestDate = DateTime.Now;
                    if (isInsert)
                    {
                        employeeLeaveRequest.ApprovalStatusId = 1;

                        employeeLeaveRequest.SetCreateProperties(LoginInformation.UserInformation.Id);
                        employeeLeaveRequest.Id = _employeeLeaveRequestService.Insert(employeeLeaveRequest);
                    }
                    else
                    {
                        employeeLeaveRequest.SetUpdateProperties(LoginInformation.UserInformation.Id);
                        _employeeLeaveRequestService.Update(employeeLeaveRequest);
                    }
                    return(Json(new { Success = true, Data = employeeLeaveRequest }));
                }
            }
            return(Json(new { Success = false, Message = "You do not have sufficient leave balance of requested type." }));
        }
예제 #2
0
        public JsonResult Approve(EmployeeLeaveRequestModel employeeLeaveRequest)
        {
            var leaveBalanceInformation = _employeeLeaveInformationService.GetEmployeeLeaveBalanceInformation(employeeLeaveRequest.EmployeeId)
                                          .FirstOrDefault(s => s.LeaveTypeId == employeeLeaveRequest.LeaveTypeId);

            if (leaveBalanceInformation == null)
            {
                return(Json(new { Success = false, Message = "Requester leave information is not found." }));
            }

            var leaveRequestInformationFromDB = _employeeLeaveRequestService.GetById(employeeLeaveRequest.Id);

            if (leaveRequestInformationFromDB.ApprovalStatusId == 3 && employeeLeaveRequest.ApprovalStatusId != 3)
            {
                return(Json(new { Success = false, Message = "Request is already been approved. It's status cannot be changed." }));
            }

            var employeeInformation = _employeeService.GetById(employeeLeaveRequest.EmployeeId);

            if (employeeLeaveRequest.ApprovalStatusId == 2)
            {
                if (employeeInformation.IsDualApprovalApplied &&
                    (employeeInformation.SupervisorId != LoginInformation.UserInformation.EmployeeId ||
                     employeeInformation.ApproverId != LoginInformation.UserInformation.EmployeeId))
                {
                    return(Json(new { Success = false, Message = "You do not have any permission to approve the request." }));
                }

                if (!(leaveRequestInformationFromDB.ApprovalStatusId == 1 || leaveRequestInformationFromDB.ApprovalStatusId == 4))
                {
                    return(Json(new { Success = false, Message = "You can recommend only that requests which are in 'Requested' or 'Rejected' status." }));
                }
            }

            if (employeeLeaveRequest.ApprovalStatusId == 3)
            {
                if (employeeInformation.ApproverId != LoginInformation.UserInformation.EmployeeId)
                {
                    return(Json(new { Success = false, Message = "You do not have any permission to approve the request." }));
                }

                if (employeeInformation.IsDualApprovalApplied && leaveRequestInformationFromDB.ApprovalStatusId != 2)
                {
                    return(Json(new { Success = false, Message = "You can approve only that requests which are in 'Recommended' status." }));
                }
            }

            if (leaveBalanceInformation.RemainingDays < employeeLeaveRequest.DaysCount)
            {
                return(Json(new { Success = false, Message = "Requester does not have sufficient leave balance for the requested type." }));
            }

            employeeLeaveRequest.ApprovalDate = DateTime.Now;
            _employeeLeaveRequestService.UpdateApprovalStatus(employeeLeaveRequest);
            return(Json(new { Success = true, Data = employeeLeaveRequest }));
        }