예제 #1
0
 public ActionResult Alterar(Animal animal)
 {
     _context.Entry(animal).State = EntityState.Modified;
     _context.SaveChanges();
     TempData["msg"] = "Animal Atualizado";
     return(RedirectToAction("Listar"));
 }
예제 #2
0
        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"));
 }
예제 #4
0
        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));
        }
예제 #5
0
 public void EditUser(User entity)
 {
     _ctx.Entry(entity).State = EntityState.Modified;
     _ctx.SaveChanges();
 }
예제 #6
0
 public void Edit(User entity)
 {
     db.Entry(entity).State = EntityState.Modified;
     db.SaveChanges();
 }
예제 #7
0
 public void Update(TEntity entity)
 {
     DbSet.Attach(entity);
     Db.Entry(entity).State = EntityState.Modified;
     Db.SaveChanges();
 }