Exemple #1
0
        public ActionResult Index()
        {
            var artistBus = new ArtistBusiness();
            var artists   = artistBus.GetArtistsWithAlbumCount();

            return(new JsonNetResult(artists));
        }
Exemple #2
0
        public ActionResult SaveArtist(Artist postedArtist)
        {
            if (!ModelState.IsValid)
            {
                throw new CallbackException("Model binding failed.", 500);
            }

            var artistBus = new ArtistBusiness();

            // attach to context
            var artist = artistBus.Attach(postedArtist);

            if (!artistBus.Validate())
            {
                throw new CallbackException("Please correct the following: " + artistBus.ValidationErrors.ToString());
            }

            if (!artistBus.Save())
            {
                throw new CallbackException("Unable to save artist: " + artistBus.ErrorMessage);
            }

            var albumBus = new AlbumBusiness();
            var albums   = albumBus.GetAlbumsForArtist(artist.Id);

            return(new JsonNetResult(new ArtistResponse
            {
                Artist = artist,
                Albums = albums
            }));
        }
        public void GetAritstsTest()
        {
            var albumBus = new ArtistBusiness();
            var artists = albumBus.GetArtists();
            Assert.IsNotNull(artists, albumBus.ErrorMessage);

            var artistList = artists.ToList();

            Assert.IsTrue(artistList.Count > 0, "List should return some data.");
        }
        public void GetAritstsTest()
        {
            var albumBus = new ArtistBusiness();
            var artists  = albumBus.GetArtists();

            Assert.IsNotNull(artists, albumBus.ErrorMessage);

            var artistList = artists.ToList();

            Assert.IsTrue(artistList.Count > 0, "List should return some data.");
        }
Exemple #5
0
        public ActionResult LookupArtist(string search)
        {
            var artistBus = new ArtistBusiness();
            var artists   = artistBus.GetArtistLookup(search)
                            .Select(art => new
            {
                name     = art.ArtistName,
                id       = art.ArtistName,
                artistId = art.Id
            });

            return(new JsonNetResult(artists.ToList()));
        }
        public void GetArtistsWithCountsTest()
        {
            var albumBus = new ArtistBusiness();
            var artists = albumBus.GetArtistsWithAlbumCount() as IEnumerable<dynamic>;

            Assert.IsNotNull(artists, albumBus.ErrorMessage);

            foreach (object art in artists)
            {
                var artist = (dynamic) art;
                string name = artist.ArtistName;
                int count = artist.AlbumCount;
                Console.WriteLine(name + " (" + count + ")");
            }
        }
Exemple #7
0
        public void GetArtistsWithCountsTest()
        {
            var albumBus = new ArtistBusiness();
            var artists  = albumBus.GetArtistsWithAlbumCount() as IEnumerable <dynamic>;

            Assert.IsNotNull(artists, albumBus.ErrorMessage);


            foreach (var artist in artists)
            {
                string name  = artist.ArtistName as string;
                int    count = artist.AlbumCount;
                Console.WriteLine(name + " (" + count + ")");
            }
        }
Exemple #8
0
        public ActionResult DeleteArtist(int id)
        {
            if (id < 1)
            {
                throw new CallbackException("Invalid Id passed.");
            }

            var artistBus = new ArtistBusiness();

            if (!artistBus.Delete(id, true, true))
            {
                throw new CallbackException("Couldn't delete artist: " + artistBus.ErrorMessage);
            }

            return(new JsonNetResult(true));
        }
Exemple #9
0
 public Artist Add(Artist artist)
 {
     try
     {
         var artbs = new ArtistBusiness();
         return(artbs.nuevo(artist));
     }
     catch (Exception ex)
     {
         var httpError = new HttpResponseMessage()
         {
             StatusCode   = (HttpStatusCode)422,
             ReasonPhrase = ex.Message
         };
         throw new HttpResponseException(httpError);
     }
 }
        public Artist Find(int id)
        {
            try
            {
                var bc = new ArtistBusiness();
                return(bc.GetArtist(id));
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode   = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }
        public void Remove(int id)
        {
            try
            {
                var bc = new ArtistBusiness();
                bc.BorrarArtista(id);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode   = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }
Exemple #12
0
        public List <Artist> List()
        {
            try
            {
                var am = new ArtistBusiness();
                return((List <Artist>)am.List());
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = new StringContent(ex.Message),
                };

                throw new HttpResponseException(httpError);
            }
        }
        public void Remove(int id)
        {
            try
            {
                var bc = new ArtistBusiness();
                bc.Remove(id);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = new StringContent(ex.Message)
                };

                throw new HttpResponseException(httpError);
            }
        }
        public List <Artist> List()
        {
            try
            {
                var bc = new ArtistBusiness();
                return(bc.ListarTodosLosArtistas());
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode   = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }
        public Artist Find(int id)
        {
            try
            {
                var bc = new ArtistBusiness();
                return(bc.Get(id));
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = new StringContent(ex.Message)
                };

                throw new HttpResponseException(httpError);
            }
        }
Exemple #16
0
        public Artist GetById(int id)
        {
            try
            {
                var artbs = new ArtistBusiness();
                return(artbs.GetbyID(id));
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode   = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }
Exemple #17
0
        public void Remove(int id)
        {
            try
            {
                var artbs  = new ArtistBusiness();
                var artist = artbs.GetbyID(id);
                artbs.Borrar(artist);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode   = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }
        public void Edit(Artist artist)
        {
            try
            {
                var bc = new ArtistBusiness();
                bc.EditarArtista(artist);
            }
            catch (Exception ex)
            {
                // Repack to Http error.
                var httpError = new HttpResponseMessage()
                {
                    StatusCode   = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }
        public void Edit(Artist artist)
        {
            try
            {
                var bc = new ArtistBusiness();
                bc.Edit(artist);
            }
            catch (Exception ex)
            {
                // Repack to Http error.
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = new StringContent(ex.Message)
                };

                throw new HttpResponseException(httpError);
            }
        }
Exemple #20
0
        public Artist Add(Artist artist)
        {
            try
            {
                var am = new ArtistBusiness();
                am.Add(artist);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = new StringContent(ex.Message),
                };

                throw new HttpResponseException(httpError);
            }

            return(artist);
        }
Exemple #21
0
        public ActionResult Get(int id = -1)
        {
            if (id < 1)
            {
                throw new CallbackException("Invalid id passed.");
            }

            var artistBus = new ArtistBusiness();
            var artist    = artistBus.Load(id);

            if (artist == null)
            {
                throw new CallbackException("Invalid id passed.");
            }

            var albumBus = new AlbumBusiness();
            var albums   = albumBus.GetAlbumsForArtist(artist.Id);

            return(new JsonNetResult(new ArtistResponse
            {
                Artist = artist,
                Albums = albums
            }));
        }