public ShopCartItem SetCount(int shopCartItemId, int count) { ShopCartItem shopCartItem = ShopCartItemRepository.Get(shopCartItemId); shopCartItem.Count = count; return(shopCartItem); }
public ShopCart AddItem(ShopCartItem shopCartItem) { var specification = SpecificationRepository.Get(shopCartItem.SpecificationId); if (specification.Product.Type == ProductType.Virtual) { throw new UserFriendlyException(L("VirtualProductCannotAddToShopCart")); } ShopCart shopCart = GetShopCart(Session.UserId.Value); ShopCartItem shopCartItemForCheck = ShopCartItemRepository.GetAll().Where(model => model.ShopCartId == shopCart.Id && model.SpecificationId == shopCartItem.SpecificationId).FirstOrDefault(); if (shopCartItemForCheck != null) { shopCartItemForCheck.Count += shopCartItem.Count; } else { shopCartItem.ShopCartId = shopCart.Id; shopCart.ShopCartItems.Add(shopCartItem); } CurrentUnitOfWork.SaveChanges(); return(shopCart); }