public async Task <IHttpActionResult> RegisterCityAsync(string city_name) { Response account = await ConsultaAPI.ConsultarApiTempAsync(city_name); try { temperaturaDBEntities.Temperatura.Add(new Temperatura { date = DateTime.Parse(account.Results.Date), temperature = int.Parse(account.Results.Temp), Cidade = temperaturaDBEntities.Cidade.Add(new Cidade { city = account.Results.City_name }) }); temperaturaDBEntities.SaveChanges(); return(Ok(city_name + " registrada com sucesso!")); } catch (DbUpdateException) { return(BadRequest(account.Results.City_name + " já cadastrada")); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public async Task <IHttpActionResult> CadastrarCidadePorCEPAsync(string cep) { var a = ConsultaAPI.ConsultarApiCep(cep); if (a == null) { return(BadRequest("Cep Invalido")); } return(await RegisterCityAsync(a)); }