public async Task <IActionResult> Edit(int id, [Bind("Id,Quantity,Name,Description,Price,ManufacturerId,CoffeTypeId,MinimumBestBeforeDate")] CoffeItem coffeItem) { if (id != coffeItem.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(coffeItem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoffeItemExists(coffeItem.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CoffeTypeId"] = new SelectList(_context.CoffeType, "Id", "Name", coffeItem.CoffeTypeId); ViewData["ManufacturerId"] = new SelectList(_context.Manufacturer, "Id", "Name", coffeItem.ManufacturerId); return(View(coffeItem)); }
public async Task <IActionResult> Create([Bind("Id,Quantity,Name,Description,Price,ManufacturerId,CoffeTypeId,MinimumBestBeforeDate")] CoffeItem coffeItem) { if (ModelState.IsValid) { _context.Add(coffeItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CoffeTypeId"] = new SelectList(_context.CoffeType, "Id", "Name", coffeItem.CoffeTypeId); ViewData["ManufacturerId"] = new SelectList(_context.Manufacturer, "Id", "Name", coffeItem.ManufacturerId); return(View(coffeItem)); }
public ActionResult EditCoffee(int?id) { if (id == null) { return(HttpNotFound()); } CoffeItem ci = cr.CoffeeDB.Find(x => x.Id == id); if (ci != null) { return(View(ci)); } return(HttpNotFound()); }
public ActionResult EditCoffee(CoffeItem item) { cr.Update(item); return(RedirectToAction("Index")); }