public async Task<IHttpActionResult> PostGenre(Genre genre) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Genres.Add(genre); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (GenreExists(genre.Name)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = genre.Name }, genre); }
// POST: odata/GenresImporter public async Task<IHttpActionResult> Post(Genre genre) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Genres.Add(genre); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (GenreExists(genre.GenreId)) { return Conflict(); } else { throw; } } return Created(genre); }
public async Task<IHttpActionResult> PutGenre(string id, Genre genre) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != genre.Name) { return BadRequest(); } db.Entry(genre).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GenreExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }