private bool CanChangeLeaveStatus(LeaveEntry leave, LeaveStatus leaveStatus, Employee actionEmployee) { switch(leaveStatus) { case LeaveStatus.Pending: return true; case LeaveStatus.Approved: return leave.CurrentApprover.EmployeeId == actionEmployee.EmployeeId; case LeaveStatus.Finalized: if(leave.LeaveStatus != LeaveStatus.Approved) { throw new ArgumentException("Cannot Finalize Leave"); } 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); }