-
-
Save dcomartin/393fe18b3fc60d0f61d71335a415956e to your computer and use it in GitHub Desktop.
This file contains 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 ShipmentService | |
{ | |
private readonly ShipmentDbContext _dbContext; | |
public ShipmentService(ShipmentDbContext dbContext) | |
{ | |
_dbContext = dbContext; | |
} | |
public void Arrive(Shipment shipment, int stopId) | |
{ | |
var stop = shipment.GetStop(stopId); | |
var previousStopsAreNotDeparted = shipment.GetAllStops().Any(x => x.StopId < stop.StopId && x.Status != StopStatus.Departed); | |
if (previousStopsAreNotDeparted) | |
{ | |
throw new InvalidOperationException("Previous stops have not departed."); | |
} | |
stop.SetStatus(StopStatus.Arrived); | |
stop.SetArrivedDateTime(DateTime.UtcNow); | |
} | |
public void Pickup(Shipment shipment, int stopId) | |
{ | |
var stop = shipment.GetStop(stopId); | |
if (stop.Status != StopStatus.Arrived) | |
{ | |
throw new InvalidOperationException("Stop is not yet arrived."); | |
} | |
stop.SetStatus(StopStatus.Departed); | |
stop.SetDepartedDateTime(DateTime.UtcNow); | |
} | |
public void Deliver(Shipment shipment, int stopId) | |
{ | |
var stop = shipment.GetStop(stopId); | |
if (stop.Status != StopStatus.Arrived) | |
{ | |
throw new InvalidOperationException("Stop is not yet arrived."); | |
} | |
stop.SetStatus(StopStatus.Departed); | |
stop.SetDepartedDateTime(DateTime.UtcNow); | |
} | |
public bool IsComplete(Shipment shipment) | |
{ | |
return shipment.GetAllStops().All(x => x.Status == StopStatus.Departed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment