// GET: Products/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var product = await _context.Product.SingleOrDefaultAsync(m => m.Id == id); if (product == null) { return(NotFound()); } var model = new ProductEdit_ViewModel(); model.Id = product.Id; model.Name = product.Name; model.TotalQuantity = product.TotalQuantity; model.SKU = product.SKU; //is this ok? can i just pass in a few things and update those few things on the other end //and the rest just remains untouched? return(View(model)); }
public async Task <IActionResult> Edit(int id, ProductEdit_ViewModel model) { if (id != model.Id) { return(NotFound()); } var product = _context.Product.FirstOrDefault(p => p.Id == model.Id); product.Name = model.Name; product.TotalQuantity = model.TotalQuantity; product.SKU = model.SKU; if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }