Skip to content

Instantly share code, notes, and snippets.

@arleypadua
Last active August 22, 2018 04:10
Show Gist options
  • Save arleypadua/d0b7ce1500d436b5e35b341b4b9b105b to your computer and use it in GitHub Desktop.
Save arleypadua/d0b7ce1500d436b5e35b341b4b9b105b to your computer and use it in GitHub Desktop.
order-item-domain-model
public class OrderItem
{
private OrderItem() { }
public static OrderItem New(string productId, int quantity, decimal price, decimal discount = 0)
{
if (string.IsNullOrWhiteSpace(productId)) throw new ArgumentNullException(nameof(productId));
if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(quantity));
if (price <= 0) throw new ArgumentOutOfRangeException(nameof(price));
if (discount < 0) throw new ArgumentOutOfRangeException(nameof(discount));
if (discount > price * quantity) throw new ArgumentException("The discount cannot be more than the total of the order item.", nameof(discount));
return new OrderItem
{
ProductId = productId,
Quantity = quantity,
Price = price,
Discount = discount
};
}
public string ProductId { get; private set; }
public int Quantity { get; private set; }
public decimal Price { get; private set; }
public decimal Discount { get; private set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment