Example #1
0
        public void AddToCard(string userId, int productId, int quantity)
        {
            var card = _cardDal.GetCardByUserId(userId);

            if (card != null)
            {
                var index = card.CardItems.FindIndex(x => x.ProductId == productId);
                if (index < 0)
                {
                    card.CardItems.Add(new CardItem()
                    {
                        ProductId = productId,
                        Quantity  = quantity,
                        CardId    = card.Id,
                    });
                }
                else
                {
                    card.CardItems[index].Quantity += quantity;
                }
                _cardDal.Update(card);
            }
        }