public ActionResult Alterar(Animal animal) { _context.Entry(animal).State = EntityState.Modified; _context.SaveChanges(); TempData["msg"] = "Animal Atualizado"; return(RedirectToAction("Listar")); }
public async Task <IActionResult> PutPet(long id, Pet pet) { if (id != pet.Id) { return(BadRequest()); } _context.Entry(pet).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PetExists(id)) { return(NotFound()); } else { throw; } } return(Ok(pet)); }
public ActionResult Editar(Produto p) { _context.Entry(p).State = EntityState.Modified; _context.SaveChanges(); TempData["msg"] = "Produto atualizado!"; return(RedirectToAction("Listar")); }
public Pet Update(int id, Pet pet) { // Makes sure the list of colour relations is set. List <PetColourRelation> petColours; if (pet.Colours != null) { petColours = new List <PetColourRelation>(pet.Colours); } else { petColours = new List <PetColourRelation>(); } // Deletes the pet colours which is already in the pet colour relation. var coloursFromDb = _ctx.Pets.Include(p => p.Colours).AsNoTracking().FirstOrDefault(p => p.Id == id).Colours.ToList(); foreach (var petColour in coloursFromDb) { if (petColours.Exists(pc => pc.ColourId == petColour.ColourId)) { _ctx.Entry(petColour).State = EntityState.Unchanged; petColours.RemoveAll(p => p.ColourId == petColour.ColourId); } else if (!petColours.Exists(pc => pc.ColourId == petColour.ColourId)) { _ctx.Entry(petColour).State = EntityState.Deleted; } } pet.Colours = petColours; _ctx.Attach(pet); _ctx.Attach(pet).State = EntityState.Modified; _ctx.Entry(pet).Collection(p => p.Colours).IsModified = false; _ctx.Entry(pet).Reference(p => p.PreviousOwner).IsModified = true; _ctx.Entry(pet).Reference(p => p.Type).IsModified = true; DisplayStates(_ctx.ChangeTracker.Entries()); _ctx.SaveChanges(); return(_ctx.Pets.Include(p => p.Colours).FirstOrDefault(p => p.Id == id)); }
public void EditUser(User entity) { _ctx.Entry(entity).State = EntityState.Modified; _ctx.SaveChanges(); }
public void Edit(User entity) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); }
public void Update(TEntity entity) { DbSet.Attach(entity); Db.Entry(entity).State = EntityState.Modified; Db.SaveChanges(); }