public ActionResult All()
        {
            AlbumsAllViewModel albumCollectionViewModel = new AlbumsAllViewModel()
            {
                Albums = this.albumsService.GetAllAlbums().Select(album => new AlbumViewModel()
                {
                    Id = album.Id, Name = album.Name
                }).ToList()
            };

            return(this.View(albumCollectionViewModel));
        }
        public HttpResponse All()
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var albums = this.albumsService
                         .GetAll()
                         .Select(a => new AlbumsListingViewModel
            {
                Id   = a.Id,
                Name = a.Name
            })
                         .ToList();

            var albumsAllViewModel = new AlbumsAllViewModel
            {
                Albums = albums
            };

            return(this.View(albumsAllViewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index(string searchName)
        {
            var allAlbums = _dbContext.Albums.ToList();

            allAlbums = allAlbums.OrderBy(x => x.Name).ToList();

            if (searchName != null && searchName != "")
            {
                allAlbums = allAlbums.Where(x => x.Name.Contains(searchName)).ToList();
            }

            var model = new AlbumsAllViewModel()
            {
                Albums = new List <AlbumsViewModel>()
            };



            foreach (var album in allAlbums)
            {
                int    songNumber    = _dbContext.Songs.Where(x => x.AlbumId == album.Id).Count();
                string performerName = (await _dbContext.Performers.FindAsync(album.PerformerId)).Name;

                var singleViewModel = new AlbumsViewModel()
                {
                    Id            = album.Id,
                    Name          = album.Name,
                    PerformerId   = album.PerformerId,
                    PerformerName = performerName,
                    SongsNumber   = songNumber
                };

                model.Albums.Add(singleViewModel);
            }

            return(View(model));
        }