/// <summary> /// Approves the leave. /// </summary> /// <param name="employeeId">The employee identifier.</param> /// <param name="approverId">The approver identifier.</param> /// <param name="isApproved">if set to <c>true</c> [is approved].</param> /// <returns>The OperationOutcome.</returns> public OperationOutcome ApproveLeave(int employeeId, int approverId, bool isApproved) { var pendingLeaveOutcome = this.leaveAdapter.GetPendingLeave(employeeId); if (pendingLeaveOutcome == null) { return(OperationOutcome.CreateError("Has not pending leave to approve")); } var supervisorId = this.employeeAdapter.GetSupervisor(employeeId); if (supervisorId == null) { return(OperationOutcome.CreateError("Employee not linked to a manager / supervisor")); } if (supervisorId != approverId) { return(OperationOutcome.CreateError("You are not authorised to approve the leave.")); } var leaveBalanceOutcome = this.leaveAdapter.GetLeaveBalance(employeeId); if (leaveBalanceOutcome == null) { return(OperationOutcome.CreateError("Unexpected internal error")); } decimal latestBalance = 0; if (isApproved) { latestBalance = leaveBalanceOutcome.Balance - pendingLeaveOutcome.RequestedDays; } else { latestBalance = leaveBalanceOutcome.Balance; } var commitOutcome = this.leaveAdapter.CommitLeaveBalance(employeeId, latestBalance, isApproved); if (!commitOutcome.IsSuccessful) { return(OperationOutcome.CreateError("Unable to commit new leave. ")); } return(OperationOutcome.Success); }
/// <summary> /// Udpates the leave request. /// </summary> /// <param name="employeeId">The employee identifier.</param> /// <param name="fromDate">From date.</param> /// <param name="toDate">To date.</param> /// <param name="balance">The balance.</param> /// <param name="leaveTypeId">The leave type identifier.</param> /// <param name="comments">The comments.</param> /// <returns> /// The OperationOutcome. /// </returns> public OperationOutcome UdpateLeaveRequest(int employeeId, DateTime fromDate, DateTime toDate, decimal balance, int leaveTypeId, string comments) { var hasAvailableLeaveOutcome = this.leaveAdapter.HasAvailableLeave(employeeId); if (!hasAvailableLeaveOutcome) { return(OperationOutcome.CreateError(Errors.NoAvailableLeave)); } var fromHolidayOutcome = this.masterData.GetHoliday(fromDate); if (fromHolidayOutcome != null) { return(OperationOutcome.CreateError($"Leave request for {fromDate} fall on a holiday ({fromHolidayOutcome.Description})")); // should look through all the days of requsted leave } var toHolidayOutcome = this.masterData.GetHoliday(toDate); if (toHolidayOutcome != null) { return(OperationOutcome.CreateError($"Leave request for {toDate} fall on a holiday ({toHolidayOutcome.Description})")); } var isWeekendOutcome = this.IsWeekend(fromDate, toDate); if (isWeekendOutcome) { return(OperationOutcome.CreateError("The date selected falls on a weekend.")); } var numberofLeaveDaysRequested = this.GetNumberOfLeaveDaysRequested(fromDate, toDate); var supervisorId = this.employeeAdapter.GetSupervisor(employeeId); if (supervisorId == null) { return(OperationOutcome.CreateError("Employee not linked to a manager / supervisor")); } var addLeaveOutcome = this.leaveAdapter.UpdateLeaveRequest(employeeId, fromDate, toDate, numberofLeaveDaysRequested, balance, leaveTypeId, comments, supervisorId.Value); if (!addLeaveOutcome.IsSuccessful) { return(OperationOutcome.CreateError(Errors.InternalError)); } return(OperationOutcome.Success); }