public async Task <IActionResult> PutCityItem(long id, CityItem cityItem) { if (id != cityItem.Id) { return(BadRequest()); } _context.Entry(cityItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("city_id,country_id,region_id,name")] City city) { if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
private async Task GetCityInfo(City city) { if (city.Population == 0 || city.Latitude == 0 || city.Longitude == 0) { var cityData = await getData.GetCityData(city); city.Population = cityData.population; city.Latitude = cityData.latitude; city.Longitude = cityData.longitude; city.WikiPop = cityData.wikiPop; await _context.SaveChangesAsync(); } }
public async Task <IActionResult> PutCity(int id, City city) { if (id != city.Id) { return(BadRequest()); } try { city.Validate(); } catch (InvalidOperationException e) { return(Problem(title: "Erro ao editar usuário!", detail: e.Message, statusCode: 400)); } _context.Entry(city).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <bool> SaveAll() { return(await _context.SaveChangesAsync() > 0); }
public async Task Create(City city) { city.Id = Guid.NewGuid(); _context.Add(city); await _context.SaveChangesAsync(); }
public async Task AddCurrentConditions(CurrentConditionsLight currentConditions) { await _dbContext.CurrentConditions.AddAsync(currentConditions); await _dbContext.SaveChangesAsync(); }