// GET: DishTypes/Edit/5 public async Task <IActionResult> Edit(int?id) { var dishTypesViewModel = new DishTypesViewModel(); if (id == null) { return(NotFound()); } var dishType = await repo.GetDishTypeID(id); await repo.GetIngredients(); if (dishType == null) { return(NotFound()); } var ingredientType = await repo.GetIngredientTypes(); var subDishType = await repo.GetSubDishTypesList(); dishTypesViewModel.Dish = dishType; dishTypesViewModel.Ingredients = ingredientType; dishTypesViewModel.SubTypeList = subDishType; return(View("Edit", dishTypesViewModel)); }
public async Task <IActionResult> Create([Bind("Dish, Dish.Name, Dish.Course, Ingredients, Dish.DishTypeID, SubTypeID, Dish.Recipe, Dish.Price")] DishTypesViewModel dishTypeViewModel) { //HEAD if (ModelState.IsValid) { // Create new Dishtype and assign properties DishType model = new DishType { Name = dishTypeViewModel.Dish.Name, Course = dishTypeViewModel.Dish.Course, Recipe = dishTypeViewModel.Dish.Recipe, Price = dishTypeViewModel.Dish.Price }; var sdt = await repo.GetSubDishTypeID(dishTypeViewModel); if (sdt == null) { return(NotFound()); } model.SubDishType = sdt; repo.InsertDishType(model); await repo.Save(); int id = model.DishTypeID; return(RedirectToAction(nameof(Edit), new { id })); } return(View(dishTypeViewModel)); }
// GET: DishTypes/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var model = await repo.GetDishTypeID(id); var model2 = await repo.GetIngredientTypes(); if (model == null) { return(NotFound()); } await repo.GetSubDishTypesList(); DishTypesViewModel a = new DishTypesViewModel() { Dish = model, Ingredients = model2 }; return(View(a)); }
public async Task <SubDishType> GetSubDishTypeID(DishTypesViewModel dishTypesViewModel) { DbSet <SubDishType> subDishTypes = GetSubDishTypes(); var sdt = subDishTypes.Where(s => dishTypesViewModel.SubTypeID == s.SubDishTypeID).FirstOrDefaultAsync(); return(await sdt); }
// GET: DishTypes/Create public async Task <IActionResult> Create() { DishTypesViewModel model = new DishTypesViewModel { SubTypeList = await repo.GetSubDishTypesList() }; return(View(model)); }
public async Task <IActionResult> Edit(DishTypesViewModel dishType) { if (ModelState.IsValid) { try { repo.UpdateDish(dishType); await repo.Save(); } catch (DbUpdateConcurrencyException) { if (!DishTypeExists(dishType.Dish.DishTypeID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(dishType)); }
public void UpdateDish(DishTypesViewModel dishType) { _context.Update(dishType.Dish); }