public IActionResult Add(AddMenuViewModel addMenuViewModel) { if (ModelState.IsValid) { Menu newMenu = addMenuViewModel.CreateMenu(); context.Menus.Add(newMenu); context.SaveChanges(); return(Redirect($"/Menu/ViewMenu/{newMenu.MenuID}")); } return(View(addMenuViewModel)); }
public IActionResult Add(AddMenuViewModel viewModel) { if (!ModelState.IsValid) { return(View("Add", viewModel)); } Menu menu = new Menu(); menu.Name = viewModel.Name; context.Menus.Add(menu); context.SaveChanges(); return(Redirect("/menu")); }
public IActionResult Add(AddCheeseViewModel cheeseViewModel) { if (ModelState.IsValid) { context.Cheeses.Add(new Cheese { Name = cheeseViewModel.Name, Description = cheeseViewModel.Description, Category = context.Categories.Single(x => x.ID == cheeseViewModel.CategoryID) }); context.SaveChanges(); return(Redirect("/Example")); } return(View(cheeseViewModel)); }
public IActionResult NewCheese(AddCheeseViewModel viewModel) { if (!ModelState.IsValid) { return(View("Add", viewModel)); } // add new cheese to static class list Cheese newCheese = viewModel.CreateCheese(); context.Cheeses.Add(newCheese); context.SaveChanges(); // go back to the list of cheeses return(Redirect("/cheese")); }
public IActionResult Add(AddCheeseViewModel addCheeseViewModel) { if (ModelState.IsValid) { CheeseCategory newCheeseCategory = context.Categories.Single(c => c.ID == addCheeseViewModel.CategoryID); Cheese newCheese = addCheeseViewModel.CreateCheese(newCheeseCategory); context.Cheeses.Add(newCheese); context.SaveChanges(); return(Redirect("/Cheese")); } return(View(addCheeseViewModel)); }
public IActionResult Add(AddCategoryViewModel addCategoryViewModel) { if (ModelState.IsValid) { CheeseCategory newCategory = addCategoryViewModel.CreateCategory(); context.Categories.Add(newCategory); context.SaveChanges(); return(Redirect("/Category")); } return(View(addCategoryViewModel)); }