public async Task <AddToCartResponse> Handle(AddToCartRequest request, CancellationToken cancellationToken) { #region STOK_KONTROL var stockStatus = await _stockServices.StockControl(request.ProductId, request.Count); if (!stockStatus.Avaible) { return(new AddToCartResponse { IsSuccess = false }); } #endregion var cacheKey = CreateCartCacheKey(request.SessionId); var shoppingCart = new List <CartItem>(); //cache de sepet değeri varsa if (_cache.TryGetValue(cacheKey, out shoppingCart)) { //Ürün halihazırda sepette bulunuyorsa miktarı güncelle if (shoppingCart.Any(x => x.ProductId == request.ProductId)) { shoppingCart.FirstOrDefault(x => x.ProductId == request.ProductId).Count += request.Count; } //değilse ürünü ekle else { shoppingCart.Add(new CartItem() { Count = request.Count, ProductId = request.ProductId }); } } else { shoppingCart = new List <CartItem>(); shoppingCart.Add(new CartItem { Count = request.Count, ProductId = request.ProductId }); } _cache.Set(cacheKey, shoppingCart); var result = new AddToCartResponse { IsSuccess = true }; return(result); }