public async Task <IHttpActionResult> PutCity(int id, EasyCity city) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DB.City cityDb = city.ToDBCity(); cityDb.Id = id; db.Entry(cityDb).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PostCity([FromBody] EasyCity city) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.City.Add(city.ToDBCity()); await db.SaveChangesAsync(); DB.City cityDb = db.City.Where(n => n.Name == city.Name).FirstOrDefault(); return(CreatedAtRoute("DefaultApi", new { id = cityDb.Id }, cityDb)); }