Beispiel #1
0
        public IActionResult Purchase(decimal?price, int Quantity)
        {
            CSIDContext db        = new CSIDContext();
            CartItems   cartItems = new CartItems();
            var         user      = User.Identity;

            foreach (Items items in db.Items)
            {
                if (items.RetailPrice == price)
                {
                    tempItem = items;
                    if (tempItem.Inventory >= 0)
                    {
                        tempItem.Inventory            -= 1;
                        tempItem.ItemId                = cartItems.Id;
                        tempItem.Description           = cartItems.Description;
                        tempItem.CustomerDiscountPrice = cartItems.CustomerDiscountPrice;
                        db.CartItems.Add(cartItems);
                    }
                    else if (tempItem.Inventory <= 10 || tempItem.Inventory == 0)
                    {
                        return(View());
                    }
                }
            }
            foreach (AspNetUsers users in db.AspNetUsers)
            {
                if (user.Name == users.Email)
                {
                    tempUser = users;
                    if (tempUser.Funds >= price)
                    {
                        tempUser.Funds -= price;
                    }
                    else if (tempUser.Funds <= price || tempUser.Funds == null)
                    {
                        return(View());
                    }
                }
            }
            db.SaveChanges();
            return(View("Shop", db));
        }
Beispiel #2
0
        public IActionResult Shop()
        {
            CSIDContext db = new CSIDContext();

            return(View(db));
        }