Exemplo n.º 1
0
        public ActionResult ByPlaylist(string playlistName)
        {
            // TODO: Use DI
            var playlistRepo = new SmartPlaylistRepository(new AppDbContext());

            var playlist = playlistRepo.GetByName(playlistName);

            if (playlist == null)
            {
                return(HttpNotFound("Playlist not found."));
            }
            ViewBag.PlaylistName = playlist.Name;
            return(View(_songRepository.List(playlist.Specification)));
        }
Exemplo n.º 2
0
        public ActionResult Index(List <int> selectedGenres     = null,
                                  List <string> selectedArtists = null,
                                  string titleSearch            = null,
                                  int minRating       = 0,
                                  string filter       = null,
                                  string save         = null,
                                  string playlistName = null)
        {
            if (selectedArtists == null)
            {
                selectedArtists = new List <string>();
            }
            if (selectedGenres == null)
            {
                selectedGenres = new List <int>();
            }

            var spec = new GlobalSongSpecification();

            spec.ArtistsToInclude.AddRange(selectedArtists);
            spec.GenreIdsToInclude.AddRange(selectedGenres);
            spec.MinRating   = minRating;
            spec.TitleFilter = titleSearch;

            var songs = _songRepository.List(spec);

            var viewModel = new HomeViewModel();

            viewModel.Artists         = _songRepository.AllArtists().ToList();
            viewModel.Genres          = _songRepository.AllGenres().ToList();
            viewModel.SelectedArtists = viewModel.Artists
                                        .Where(a => spec.ArtistsToInclude.Contains(a))
                                        .ToList();
            viewModel.SelectedGenres = viewModel.Genres
                                       .Where(g => selectedGenres.Contains(g.Id))
                                       .ToList();
            viewModel.Songs = songs.ToList();

            if (save != null)
            {
                var smartPlaylist = new SmartPlaylist();
                smartPlaylist.Name          = playlistName;
                smartPlaylist.Specification = spec;
                var playlistRepo = new SmartPlaylistRepository(_dbContext);
                playlistRepo.Add(smartPlaylist);
                return(RedirectToAction("Index", "SmartPlaylists"));
            }

            return(View(viewModel));
        }
Exemplo n.º 3
0
 public IndexModel(AppDbContext dbContext)
 {
     _dbContext = dbContext;
     _smartPlaylistRepository = new SmartPlaylistRepository(dbContext);
 }
Exemplo n.º 4
0
 public SmartPlaylistsController(SmartPlaylistRepository smartPlaylistRepository)
 {
     _smartPlaylistRepository = smartPlaylistRepository;
 }