public async Task <IActionResult> Post(Imovel model, string Token) { var TokenApi = new Token { TokenDef = _config.GetValue <string>("Token:TokenDef") }; if (TokenApi.TokenDef != Token) { return(this.StatusCode(StatusCodes.Status401Unauthorized, $"O Token informado não é autorizado.")); } try { var Imovel = await _repo.GetImovelByRefAsync(model.Nome); if (Imovel != null) { return(this.StatusCode(StatusCodes.Status401Unauthorized, "Imovel ja existe com essa Referencia.")); } _repo.Add(model); if (await _repo.SaveChangesAsync()) { return(Created($"/api/Imoveis/GetById/{model.Id}", model)); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}")); } return(BadRequest()); }