Esempio n. 1
0
        public static Library.Cart Map(Entities.Cart cart) => new Library.Cart
        {
            CartId = cart.CartId,

            ProductId = cart.ProductId,
            Qty       = cart.Qty
        };
Esempio n. 2
0
        /*public Library.PurOrder PlaceOrder(string Phonenumber,int store,Dictionary<string, int> product)
         * {
         *  if(VerifyCustomer(Phonenumber)== true)
         *  {
         *      Library.PurOrder order = new Library.PurOrder
         *      {
         *
         *
         *          CustomerId =int.Parse( GetCustomer(Phonenumber)),
         *          StoreId = store,
         *
         *
         *
         *      }
         *
         *
         *  }
         * }*/
        public int AddToCart(Library.Product item)
        {
            // Get the matching cart and item instances
            var cartItem = _dbContext.Cart.SingleOrDefault(
                c => c.ProductId == item.ProductId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Entities.Cart
                {
                    ProductId = item.ProductId,
                    Qty       = 1
                };
                _dbContext.Cart.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Qty++;
            }
            // Save changes
            _dbContext.SaveChanges();

            return(cartItem.Qty);
        }