public async Task <IActionResult> Post(ResidenceDto residenceDto) { try { var residence = _mapper.Map <Residence>(residenceDto); //Validate data integrity in ViaCep Api residence = await _repo.GetAddressByViaCepApiAsync(residence); if (residence.ZipCode == null) { return(NotFound(ApiReturnMessages.ZipCodeNotFound)); } _repo.Add(residence); if (await _repo.SaveChangesAsync()) { return(Created($"/api/Residence/{residence.ResidenceId}", residenceDto)); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ApiReturnMessages.DbFailed)); } return(BadRequest()); }
public async Task <IActionResult> Post(ResidenceType residenceType) { try { _repo.Add(residenceType); if (await _repo.SaveChangesAsync()) { return(Created($"/api/ResidenceType/{residenceType.ResidenceTypeId}", residenceType)); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ApiReturnMessages.DbFailed)); } return(BadRequest()); }