public IHttpActionResult Post([FromBody] Habitant habitant) { try { if (habitant == null) { return(BadRequest("Habitant cannot be null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var habitantRepository = new Models.HabitantRepository(); var newHabitant = habitantRepository.Save(habitant); if (newHabitant == null) { return(Conflict()); } return(Created <Habitant>(Request.RequestUri + newHabitant.HabitantId.ToString(), newHabitant)); } catch (Exception ex) { return(InternalServerError(ex)); } }
// PUT: api/Habitants/5 public IHttpActionResult Put(int id, [FromBody] Habitant habitant) { try { if (habitant == null) { return(BadRequest("Habitant cannot be null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var habitantRepository = new Models.HabitantRepository(); var updatedHabitant = habitantRepository.Save(id, habitant); if (updatedHabitant == null) { return(NotFound()); } return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }