// GET: FoodItems/Create public IActionResult Create() { var viewModel = new FoodItemCreateViewModel() { FoodItem = new FoodItem(), FoodGroups = ctx.FoodGroups.AsEnumerable() }; return(View(viewModel)); }
public async Task <IActionResult> Create([Bind("FoodItemID,FoodItemName,FoodDescription,Cost,FoodGroupID")] FoodItem foodItem) { if (ModelState.IsValid) { await repository.Add(foodItem); await repository.AddFoodForUser(CurrentUser.User, foodItem); return(RedirectToAction(nameof(Index))); } var viewModel = new FoodItemCreateViewModel() { FoodGroups = ctx.FoodGroups.AsEnumerable(), FoodItem = new FoodItem() }; return(View(viewModel)); }