// PUT api/<controller>/5 public IHttpActionResult Put(int id, [FromBody] HouseViewModel house) { try { if (ModelState.IsValid) { house.CensusHouseNumber = house.CensusHouseNumber == 0 ? id : house.CensusHouseNumber; var newHouseDTO = HouseMapper.VMtoDTOHouse(house); house = HouseMapper.DTOtoVMHouse(service.AddUpdateHouse(newHouseDTO)); return(Content(HttpStatusCode.OK, house)); } else { return(Content(HttpStatusCode.BadRequest, GetModelStateErrors(ModelState))); } } catch (HouseDoesNotExistException e) { ModelState.AddModelError("", e.Message); return(Content(HttpStatusCode.NotFound, GetModelStateErrors(ModelState))); } catch (Exception e /* dex */) { ModelState.AddModelError("", e.Message); return(Content(HttpStatusCode.InternalServerError, GetModelStateErrors(ModelState))); } }
public IHttpActionResult Post([FromBody] HouseViewModel house) { try { if (ModelState.IsValid) { var h = HouseMapper.VMtoDTOHouse(house); var newHouse = service.AddUpdateHouse(h); { return(Content(HttpStatusCode.OK, newHouse)); } } else { return(Content(HttpStatusCode.BadRequest, GetModelStateErrors(ModelState))); } } catch (Exception /* dex */) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); return(Content(HttpStatusCode.InternalServerError, GetModelStateErrors(ModelState))); } }