public async Task<IActionResult> PutProducts(int id, Products products) { if (id != products.ProductId) { return BadRequest(); } _context.Entry(products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public void Update(TEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } try { _context.Set <TEntity>().Attach(entity); } catch (Exception e) { _context.Entry(entity).State = EntityState.Detached; _context.Set <TEntity>().Attach(entity); } _context.Entry(entity).State = EntityState.Modified; }
public ActionResult Edit([Bind(Include = "Id,Name,Passwprd,Gender,Birthday,Memo")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }