reneumg
(Reneumg)
5
[HttpPost("{franchise_id}")]
public async Task<IActionResult> CreateFanchise(Guid franchise_id)
{
Configuration config = new Configuration();
HttpClient httpClient = new HttpClient();
HttpClientHandler httpClientHandler = new HttpClientHandler();
var franchise = await _franchiseRepository.GetFranchise(franchise_id);
var endereco = new EmpresaEndereco(franchise.Person.District, franchise.Person.Number, franchise.Person.Complement,
franchise.Person.District, franchise.Person.City.CodIBGE, franchise.Person.City.Name, franchise.Person.City.State,
franchise.Person.City.Country.CountryCode, franchise.Person.City.Country.Name, franchise.Person.CEP);
Empresa empresa = new Empresa(franchise.Person.CPFeCNPJ, new DateTime(), new DateTime(), franchise.Person.RGeStateRegistration, " ",
franchise.Person.Name, franchise.Person.FantasyName, franchise.Person.CellPhone, franchise.Person.Email, endereco,
false,int.Parse(franchise.TaxRegime), 0);
config.AccessToken = tokenAcess;
config.BasePath = baseUrl;
var ApiInstance = new EmpresaApi(httpClient, config, httpClientHandler);
try
{
Empresa result = await ApiInstance.CriarEmpresaAsync(empresa);
if (result is null)
{
throw new ApiException(204, "cnpj não encontrado em nossa pesquisa.");
}
return Ok(result);
}
catch (ApiException ex)
{
if (ex.ErrorCode == 204)
{
return BadRequest(ex.Message);
}
return BadRequest(ex.Message);
}
}