-
-
Save dcomartin/de7d44a58c39aa44389ab834716838fd 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 sealed class Shipment | |
| { | |
| public Guid Id { get; } | |
| public ShipmentStatus Status { get; private set; } = ShipmentStatus.Created; | |
| public DateTime? DispatchedAt { get; private set; } | |
| public DateTime? ArrivedAt { get; private set; } | |
| public int PalletsLoaded { get; private set; } | |
| public DateTime? EmptiedAt { get; private set; } | |
| public Shipment(Guid id) => Id = id; | |
| public void Dispatch(DateTime now) | |
| { | |
| if (Status != ShipmentStatus.Created) throw new InvalidOperationException("Can only dispatch from Created."); | |
| Status = ShipmentStatus.Dispatched; | |
| DispatchedAt = now; | |
| } | |
| public void Arrive(DateTime now) | |
| { | |
| if (Status != ShipmentStatus.Dispatched) throw new InvalidOperationException("Can only arrive from Dispatched."); | |
| Status = ShipmentStatus.Arrived; | |
| ArrivedAt = now; | |
| } | |
| public void Load(int pallets, DateTime now) | |
| { | |
| if (Status != ShipmentStatus.Arrived) throw new InvalidOperationException("Can only load after Arrived."); | |
| if (pallets <= 0) throw new InvalidOperationException("Invalid pallet count."); | |
| Status = ShipmentStatus.Loading; | |
| PalletsLoaded += pallets; | |
| } | |
| public void Empty(DateTime now) | |
| { | |
| if (Status is not (ShipmentStatus.Arrived or ShipmentStatus.Loading)) | |
| throw new InvalidOperationException("Can only empty after Arrived/Loading."); | |
| Status = ShipmentStatus.Empty; | |
| EmptiedAt = now; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment