public ActionResult CreateIngredient() { CreateIngredientVM ci = new CreateIngredientVM(); IngredientRepo ingredientRepo = new IngredientRepo(); var listOfCategories = ingredientRepo.GetAllIngredientCategories(); ci.IngredientCategories = listOfCategories; return(View(ci)); }
public ActionResult ViewIngredient(int IngredientID) { try { CreateIngredientVM vm = new CreateIngredientVM(); IngredientRepo ri = new IngredientRepo(); var ingredient = ri.GetIngredientByID(IngredientID); vm.IngredientName = ingredient.IngredientName; vm.IngredientCategory = ingredient.IngredientCategory.IngredientCategory1; return(View(vm)); } catch (Exception ex) { throw; } }
public ActionResult CreateIngredient(CreateIngredientVM model) { if (!ModelState.IsValid) { return(View(model)); } try { IngredientRepo ri = new IngredientRepo(); Ingredient i = new Ingredient(); i.IngredientName = model.IngredientName; i.IngredientCategoryID = model.IngredientCategoryID; i = ri.InsertIngredient(i); ModelState.Clear(); return(RedirectToAction("ViewIngredient", new { i.IngredientID })); } catch (Exception ex) { throw; } }