public IHttpActionResult Post(ArtistRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var artist = new Artist { Name = model.Name, DateOfBirth = model.DateOfBirth }; this.data.Artists.Add(artist); this.data.Artists.SaveChanges(); return this.Ok(artist); }
public IHttpActionResult Put(int id, ArtistRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var artist = this.data.Artists .All() .FirstOrDefault(a => a.Id == id); if (artist == null) { return this.BadRequest("Artist with id " + id + " does not exist!"); } artist.Name = model.Name; artist.DateOfBirth = model.DateOfBirth; this.data.Artists.Update(artist); this.data.Artists.SaveChanges(); return this.Ok(model); }