-
-
Save dcomartin/2e3349bb3b9102bea44bf58b1d1259c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum VacationRequestStatus | |
| { | |
| Pending, | |
| Approved, | |
| Rejected | |
| } | |
| public class Employee | |
| { | |
| public Guid Id { get; private set; } | |
| public bool IsManager { get; private set; } | |
| public Employee(Guid id, bool isManager) | |
| { | |
| Id = id; | |
| IsManager = isManager; | |
| } | |
| } | |
| public class VacationRequest | |
| { | |
| public Guid EmployeeId { get; private set; } | |
| public VacationRequestStatus Status { get; private set; } | |
| public VacationRequest(Guid employeeId) | |
| { | |
| EmployeeId = employeeId; | |
| Status = VacationRequestStatus.Pending; | |
| } | |
| public void Approve(Employee approver) | |
| { | |
| if (approver.IsManager == false) | |
| { | |
| throw new UnauthorizedAccessException("Only managers can approve vacation requests."); | |
| } | |
| if (Status != VacationRequestStatus.Pending) | |
| { | |
| throw new InvalidOperationException("Only pending requests can be approved."); | |
| } | |
| Status = VacationRequestStatus.Approved; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment