예제 #1
0
        public Pet EditPet(int id, Pet editedPet)
        {
            //var petTypeChangeTracker = _context.ChangeTracker.Entries<PetType>();
            //var ChangeTracker = _context.ChangeTracker.Entries<Pet>();

            //if (editedPet.PetType != null && _context.ChangeTracker.Entries<PetType>()
            //    .FirstOrDefault(petTypeEntry => petTypeEntry.Entity.OwnerId == editedPet.PetType.OwnerId) == null)
            //{
            //    _context.Attach(editedPet.PetType);
            //}
            //else
            //{
            //    _context.Entry(editedPet).Reference(pet => pet.PetType).IsModified = true;
            //}

            //var petOwnerChangeTracker = _context.ChangeTracker.Entries<Owner>();

            //if (editedPet.Owner != null && _context.ChangeTracker.Entries<Owner>()
            //    .FirstOrDefault(ownerEntry => ownerEntry.Entity.OwnerId == editedPet.Owner.OwnerId) == null)
            //{
            //    _context.Attach(editedPet.Owner);
            //}
            //else
            //{
            //    _context.Entry(editedPet).Reference(pet => pet.Owner).IsModified = true;
            //}

            // _context.Attach(editedPet).State = EntityState.Modified;

            if (editedPet.Owner != null)
            {
                _context.Attach(editedPet.Owner).State = EntityState.Unchanged;
            }
            else
            {
                _context.Entry(editedPet).Reference(pet => pet.Owner).IsModified = true;
            }

            _context.Attach(editedPet.PetType).State = EntityState.Unchanged;
            _context.Update(editedPet);
            _context.SaveChanges();
            return(editedPet);
        }
예제 #2
0
 public async Task Update(Client client)
 {
     _context.Update(client);
     await _context.SaveChangesAsync();
 }
예제 #3
0
 public async Task Update(Pet pet)
 {
     _context.Update(pet);
     await _context.SaveChangesAsync();
 }