Ejemplo n.º 1
0
        public async Task <IActionResult> Index(string searchName = "")
        {
            var allPerformers = await _dbContext.Performers.ToListAsync();

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

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

            var model = new PerformersAllViewModel()
            {
                Performers = new List <PerformersViewModel>()
            };

            foreach (var performer in allPerformers)
            {
                int albumsNumber = _dbContext.Albums.Where(x => x.PerformerId == performer.Id).Count();
                int songsNumber  = _dbContext.Songs.Where(x => x.PerformerId == performer.Id).Count();

                var singleViewModel = new PerformersViewModel()
                {
                    Id           = performer.Id,
                    Name         = performer.Name,
                    Description  = performer.Description,
                    AlbumsNumber = albumsNumber,
                    SongsNumber  = songsNumber
                };

                model.Performers.Add(singleViewModel);
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var performer = await _dbContext.Performers.FindAsync(id);

            if (performer == null)
            {
                return(NotFound());
            }

            var model = new PerformersViewModel()
            {
                Id          = performer.Id,
                Name        = performer.Name,
                Description = performer.Description
            };

            return(View(model));
        }