Exemplo n.º 1
0
        // GET: Songs
        public ActionResult MySongs()
        {
            var currentUser = this.User.Identity.GetUserId();
            var userSongs   = db.Songs
                              .Where(s => s.Uploader.Id == currentUser)
                              .OrderByDescending(d => d.UploadDate)
                              .Include(u => u.Uploader)
                              .Include(s => s.Tags)
                              .ToList();

            var playlists = db.Playlists
                            .Where(a => a.Creator.Id == currentUser)
                            .ToList();

            var songsPerPage = userSongs.Take(5).ToList();

            var lastPage = Math.Ceiling((decimal)userSongs.Count() / 5);

            var model = new ListAllSongsViewModel
            {
                Songs         = songsPerPage,
                UserPlaylists = playlists,
                LastPage      = lastPage
            };

            return(PartialView(model));
        }
Exemplo n.º 2
0
        public ActionResult List(int?id)
        {
            if (id == null)
            {
                this.AddNotification("Song does not exist", NotificationType.ERROR);
                return(RedirectToAction("MySongs"));
            }

            using (var db = new ApplicationDbContext())
            {
                var songs = db.Tags
                            .Include(t => t.Songs.Select(s => s.Tags))
                            .Include(t => t.Songs.Select(s => s.Uploader))
                            .FirstOrDefault(t => t.id == id)
                            .Songs
                            .ToList();

                var currentUser   = this.User.Identity.GetUserId();
                var userPlaylists = db.Playlists
                                    .Where(a => a.Creator.Id == currentUser)
                                    .ToList();

                var model = new ListAllSongsViewModel
                {
                    Songs         = songs,
                    UserPlaylists = userPlaylists,
                };

                return(View(model));
            }
        }
Exemplo n.º 3
0
        public ActionResult ListSongs(ListAllSongsViewModel songsModel)
        {
            var allSongs         = db.Songs.OrderBy(s => s.Id).ToList();
            var currentPageSongs = allSongs.Skip((songsModel.CurrentPage - 1) * 6).Take(6).ToList();

            songsModel.Songs         = currentPageSongs;
            songsModel.UserPlaylists = LoggedUser();

            return(PartialView("SongPartial", songsModel));
        }
Exemplo n.º 4
0
        public ActionResult Genres()
        {
            var allSongs        = db.Songs.ToList();
            var allGenres       = db.Genres.ToList();
            var currentPageSong = allSongs.Take(6).ToList();
            var songsTotalPages = Math.Ceiling((decimal)allSongs.Count() / 6);

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

            ViewBag.Genres = allGenres;

            return(View(songsModel));
        }
Exemplo n.º 5
0
        public ActionResult MySongs(ListAllSongsViewModel model)
        {
            var currentUser = this.User.Identity.GetUserId();
            var userSongs   = db.Songs
                              .Where(s => s.Uploader.Id == currentUser)
                              .OrderByDescending(d => d.UploadDate)
                              .Include(u => u.Uploader)
                              .Include(s => s.Tags)
                              .ToList();

            var playlists = db.Playlists
                            .Where(a => a.Creator.Id == currentUser)
                            .ToList();

            var currentPageSongs = userSongs.Skip((model.CurrentPage - 1) * 5).Take(5).ToList();

            model.Songs         = currentPageSongs;
            model.UserPlaylists = playlists;

            return(PartialView("SongPartial", model));
        }
Exemplo n.º 6
0
        public ActionResult Genres(int id)
        {
            var selectedGenre = db.Genres.Select(i => i.Id).Contains(id);

            if (!selectedGenre)
            {
                return(HttpNotFound());
            }

            var songsInGenre = db.Songs.Where(g => g.GenreId == id).ToList();
            var lastSongPage = Math.Ceiling((decimal)songsInGenre.Count() / 6);

            var model = new ListAllSongsViewModel
            {
                Songs         = songsInGenre,
                UserPlaylists = LoggedUser(),
                LastPage      = lastSongPage
            };

            return(PartialView("SongPartial", model));
        }
Exemplo n.º 7
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.º 8
0
 public ActionResult SearchSongs(ListAllSongsViewModel model)
 {
     return(null);
 }
Exemplo n.º 9
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());
            }
        }