// GET: Supply/Create public ActionResult Create() { var viewModel = new SupplyListAndSupplyViewModel { Ingredients = MealHelper.GetAllIngredients().Select(i => new SelectListItem { Value = i.Id.ToString(), Text = i.Name }).ToList() }; return(View(viewModel)); }
// GET: Supply/Edit/5 public ActionResult Edit(int id) { var viewModel = new SupplyListAndSupplyViewModel { Supply = SupplyHelper.GetAllSupplies().Where(x => x.Id == id).FirstOrDefault(), Ingredients = MealHelper.GetAllIngredients().Select(i => new SelectListItem { Value = i.Id.ToString(), Text = i.Name }).ToList() }; return(View(viewModel)); }
public ActionResult Create() { var viewModel = new MealWithMealTypesViewModel { MealTypes = MealHelper.GetAllMealTypes(), Ingredients = MealHelper.GetAllIngredients().Select(i => new SelectListItem { Value = i.Id.ToString(), Text = i.Name }).ToList(), PostIngredients = new List <string>() }; return(View("CreateMealForm", viewModel)); }
public ActionResult Edit(int editId, SupplyListAndSupplyViewModel PostSupply) { if (!ModelState.IsValid) { return(RedirectToAction("Edit")); } var ingredientNum = int.Parse(PostSupply.PostIngredient); var selectedIngredient = MealHelper.GetAllIngredients().Where(x => x.Id == ingredientNum).FirstOrDefault(); PostSupply.Supply.Ingredient = selectedIngredient; SupplyHelper.UpdateSupply(editId, PostSupply.Supply); return(RedirectToAction("Index")); }
public ActionResult Create(SupplyListAndSupplyViewModel PostSupply) { if (!ModelState.IsValid) { return(RedirectToAction("Create")); } var ingredientNum = int.Parse(PostSupply.PostIngredient); var selectedIngredient = MealHelper.GetAllIngredients().Where(x => x.Id == ingredientNum).FirstOrDefault(); PostSupply.Supply.Ingredient = selectedIngredient; PostSupply.Supply.Id = SupplyHelper.GetSupplyNextId(); SupplyHelper.AddSupply(PostSupply.Supply); return(RedirectToAction("Index")); }