public IActionResult AddDish() { // Need to utilize the bundle to access both chef and dish models var chefDishBundle = new ChefDishBundle(); chefDishBundle.AllChefs = dbContext.Chefs.ToList(); return(View("AddDish", chefDishBundle)); }
public IActionResult CreateDish(ChefDishBundle chefDishBundle) { // creates a dish object from the bundled model var newDish = chefDishBundle.dish; if (ModelState.IsValid) { // updates DateTime values newDish.CreatedAt = DateTime.Now; newDish.UpdatedAt = DateTime.Now; // queries to add the dish object to the DB dbContext.Dishes.Add(newDish); dbContext.SaveChanges(); return(RedirectToAction("ViewDishes")); } else { // if model state is invalid, uses the created bundle // to query the db, for the chef list on the add // dish view. chefDishBundle.AllChefs = dbContext.Chefs.ToList(); return(View("AddDish", chefDishBundle)); } }