// sepete ürün eklemek için public void AddToCart(CartItem cartItem) { // add methodu daha geliştirilecek. var cart = _cartSessionService.Get("CartSession"); // daha önce aynı ürün sepete eklendiyse bu durumda sepetteki ürün adetini güncelleyeceğiz // yeni ekleniyorsa bu durumda yeni bir item olarak cartItemsa ekleteceğiz. CartItem foundedCartItem = cart.CarItems.FirstOrDefault(x => x.ProductId == cartItem.ProductId); if (foundedCartItem != null) { // daha öncesinde ürün sepete konmuş foundedCartItem.Quantity += cartItem.Quantity; } else { cart.CarItems.Add(cartItem); // daha önce bu item sepete eklenmediyse } // buradaki sepet değerimiz en son olarak güncellenmiştir. ya yeni bir item gelmiş yada var olan bir item quantity artmıştır. _cartSessionService.Set("CartSession", cart); }