public IHttpActionResult Create(GenreModel genre) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newGenre = new Genre { Name = genre.Name }; this.data.Genres.Add(newGenre); this.data.SaveChanges(); genre.GenreId = newGenre.GenreId; return Ok(genre); }
public IHttpActionResult Update(int id, GenreModel genre) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var genreFromDb = this.data.Genres.All().FirstOrDefault(s => s.GenreId == id); if (genreFromDb == null) { return BadRequest("Such genre does not exist!"); } genreFromDb.Name = genre.Name; this.data.SaveChanges(); genre.GenreId = id; return Ok(genre); }