public IActionResult Post([FromBody] HouseModel houseModel) { try { var house = houseModel.ToDomainModel(); _houseService.Add(house); var newHouseModel = house.ToApiModel(); return(Ok(newHouseModel)); } catch (System.Exception ex) { ModelState.AddModelError("AddHouse", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Put(int id, [FromBody] HouseModel houseModel) { try { var house = houseModel.ToDomainModel(); var updatedHouse = _houseService.Update(house); var updatedHouseModel = updatedHouse.ToApiModel(); return(Ok(updatedHouseModel)); } catch (Exception ex) { ModelState.AddModelError("UpdateHouse", ex.Message); return(BadRequest(ModelState)); } }