public IHttpActionResult Post(Song song) { if (!ModelState.IsValid) { return BadRequest(); } this.Data.Songs.Add(song); this.Data.SaveChanges(); return Ok(song); }
public IHttpActionResult Put(int id, Song song) { if (!ModelState.IsValid) { return BadRequest(); } var songFromDb = this.Data.Songs.GetById(id); songFromDb = song; this.Data.Songs.Update(songFromDb); this.Data.SaveChanges(); return Ok(song); }
public IHttpActionResult Post([FromBody]SongDataModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } if (this.data.Genres.Find(model.GenreId) == null) { return this.BadRequest("No such genre can be found."); } var song = new Song { Name = model.Name, GenreId = model.GenreId, Year = model.Year }; this.data.Songs.Add(song); this.data.Savechanges(); return this.Created(this.Url.ToString(), song); }