-
-
Save dcomartin/53df8bfe9457ff303bc52af6a5b06636 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 class Shipment | |
| { | |
| [Key] | |
| public int ShipmentId { get; private set; } | |
| [Column("BookedDateTime")] | |
| public DateTime Booked { get; set; } | |
| public DateTime LastUpdated { get; set; } | |
| public string LastUpdatedByUserId { get; set; } | |
| public Shipper Shipper { get; private set; } | |
| public ICollection<Stop> Stops { get; } = new List<Stop>(); | |
| public Shipment(int shipmentId, Shipper shipper, string lastUpdatedByUserId) | |
| { | |
| ShipmentId = shipmentId; | |
| Shipper = shipper; | |
| LastUpdatedByUserId = lastUpdatedByUserId; | |
| } | |
| public bool IsComplete() | |
| { | |
| return Stops.All(x => x.Status == StopStatus.Departed); | |
| } | |
| public void Arrive(Guid stopId) | |
| { | |
| var currentStop = Stops.SingleOrDefault(x => x.StopId == stopId); | |
| if (currentStop == null) | |
| { | |
| throw new InvalidOperationException("Stop does not exist."); | |
| } | |
| var previousStopsAreNotDeparted = Stops.Any(x => x.Sequence < currentStop.Sequence && x.Status != StopStatus.Departed); | |
| if (previousStopsAreNotDeparted) | |
| { | |
| throw new InvalidOperationException("Previous stops have not departed."); | |
| } | |
| currentStop.Arrive(); | |
| } | |
| public void Pickup(Guid stopId) | |
| { | |
| var currentStop = Stops.SingleOrDefault(x => x.StopId == stopId); | |
| if (currentStop == null) | |
| { | |
| throw new InvalidOperationException("Stop does not exist."); | |
| } | |
| if (currentStop.StopType == StopType.Pickup) | |
| { | |
| throw new InvalidOperationException("Stop is not a pickup."); | |
| } | |
| currentStop.Depart(); | |
| } | |
| public void Deliver(Guid stopId) | |
| { | |
| var currentStop = Stops.SingleOrDefault(x => x.StopId == stopId); | |
| if (currentStop == null) | |
| { | |
| throw new InvalidOperationException("Stop does not exist."); | |
| } | |
| if (currentStop.StopType == StopType.Delivery) | |
| { | |
| throw new InvalidOperationException("Stop is not a delivery."); | |
| } | |
| currentStop.Depart(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment