public async Task <IActionResult> Edit(long id, [Bind("ID,Name")] Product product) { if (id != product.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(product)); }
public IActionResult Edit(Product pro) { if (ModelState.IsValid) { context.Update(pro); context.SaveChanges(); ViewData["Message"] = "Product Updated!"; } return(View(pro)); }
public IActionResult Edit(Product p) { if (ModelState.IsValid) { context.Update(p); context.SaveChanges(); ViewData["Message"] = "Product Updated!"; //Return same page with message, or redirect to another page return(View(p)); } //Return view with errors return(View(p)); }
public async Task <TEntity> UpdateAsync(TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(UpdateAsync)} entity must not be null"); } try { context.Update(entity); await context.SaveChangesAsync(); return(entity); } catch (Exception ex) { throw new Exception($"{nameof(entity)} could not be updated: {ex.Message}"); } }
public void Update(TEntity entity) { _dbSet.Attach(entity); _dbContext.Update(entity).State = EntityState.Modified; }