public IHttpActionResult Create(AlbumModel album) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newAlbum = new Album { Title = album.Title }; this.data.Albums.Add(newAlbum); this.data.SaveChanges(); album.Id = newAlbum.Id; return Ok(album); }
public IHttpActionResult Update(int id, AlbumModel album) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var existingAlbum = this.data.Albums.All().First(a => a.Id == id); if (existingAlbum == null) { return BadRequest("Such album does not exist!"); } existingAlbum.Title = album.Title; this.data.SaveChanges(); album.Id = id; return Ok(album); }