Exemplo n.º 1
0
        public ActionResult ListPlaylists(ListAllPlaylistsViewModel playlistsModel)
        {
            var allPlaylists         = db.Playlists.Where(p => p.IsPublic).OrderBy(p => p.Id).ToList();
            var currentPagePlaylists = allPlaylists.Skip((playlistsModel.CurrentPage - 1) * 6).Take(6).ToList();

            playlistsModel.Playlists = currentPagePlaylists;

            return(PartialView("PlaylistPartial", playlistsModel));
        }
        public ActionResult MyPlaylists(ListAllPlaylistsViewModel playlistsModel)
        {
            var currentUserId        = this.User.Identity.GetUserId();
            var userPlaylists        = db.Playlists.Where(u => u.Creator.Id == currentUserId).OrderByDescending(p => p.DateCreated).ToList();
            var currentPagePlaylists = userPlaylists.Skip((playlistsModel.CurrentPage - 1) * 6).Take(6).ToList();

            playlistsModel.Playlists = currentPagePlaylists;

            return(PartialView("PlaylistPartial", playlistsModel));
        }
Exemplo n.º 3
0
        public ActionResult SearchPlaylists(string query, ListAllPlaylistsViewModel playlistsModel)
        {
            var publicPlaylists = db.Playlists.Where(playlist => playlist.IsPublic).ToList();

            var playlistResult = publicPlaylists
                                 .AsQueryable()
                                 .Where(playlist => playlist.PlaylistName.ToLower().Contains(query.ToLower()))
                                 .ToList();

            var currentPagePlaylists = publicPlaylists.Skip((playlistsModel.CurrentPage - 1) * 6).Take(6).ToList();

            playlistsModel.Playlists = currentPagePlaylists;
            return(PartialView("PlaylistPartial", playlistsModel));
        }
        public ActionResult MyPlaylists()
        {
            var currentUserId    = this.User.Identity.GetUserId();
            var userPlaylists    = db.Playlists.Where(u => u.Creator.Id == currentUserId).OrderByDescending(p => p.DateCreated).ToList();
            var playlistsPerPage = userPlaylists.Take(6).ToList();

            var lastPage = Math.Ceiling((decimal)userPlaylists.Count() / 6);

            var playlistsModel = new ListAllPlaylistsViewModel
            {
                Playlists = playlistsPerPage,
                LastPage  = lastPage
            };

            return(PartialView(playlistsModel));
        }
Exemplo n.º 5
0
        public ActionResult List(string id)
        {
            switch (id)
            {
            case "Songs":
                var allSongs         = db.Songs.OrderBy(s => s.Id).ToList();
                var songsTotalPages  = Math.Ceiling((decimal)allSongs.Count() / 6);
                var currentPageSongs = allSongs.Take(6).ToList();

                var songsModel = new ListAllSongsViewModel
                {
                    Songs         = currentPageSongs,
                    UserPlaylists = LoggedUser(),
                    LastPage      = songsTotalPages
                };

                return(View("ListSongs", songsModel));

            case "Playlists":
                var allPlaylists         = db.Playlists.Where(p => p.IsPublic).OrderBy(p => p.Id).ToList();
                var playlistsTotalPages  = Math.Ceiling((decimal)allPlaylists.Count() / 6);
                var currentPagePlaylists = allPlaylists.Take(6).ToList();

                var playlistsModel = new ListAllPlaylistsViewModel
                {
                    Playlists = currentPagePlaylists,
                    LastPage  = playlistsTotalPages
                };

                return(View("ListPlaylists", playlistsModel));

            default:
                this.AddNotification("Somethings get wrong", NotificationType.WARNING);
                return(null);
            }
        }
Exemplo n.º 6
0
        public ActionResult Search(string query, string type)
        {
            switch (type)
            {
            case "songs":
                var allSongs = db.Songs;

                var songResult = allSongs
                                 .AsQueryable()
                                 .Where(song => song.Artist.ToLower().Contains(query.ToLower()) ||
                                        song.Title.ToLower().Contains(query.ToLower()))
                                 .ToList();

                var songsPerPage    = songResult.Take(6).ToList();
                var songsTotalPages = Math.Ceiling((decimal)songResult.Count() / 6);

                var songModel = new ListAllSongsViewModel
                {
                    Songs         = songsPerPage,
                    UserPlaylists = LoggedUser(),
                    LastPage      = songsTotalPages,
                };

                if (query == string.Empty)
                {
                    songModel.Songs    = allSongs.ToList();
                    songModel.LastPage = Math.Ceiling((decimal)allSongs.Count() / 6);
                }

                return(PartialView("SearchSongs", songModel));

            case "playlists":
                var publicPlaylists = db.Playlists.Where(playlist => playlist.IsPublic).ToList();

                var playlistResult = publicPlaylists
                                     .AsQueryable()
                                     .Where(playlist => playlist.PlaylistName.ToLower().Contains(query.ToLower()))
                                     .ToList();

                var playlistsPerPage    = playlistResult.Take(6).ToList();
                var playlistsTotalPages = Math.Ceiling((decimal)playlistResult.Count() / 6);

                var playlistModel = new ListAllPlaylistsViewModel
                {
                    Playlists = playlistsPerPage,
                    LastPage  = playlistsTotalPages,
                };

                if (query == string.Empty)
                {
                    playlistModel.Playlists = publicPlaylists;
                    playlistModel.LastPage  = Math.Ceiling((decimal)publicPlaylists.Count() / 6);
                }

                return(PartialView("SearchPlaylists", playlistModel));

            default:

                return(HttpNotFound());
            }
        }