public async Task <ActionResult <District> > PostDistrict(District district) { _context.Districts.Add(district); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDistrict", new { id = district.Id }, district)); }
public async Task <District> Add(District district) { var result = _context.Districts.Add(district); await _context.SaveChangesAsync(); return(result.Entity); }
public async Task <Region> Add(Region Region) { var result = _context.Regions.Add(Region); await _context.SaveChangesAsync(); return(result.Entity); }
public async Task <ActionResult <City> > PostCity(City city) { _context.Cities.Add(city); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCity", new { id = city.Id }, city)); }
public async Task <IActionResult> PutCountry(int id, Country country) { if (id != country.Id) { return(BadRequest()); } _context.Entry(country).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CountryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Country> > PostCountry(Country country) { _context.Countries.Add(country); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCountry", new { id = country.Id }, country)); }
public async Task <City> Add(City City) { var result = _context.Cities.Add(City); await _context.SaveChangesAsync(); return(result.Entity); }
public async Task <ActionResult <Region> > PostRegion(Region region) { _context.Regions.Add(region); await _context.SaveChangesAsync(); return(CreatedAtAction("GetRegion", new { id = region.Id }, region)); }
public async Task <ActionResult <District> > PostDistrict(DistrictDto district) { var newDistrict = _context.Districts.Add(new District { Name = district.Name }); await _context.SaveChangesAsync(); var response = _context.Districts.Include(r => r.Region).FirstOrDefault(r => r.Id == newDistrict.Entity.Id); return(CreatedAtAction("GetDistrict", new { id = response.Id }, response)); }
public async Task <ActionResult <City> > PostCity(CityDto city) { var newCity = _context.Cities.Add(new City { Name = city.Name }); await _context.SaveChangesAsync(); var response = _context.Cities.Include(r => r.District).FirstOrDefault(r => r.Id == newCity.Entity.Id); return(CreatedAtAction("GetCity", new { id = response.Id }, response)); }
public async Task <bool> Update(int id, Country country) { _context.Entry(country).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(true); } catch (DbUpdateConcurrencyException) { return(false); } }
public async Task <ActionResult <Region> > PostRegion(RegionDto region) { var newRegion = _context.Regions.Add( new Region { Name = region.Name, CountryId = region.CountryId }); await _context.SaveChangesAsync(); var response = _context.Regions.Include(r => r.Country).FirstOrDefault(r => r.Id == newRegion.Entity.Id); return(CreatedAtAction("GetRegion", new { id = response.Id }, response)); }
public async Task <bool> PutDistrict(int id, District district) { _context.Entry(district).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(true); } catch (DbUpdateConcurrencyException) { return(false); } }
public async Task <bool> Update(Region region) { _context.Entry(region).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RegionExists(region.Id)) { return(false); } throw; } return(true); }