Example #1
0
        public void AddToBasket(int productId, int quantity)
        {
            Debug.WriteLine(BasketID + "=======================AAAAAAAAAAAAAAAAAAAAAAAAAAAAA============");
            var basketLine = _context.BasketLine.FirstOrDefault(b => b.BasketId == BasketID && b.ProductId == productId);

            if (basketLine == null)
            {
                basketLine = new BasketLine
                {
                    ProductId   = productId,
                    BasketId    = BasketID,
                    Quantity    = quantity,
                    DateCreated = DateTime.Now
                };
                _context.Add(basketLine);
            }
            else
            {
                basketLine.Quantity += quantity;
            }
            _context.SaveChanges();
        }