public IHttpActionResult PostAnimalType(AnimalTypeModel animalType) { if (!ModelState.IsValid) { return BadRequest(ModelState); } AnimalType dbAnimalType = new AnimalType(); dbAnimalType.Update(animalType); db.AnimalTypes.Add(dbAnimalType); try { db.SaveChanges(); } catch (Exception e) { throw new Exception("Unable to add animal type"); } return CreatedAtRoute("DefaultApi", new { id = animalType.AnimalTypeId }, animalType); }
public void Update(AnimalTypeModel animalType) { AnimalTypeId = animalType.AnimalTypeId; Description = animalType.Description; ImageUrl = animalType.ImageUrl; }
public IHttpActionResult PutAnimalType(int id, AnimalTypeModel animalType) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != animalType.AnimalTypeId) { return BadRequest(); } var dbAnimalType = db.AnimalTypes.Find(id); dbAnimalType.Update(animalType); db.Entry(dbAnimalType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AnimalTypeExists(id)) { return NotFound(); } else { throw new Exception("Unable to update animal type"); } } return StatusCode(HttpStatusCode.NoContent); }