コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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();
        }