public void RemoveDish(int?id) { DishType dishType = _context.DishTypes.Include(x => x.DefaultIngredients).Include(x => x.SubDishType).Where(x => x.DishTypeID == id).FirstOrDefault(); ICollection <Ingredient> ingredients = dishType.DefaultIngredients; dishType.DefaultIngredients = null; _context.Update(dishType); foreach (Ingredient i in ingredients) { _context.Ingredients.Remove(i); } _context.DishTypes.Remove(dishType); }
public async Task <IActionResult> Edit(int id, [Bind("SubDishTypeID,SubType")] SubDishType subDishType) { if (id != subDishType.SubDishTypeID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(subDishType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubDishTypeExists(subDishType.SubDishTypeID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(subDishType)); }
public async Task <IActionResult> Edit(int id, [Bind("IngredientTypeID,Name,UnitSingular,UnitPlural")] IngredientType ingredientType) { if (id != ingredientType.IngredientTypeID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ingredientType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IngredientTypeExists(ingredientType.IngredientTypeID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ingredientType)); }
public IActionResult FinalizesdOrderButton(IFormCollection col, string GuestCode) { Order order = ctx.Orders.Include(x => x.Selected).Include(x => x.Finalized).Where(x => x.Owner.Code == GuestCode).LastOrDefault(); if (order == null) { RedirectToAction("ErrorView"); } if (order.Selected != null) { if (order.Finalized == null) { order.Finalized = new List <Dish>(); } var newfinalized = order.Finalized.Concat(order.Selected); order.Finalized = newfinalized.ToList(); order.Selected.Clear(); ctx.Update(order); ctx.SaveChanges(); } return(RedirectToAction("FinalizedOrder", "MenuCard", new { guestCode = GuestCode })); }
public async Task <IActionResult> Edit(int id, [Bind("TableID,Capacity")] Table table) { if (id != table.TableID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(table); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TableExists(table.TableID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(table)); }