public void AddOrderItem(Product product, int quantity, decimal realPrice) { var item = this.Items.Where(n => n.ProductId == product.Id).FirstOrDefault(); if (item != null) { item.Quantity += quantity; } else { item = new SaleOrderItem() { ProductId = product.Id, ProductName = product.Name, SalePrice = product.SalePrice, Quantity = quantity, ProductCode = product.Code, SaleOrderId = this.Id, RealPrice = realPrice, }; } this.Items.Add(item); // 计算订单总金额 this.OrderAmount += item.RealPrice * quantity; }
public void AddOrderItem(Product product, int quantity, decimal realPrice) { if (quantity > 1000) { throw new AppException(string.Format("商品{0}单次购买数量不能过大", product.Name)); } var item = this.Items.Where(n => n.ProductId == product.Id).FirstOrDefault(); if (item != null) { item.Quantity += quantity; } else { item = new SaleOrderItem() { ProductId = product.Id, ProductName = product.Name, SalePrice = product.SalePrice, Quantity = quantity, ProductCode = product.Code, SaleOrderId = this.Id, RealPrice = realPrice, }; } this.Items.Add(item); // 计算订单总金额 this.OrderAmount += item.RealPrice * quantity; }