public IHttpActionResult Create(ArtistOutputModel artist) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var newArtist = this.CreateArtistFromModel(artist); artist.Id = newArtist.Id; return this.Ok(artist); }
public IHttpActionResult Update(ArtistOutputModel artistUpdate) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var artist = this.GetArtistById(artistUpdate.Id); if (artist == null) { return this.BadRequest(NoSuchArtist); } this.UpdateArtist(artistUpdate, artist); return this.Ok(artistUpdate); }
private Artist CreateArtistFromModel(ArtistOutputModel artist) { var newArtist = new Artist { Id = artist.Id, Name = artist.Name, Country = artist.Country, Nickname = artist.Nickname, DateOfBirth = artist.DateOfBirth, }; this.musicArtistsData.Artists.Add(newArtist); this.musicArtistsData.SaveChanges(); return newArtist; }
private void UpdateArtist(ArtistOutputModel artistUpdate, Artist artist) { artist.Name = artistUpdate.Name; artist.Country = artistUpdate.Country; artist.Nickname = artistUpdate.Nickname; artist.DateOfBirth = artistUpdate.DateOfBirth; this.musicArtistsData.SaveChanges(); }