public async Task <IActionResult> Create(AddDefaultMealViewModel addDefaultMealViewModel) { if (ModelState.IsValid) { WeatherType newWeatherType = _context.WeatherTypes.Single(w => w.ID == addDefaultMealViewModel.WeatherTypeID); CookingMethod newCookingMethod = _context.CookingMethods.Single(m => m.ID == addDefaultMealViewModel.CookingMethodID); CookingMethod newAltCookingMethod = _context.CookingMethods.Single(a => a.ID == addDefaultMealViewModel.AltCookingMethodID); CookingTime newCookingTime = _context.CookingTimes.Single(t => t.ID == addDefaultMealViewModel.CookingTimeID); PrepTime newPrepTime = _context.PrepTimes.Single(p => p.ID == addDefaultMealViewModel.PrepTimeID); //Add the new default meal to the default meal table DefaultMeal newDefaultMeal = new DefaultMeal { Name = addDefaultMealViewModel.Name, Description = addDefaultMealViewModel.Description, WeatherType = newWeatherType, CookingMethod = newCookingMethod, AltCookingMethod = newAltCookingMethod, CookingTime = newCookingTime, PrepTime = newPrepTime }; _context.DefaultMeals.Add(newDefaultMeal); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(addDefaultMealViewModel)); }
// GET: DefaultMeals/Create public IActionResult Create() { AddDefaultMealViewModel addDefaultMealViewModel = new AddDefaultMealViewModel( _context.WeatherTypes.ToList(), _context.CookingMethods.ToList(), _context.CookingMethods.ToList(), _context.CookingTimes.ToList(), _context.PrepTimes.ToList()); return(View(addDefaultMealViewModel)); }