Exemple #1
0
        public IHttpActionResult Put(AnimalRUD animal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateAnimalServices();

            if (!service.UpdateAnimal(animal))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool UpdateAnimal(AnimalRUD animal)
        {
            using (var db = new ApplicationDbContext())
            {
                var entity = db.Animals
                             .Single(e => e.AnimalId == animal.AnimalId);
                entity.Name           = animal.Name;
                entity.Species        = animal.Species;
                entity.Breed          = animal.Breed;
                entity.Sex            = animal.Sex;
                entity.Fixed          = animal.Fixed;
                entity.Vaccines       = animal.Vaccines;
                entity.Age            = animal.Age;
                entity.Description    = animal.Description;
                entity.AdoptionPrice  = animal.AdoptionPrice;
                entity.IsHouseTrained = animal.IsHouseTrained;
                entity.IsDeclawed     = animal.IsDeclawed;
                entity.IsEdible       = animal.IsEdible;

                return(db.SaveChanges() == 1);
            }
        }