public Owner CreateOwner(Owner owner) { var changeTracker = _context.ChangeTracker.Entries <Pet>(); _context.Attach(owner).State = EntityState.Added; _context.SaveChanges(); return(owner); }
public Owner CreateOwner(Owner owner) { var own = _ctx.Attach(owner).State = EntityState.Added; _ctx.Entry(owner).Collection(o => o.Pets).IsModified = true; _ctx.SaveChanges(); return(owner); }
public Pet CreatePet(Pet pet) { if (pet != null) { _context.Attach(pet).State = EntityState.Added; _context.Entry(pet).Collection(p => p.ownersHistory).IsModified = true; } var petSaved = _context.Pets.Add(pet).Entity; _context.SaveChanges(); return(petSaved); }
public Pet CreatePet(Pet pet) { if (pet.PreviousOwner != null && _ctx.ChangeTracker.Entries <Owner>() .FirstOrDefault(ce => ce.Entity.Id == pet.PreviousOwner.Id) == null) { _ctx.Attach(pet.PreviousOwner); } var petSaved = _ctx.Pets.Add(pet).Entity; _ctx.SaveChanges(); return(petSaved); }
/// <summary> /// Adds pet to DB. /// </summary> /// <param name="pet"></param> /// <returns>Pet with id from DB.</returns> public Pet CreatePet(Pet pet) { //var changeTracker = _ctx.ChangeTracker.Entries<Owner>(); try { _ctx.Attach(pet).State = EntityState.Added; _ctx.SaveChanges(); } catch (Exception e) { throw new Exception("Failed to create pet!"); } return(pet); }
public Owner Create(Owner owner) { Owner OwnerToReturn = _context.Attach(owner).Entity; _context.SaveChanges(); return(OwnerToReturn); }
public Pet CreatePet(Pet pet) { /* if (pet.Owner != null && * _ctx.ChangeTracker.Entries<Owner>() * .FirstOrDefault(ce => ce.Entity.Id == pet.Owner.Id) == null) * { * _ctx.Attach(pet.Owner); * } * * var newPet = _ctx.Add(pet).Entity; * _ctx.SaveChanges(); * return newPet; */ _ctx.Attach(pet).State = EntityState.Added; _ctx.SaveChanges(); return(pet); }
public User Update(User userUpdated) { _ctx.Attach(userUpdated).State = EntityState.Modified; _ctx.Remove(_ctx.Users.Where(u => u.Id == userUpdated.Id)); _ctx.Entry(userUpdated).Reference(u => u.Owner).IsModified = true; _ctx.SaveChanges(); return(userUpdated); }
public Pet Create(Pet pet) { _context.Attach(pet).State = EntityState.Added; _context.SaveChanges(); return(pet); //var petToCreate = _context.Pets.Add(pet).Entity; //_context.SaveChanges(); //return petToCreate; }
public Color CreateColor(Color color) { var existingColor = _ctx.Colors.FirstOrDefault(c => c.PetColor == color.PetColor); if (existingColor != null) { throw new Exception($"The color you have added does already exist and has the Id: {existingColor.Id}"); } _ctx.Attach(color).State = EntityState.Added; _ctx.SaveChanges(); return(color); }
public Owner Update(Owner ownerUpdate) { _ctx.Attach(ownerUpdate).State = EntityState.Modified; _ctx.Entry(ownerUpdate).Collection(o => o.Pets).IsModified = true; var pets = _ctx.Pets.Where(p => p.Owner.Id == ownerUpdate.Id && !ownerUpdate.Pets.Exists(po => po.Id == p.Id)); foreach (var pet in pets) { pet.Owner = null; _ctx.Entry(pet).Reference(p => p.Owner).IsModified = true; } _ctx.SaveChanges(); return(ownerUpdate); }
public void Edit(User entity) { _context.Attach(entity).State = EntityState.Modified; _context.SaveChanges(); }
public Pet Create(Pet pet) { _ctx.Attach(pet).State = EntityState.Added; _ctx.SaveChanges(); return(pet); }
public Pet AddPet(Pet pet) { _context.Attach(pet).State = EntityState.Added; _context.SaveChanges(); return(pet); }
public Owner AddOwner(Owner owner) { _context.Attach(owner).State = EntityState.Added; _context.SaveChanges(); return(owner); }
public Owner UpdateOwner(Owner updateOwner) { _ctx.Attach(updateOwner).State = EntityState.Modified; _ctx.SaveChanges(); return(updateOwner); }
public void UpdateUser(User user) { _ctx.Attach(user).State = EntityState.Modified; _ctx.SaveChanges(); }
public Pet CreateNewPetRepo(Pet newPet) { _ctx.Attach(newPet).State = EntityState.Added; _ctx.SaveChanges(); return(newPet); }
/// <summary> /// Adds the owner to the DB. /// </summary> /// <param name="owner"></param> /// <returns>Owner with id given by DB.</returns> public Owner CreateOwner(Owner owner) { _ctx.Attach(owner).State = EntityState.Added; _ctx.SaveChanges(); return(owner); }