public int PasalintiIsKrepselio(Pica pica) { var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault( x => x.Pica.PicaId == pica.PicaId && x.ShoppingCartId == ShopingCartId); var localKiekis = 0; if (shoppingCartItem != null) { if (shoppingCartItem.Kiekis > 1) { shoppingCartItem.Kiekis--; localKiekis = shoppingCartItem.Kiekis; } else { _appDbContext.ShoppingCartItems.Remove(shoppingCartItem); } } _appDbContext.SaveChanges(); return(localKiekis); }
public void IdetiIKrepseli(Pica pica, int amount) { var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault( x => x.Pica.PicaId == pica.PicaId && x.ShoppingCartId == ShopingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = ShopingCartId, Pica = pica, Kiekis = 1 }; _appDbContext.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Kiekis++; } _appDbContext.SaveChanges(); }