private bool CanChangeLeaveStatus(LeaveEntry leave, LeaveStatus leaveStatus, Employee actionEmployee) { switch(leaveStatus) { case LeaveStatus.Pending: case LeaveStatus.AwaitingDocumentation: //Change return true; case LeaveStatus.Approved: if (this.IsSickLeaveWithoutDocumentation(leave))//Change { return false;//Change } return leave.CurrentApprover.EmployeeId == actionEmployee.EmployeeId; case LeaveStatus.Finalized: if (this.IsSickLeaveWithoutDocumentation(leave))//Change { return false;//Change } return actionEmployee.IsManager(); default: throw new ArgumentOutOfRangeException("leaveStatus"); } }
public void UpdateStatus(int leaveId, LeaveStatus leaveStatus, Employee actionEmployee) { var leave = this.leaveRepository.FindById(leaveId); if(this.CanChangeLeaveStatus(leave, leaveStatus, actionEmployee)) { leave.LeaveStatus = leaveStatus; } else { throw new Exception("Not Allowed #YOLO"); } this.leaveRepository.Update(leave); }