public async Task <IActionResult> Edit(Guid id, [Bind("Id,RecipeId,ComponentId,Quantity,UnitId,Number")] Ingredient ingredient) { if (id != ingredient.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ingredient); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IngredientExists(ingredient.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ingredient)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] ComponentType componentType) { if (id != componentType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(componentType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ComponentTypeExists(componentType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(componentType)); }
public async Task<IActionResult> Edit(int id, [Bind("Id,Name")] Unit unit) { if (id != unit.Id) { return NotFound(); } if (ModelState.IsValid) { try { _context.Update(unit); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UnitExists(unit.Id)) { return NotFound(); } else { throw; } } return RedirectToAction(nameof(Index)); } return View(unit); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name")] Library library) { if (id != library.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(library); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LibraryExists(library.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(library)); }
public async Task <IActionResult> Edit( Guid id, [Bind("Id,LibraryId,Name,MixTypeId,Instructions,Source")] Recipe recipe, RecipeViewModel recipeVM) { if (id != recipe.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(recipe); foreach (var ingredientVM in recipeVM.IngredientViewModels) { bool isNew = false; var ingredient = Helper.GetIngredient(_context, ingredientVM.Id); if (ingredient == null) { isNew = true; ingredient = new Ingredient { Id = ingredientVM.Id }; } ingredient.RecipeId = recipe.Id; ingredient.ComponentId = ingredientVM.ComponentId; ingredient.Quantity = ingredientVM.Quantity; ingredient.UnitId = ingredientVM.UnitId; ingredient.Number = ingredientVM.Number; if (isNew) { _context.Add(ingredient); } else { _context.Update(ingredient); } } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(recipe.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(recipe)); }