public async Task <IActionResult> PutCountry(int id, Country country) { if (id != country.CountryId) { return(BadRequest()); } CountryValid c = new CountryValid(_context, country); if (!c.Valid()) { 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 <IActionResult> PutCountry(int id, Country country) { if (id != country.Id) { return(BadRequest()); } CountryValid valid = new CountryValid(_context, country); if (valid.Valid() == false) { 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) { CountryValid c = new CountryValid(_context, country); if (!c.Valid()) { return(BadRequest("Країна з такою назвою вже існує")); } _context.Country.Add(country); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCountry", new { id = country.CountryId }, country)); }
public async Task <ActionResult <Country> > PostCountry(Country country) { CountryValid valid = new CountryValid(_context, country); if (valid.Valid() == false) { return(BadRequest("Данная страна уже существует")); } _context.Countries.Add(country); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCountry", new { id = country.Id }, country)); }