internal OrderItem(long orderId, OrderItemProduct product, int count) { this.Id = product.Id; this.OrderId = Checker.GTZero(orderId, nameof(orderId)); this.Product = Checker.NotNull(product, nameof(product)); this.Count = Checker.GTZero(count, nameof(count)); //this.Amount = product.Price * count; }
/// <summary> /// 添加订单产品 /// </summary> /// <param name="product"></param> /// <param name="count"></param> public void AddProduct(OrderItemProduct product, int count) { Checker.NotNull(product, nameof(product)); Checker.GTZero(count, nameof(count)); var existProduct = this.Items.FirstOrDefault(x => x.Product.Id == product.Id); if (existProduct == null) { this.Items.Add(new OrderItem(this.Id, product, count)); } else { existProduct.ChangeCount(count); } this.Amount += product.Price * count; }