Last active
May 10, 2020 19:44
-
-
Save raschmitt/6e0f499981d65acb6fd066d8fe9e151f to your computer and use it in GitHub Desktop.
Order
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 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