public async Task <IActionResult> DeleteCoupling(long id) { DishComponentIngredientCoupling component = _db.DishComponentIngredientCouplings.First(x => x.ID == id); _db.Remove(component); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreateCoupling([Bind("DichComponentID,Amount,Price,Notes,IngredientID")] DishComponentIngredientCoupling c) { try { c.Guid = Guid.NewGuid(); _db.Add(c); await _db.SaveChangesAsync(); } catch (Exception e) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator. " + e); } ComponentData data = new ComponentData() { Component = _db.DishComponents.Single(x => x.ID == c.DichComponentID), Ingredients = _db.Ingredients.ToList() }; return(View("Index", data)); }