public async Task <ActionResult <ArtistViewModel> > GetArtist(long id)
        {
            var artist = await _context.Artists.Where(x => x.Id == id).FirstOrDefaultAsync();

            if (artist == null)
            {
                return(NotFound());
            }
            var albums = await _context.Albums.Where(x => x.ArtistId == artist.Id).ToListAsync();

            List <AlbumViewModel> albumViewModels = new List <AlbumViewModel>();

            foreach (var item in albums)
            {
                var songs = await _context.Songs.Where(x => x.AlbumId == item.Id).ToListAsync();

                List <SongViewModel> songViewModels = new List <SongViewModel>();
                foreach (var song in songs)
                {
                    var artistman = await _context.Artists.Where(x => x.Id == item.ArtistId).FirstAsync();

                    songViewModels.Add(Mapper.SongToViewModel(song, artist));
                }

                albumViewModels.Add(Mapper.AlbumToViewModel(item, songViewModels, Mapper.ArtistToViewModel(artist)));
            }

            return(Mapper.ArtistToViewModel(artist, albumViewModels));
        }
Example #2
0
        public async Task <ActionResult <IEnumerable <AlbumViewModel> > > GetAlbumByUser()
        {
            var user = await userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                return(Unauthorized(new Response {
                    Status = "Fail", Message = "I don't know how you could possibly get this error message but you managed to do it"
                }));
            }
            var artist = await _context.Artists.Where(x => x.UserId == user.Id).FirstAsync();

            if (artist == null)
            {
                return(Unauthorized());
            }
            var albums = await _context.Albums.Where(x => x.ArtistId == artist.Id).ToListAsync();

            List <AlbumViewModel> AlbumsViewModels = new List <AlbumViewModel>();

            foreach (var item in albums)
            {
                AlbumsViewModels.Add(Mapper.AlbumToViewModel(item, null, Mapper.ArtistToViewModel(artist)));
            }
            return(AlbumsViewModels);
        }
Example #3
0
        public async Task <ActionResult <AlbumViewModel> > GetAlbumByUser(long id)
        {
            var user = await userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                return(Unauthorized(new Response {
                    Status = "Fail", Message = "I don't know how you could possibly get this error message but you managed to do it"
                }));
            }
            var artist = await _context.Artists.Where(x => x.UserId == user.Id).FirstAsync();

            if (artist == null)
            {
                return(Unauthorized());
            }
            var album = await _context.Albums.Where(p => p.Id == id).Where(x => x.ArtistId == artist.Id).FirstOrDefaultAsync();

            if (album == null)
            {
                return(Unauthorized());
            }


            return(Mapper.AlbumToViewModel(album, null, Mapper.ArtistToViewModel(artist)));
        }
Example #4
0
        public async Task <ActionResult <IEnumerable <AlbumViewModel> > > GetAlbums([FromQuery] int pageSize = 30, [FromQuery] int pageIndex = 0)
        {
            var albums = await _context.Albums.Skip(pageSize *pageIndex).Take(pageSize).ToListAsync();

            List <AlbumViewModel> AlbumsViewModels = new List <AlbumViewModel>();

            foreach (var item in albums)
            {
                var artist = await _context.Artists.Where(x => x.Id == item.ArtistId).FirstAsync();

                AlbumsViewModels.Add(Mapper.AlbumToViewModel(item, null, Mapper.ArtistToViewModel(artist)));
            }
            return(AlbumsViewModels);
        }