public virtual void AddProduct(Product product, double quantity, double discount = 0) { var orderDetails = new OrderDetails {Orders = this}; orderDetails.SetProduct(product, quantity, discount); TotalValue += orderDetails.TotalPrice; OrderDetails.Add(orderDetails); }
public virtual void SetProduct(Product product, double quantity, double discount = 0) { Product = product; Quantity = quantity; Discount = discount; TotalPrice = product.Price*quantity - discount; }
public virtual bool RemoveProduct(Product product) { var orderDetails = OrderDetails.First(c => c.Product == product); if (orderDetails == null) { return false; } OrderDetails.Remove(orderDetails); TotalValue -= orderDetails.TotalPrice; return true; }