コード例 #1
0
ファイル: Cart.cs プロジェクト: hardweight/ShopBackend
 /// <summary>
 /// 添加商品
 /// </summary>
 /// <param name="cartGoodsInfo"></param>
 public void AddGoods(CartGoodsInfo cartGoodsInfo)
 {
     cartGoodsInfo.CheckNotNull(nameof(cartGoodsInfo));
     var finalCount = _goodsCount;
     finalCount += cartGoodsInfo.Quantity;
     //判断是否存在该商品
     var cartGoods = _cartGoodses.SingleOrDefault(x => x.Info.SpecificationId == cartGoodsInfo.SpecificationId);
     if(cartGoods!=null)
     {//存在商品只更新数量即可
         var finalQuantity = cartGoods.Info.Quantity + cartGoodsInfo.Quantity;
         ApplyEvent(new CartGoodsQuantityChangedEvent(cartGoods.Id, finalQuantity, finalCount));
     }
     else
     {
         ApplyEvent(new CartAddedGoodsEvent(Guid.NewGuid(),cartGoodsInfo, finalCount));
     }
 }
コード例 #2
0
 public CartAddedGoodsEvent(Guid cartGoodsId, CartGoodsInfo info, int finalCount)
 {
     CartGoodsId = cartGoodsId;
     Info        = info;
     FinalCount  = finalCount;
 }