Exemplo n.º 1
0
        public IHttpActionResult PostAnimal(AnimalModel animal)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Animal dbAnimal = new Animal();

            dbAnimal.Update(animal);

            db.Animals.Add(dbAnimal);

            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {

                throw new Exception("Unable to add animal");
            }

            return CreatedAtRoute("DefaultApi", new { id = animal.AnimalId }, animal);
        }
Exemplo n.º 2
0
 public void Update(AnimalModel animal)
 {
     AnimalId = animal.AnimalId;
     AnimalTypeId = animal.AnimalTypeId;
     WufioUserId = animal.WufioUserId;
     AgeId = animal.AgeId;
     Gender = animal.Gender;
     Breed = animal.Breed;
     ImageUrl = animal.ImageUrl;
     Notes = animal.Notes;
 }
Exemplo n.º 3
0
        public IHttpActionResult PutAnimal(int id, AnimalModel animal)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != animal.AnimalId)
            {
                return BadRequest();
            }
            var dbAnimal = db.Animals.Find(id);

            dbAnimal.Update(animal);

            db.Entry(dbAnimal).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnimalExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw new Exception("Unable to update animal");
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }