public IHttpActionResult Post(ArtistAddRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Invalid model state"); } var artist = Mapper.Map<ArtistAddRequestModel, Artist>(model); this.Data.Artists.Add(artist); this.Data.SaveChanges(); return this.Ok(artist.Id); }
public IHttpActionResult Put(int id, ArtistAddRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Invalid model state"); } var artist = this.Data.Artists.All().FirstOrDefault(x => x.Id == id); if (artist == null) { return this.NotFound(); } artist.Name = model.Name; artist.BirthDate = model.BirthDate; artist.Country = model.Country; this.Data.Artists.Update(artist); this.Data.SaveChanges(); return this.Ok(artist.Id); }