예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] CheeseCategory cheeseCategory)
        {
            if (id != cheeseCategory.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cheeseCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CheeseCategoryExists(cheeseCategory.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cheeseCategory));
        }
        public IActionResult Edit(Cheese toEdit, int cheeseId, EditCheeseViewModel editCheeseViewModel)
        {
            if (ModelState.IsValid)
            {
                context.Update(toEdit);
                context.SaveChanges();
            }

            return(Redirect("/"));
        }
예제 #3
0
        public IActionResult Edit(EditCheeseViewModel editCheeseViewModel)
        {
            if (ModelState.IsValid)
            {
                Cheese cheeseToEdit = context.Cheeses.Single(c => c.ID == editCheeseViewModel.CheeseId);
                // Update properties of cheese item
                cheeseToEdit.Name        = editCheeseViewModel.Name;
                cheeseToEdit.Description = editCheeseViewModel.Description;
                cheeseToEdit.CategoryID  = editCheeseViewModel.CategoryID;
                cheeseToEdit.ID          = editCheeseViewModel.CheeseId;

                // Update to database and save changes
                context.Update(cheeseToEdit);
                context.SaveChanges();

                return(Redirect("/"));
            }
            return(View(editCheeseViewModel));
        }