public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryName")] Category category)
 {
     if (id != category.Id)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(category);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!CategoryExists(category.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(category));
 }
예제 #2
0
        public IActionResult Edit(int id, [Bind("Id,UserName,FirstName,LastName,Email,Phone,UserPassword,ConfirmPassword,Points,Notifications")] Users users)
        {
            if (id != users.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(users);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UsersExists(users.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(users));
        }
예제 #3
0
        public IActionResult Edit(int id, [Bind("Id,ItemName,ItemDescription,Quantity,Price")] Items items)
        {
            if (id != items.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(items);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemsExists(items.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(items));
        }
예제 #4
0
 public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryId,ProductName,ProductPrice,InsertedDate,UpdatedDate")] Product product)
 {
     if (id != product.Id)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(product);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!ProductExists(product.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "CategoryName", product.CategoryId);
     return(View(product));
 }
        public void UpdateProduct(Product product)
        {
            using (var dbc = new ShopDBContext())
            {
                var prdToUpdate = dbc.Product.FirstOrDefault(p => p.Id == product.Id);
                prdToUpdate.Name       = product.Name;
                prdToUpdate.OrderItem  = product.OrderItem;
                prdToUpdate.Price      = product.Price;
                prdToUpdate.Stock      = product.Stock;
                prdToUpdate.UpdateDate = product.UpdateDate;

                dbc.Update(prdToUpdate);
                dbc.SaveChanges();
            }
        }
예제 #6
0
        public async Task <IActionResult> Buy()
        {
            /*In case I decide to go back to using TempData.
             *
             * Users user = _context.Users.FirstOrDefault(e => e.Id == (int)TempData["userId"]);
             * Items item = _context.Items.FirstOrDefault(e => e.Id == (int)TempData["itemId"]);*/

            UserItems thisPurchase = (UserItems)ByteArrayToObject(HttpContext.Session.Get("thisPurchase"));

            thisPurchase.PurchaseDate = DateTime.Now;
            Users user = _context.Users.FirstOrDefault(e => e.Id == thisPurchase.UserId);
            Items item = _context.Items.FirstOrDefault(e => e.Id == thisPurchase.ItemId);

            user.Balance -= item.Price;
            user.Points++;
            _context.Update(user);
            _context.UserItems.Add(thisPurchase);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }