Skip to content

Instantly share code, notes, and snippets.

@raschmitt
Last active May 10, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raschmitt/6e0f499981d65acb6fd066d8fe9e151f to your computer and use it in GitHub Desktop.
Save raschmitt/6e0f499981d65acb6fd066d8fe9e151f to your computer and use it in GitHub Desktop.
Order
public class Order
{
public TimeSpan _purchaseSpanLimit = new TimeSpan(2, 0, 0);
public Guid Id { get; }
public List<Item> Items { get; }
public Order()
{
Id = Guid.NewGuid();
Items = new List<Item>();
}
public void AddItem(Item item)
{
var firstItemPurchasedAt = Items.OrderBy(i => i.PurchaseTime).FirstOrDefault()?.PurchaseTime;
var totalPurchaseSpan = item.PurchaseTime - firstItemPurchasedAt;
if (firstItemPurchasedAt == null || totalPurchaseSpan <= _purchaseSpanLimit)
Items.Add(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment