Ejemplo n.º 1
0
        public Owner CreateOwner(Owner owner)
        {
            var changeTracker = _context.ChangeTracker.Entries <Pet>();

            _context.Attach(owner).State = EntityState.Added;
            _context.SaveChanges();
            return(owner);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        public Owner Create(Owner owner)
        {
            Owner OwnerToReturn = _context.Attach(owner).Entity;

            _context.SaveChanges();
            return(OwnerToReturn);
        }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
 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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
 public void Edit(User entity)
 {
     _context.Attach(entity).State = EntityState.Modified;
     _context.SaveChanges();
 }
Ejemplo n.º 13
0
 public Pet Create(Pet pet)
 {
     _ctx.Attach(pet).State = EntityState.Added;
     _ctx.SaveChanges();
     return(pet);
 }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 17
0
 public void UpdateUser(User user)
 {
     _ctx.Attach(user).State = EntityState.Modified;
     _ctx.SaveChanges();
 }
Ejemplo n.º 18
0
 public Pet CreateNewPetRepo(Pet newPet)
 {
     _ctx.Attach(newPet).State = EntityState.Added;
     _ctx.SaveChanges();
     return(newPet);
 }
Ejemplo n.º 19
0
 /// <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);
 }