Exemplo n.º 1
0
        public void AddToChart(string userId, int productId, int quantity)
        {
            var cart = GetSepetByUserId(userId);

            if (cart != null)                                                         // Kullanıcının bir sepeti olup olmadığı kontrol edilir
            {
                var index = cart.SepetItems.FindIndex(i => i.ProductId == productId); //
                if (index < 0)
                {
                    cart.SepetItems.Add(new SepetItem()
                    {
                        ProductId = productId,
                        Quantity  = quantity,
                        SepetId   = cart.Id
                    });
                }
                else
                {
                    cart.SepetItems[index].Quantity += quantity;
                }
                _sepetRepository.Update(cart);
            }
        }
Exemplo n.º 2
0
        public async Task <SepetResponse> UpdateAsync(int id, Sepet sepet)
        {
            var existingSepet = await _sepetRepository.FindByIdAsync(id);

            if (existingSepet == null)
            {
                return(new SepetResponse("Sepet not found."));
            }

            existingSepet.SepetId = sepet.SepetId;

            try
            {
                _sepetRepository.Update(existingSepet);
                await _unitOfWork.CompleteAsync();

                return(new SepetResponse(existingSepet));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SepetResponse($"An error occurred when updating the sepet: {ex.Message}"));
            }
        }