Ejemplo n.º 1
0
        public IHttpActionResult UpdateArtist(int id, [FromBody] ArtistBindingModel artist)
        {
            var updateArtist = this.Data.Artists.Find(id);

            try
            {
                if (artist.Name != null)
                {
                    updateArtist.Name = artist.Name;
                }

                if (artist.Country != null)
                {
                    updateArtist.Country = artist.Country;
                }

                if (artist.DateOfBirth != null)
                {
                    updateArtist.DateOfBirth = (DateTime)artist.DateOfBirth;
                }

                this.Data.Artists.Update(updateArtist);
                this.Data.SaveChanges();
            }
            catch (NullReferenceException)
            {
                return(this.NotFound());
            }

            return(this.Ok());
        }
Ejemplo n.º 2
0
        public IHttpActionResult AddArtist([FromBody] ArtistBindingModel artist)
        {
            this.Data.Artists.AddArtist(artist.Name, artist.Country, (DateTime)artist.DateOfBirth);
            this.Data.SaveChanges();

            return(this.Ok());
        }
Ejemplo n.º 3
0
        //[Route("api/artists/{id}")]
        public IHttpActionResult ArtistsById(int id)
        {
            var artist = this.Data.Artists.Find(id);

            if (artist == null)
            {
                return(this.NotFound());
            }

            var artistResult = new ArtistBindingModel
            {
                Name        = artist.Name,
                Country     = artist.Country,
                DateOfBirth = artist.DateOfBirth
            };

            return(this.Ok(artistResult));
        }
Ejemplo n.º 4
0
        public IHttpActionResult AddSongs([FromBody] ArtistBindingModel artist)
        {
            var artistObj = this.Data.Artists.All().FirstOrDefault(a => a.Name == artist.Name);

            if (artistObj == null)
            {
                return(this.NotFound());
            }

            artist.Songs.ForEach(s =>
            {
                var song = this.Data.Songs.Find(s);
                if (song != null)
                {
                    artistObj.Songs.Add(song);
                }
            });

            this.Data.Artists.SaveChanges();
            return(this.Ok());
        }
Ejemplo n.º 5
0
        public IHttpActionResult GetSongs([FromBody] ArtistBindingModel artist)
        {
            var artistObj = this.Data.Artists
                            .All()
                            .FirstOrDefault(a => a.Name == artist.Name);


            if (artistObj != null)
            {
                var songs = artistObj.Songs
                            .Select(s => new SongBindingModel
                {
                    Title = s.Title,
                    Genre = s.Genre,
                    Year  = s.Year
                });

                return(this.Ok(songs));
            }

            return(this.NotFound());
        }