コード例 #1
0
        public async Task <ViewResult> Index(string sortOrder, string currentFilter, string searchString, int?page, int?pageSize, string currentSort)
        {
            ViewBag.CurrentSort = sortOrder ?? currentSort;
            sortOrder           = ViewBag.CurrentSort;

            ViewBag.SortTitle    = (string.IsNullOrEmpty(sortOrder) ? "title_desc" : "");
            ViewBag.SortDuration = ((sortOrder == "duration") ? "duration_desc" : "duration");
            ViewBag.SortArtist   = ((sortOrder == "artist") ? "artist_desc" : "artist");

            var currentPageSize = pageSize.HasValue ? pageSize.Value : 10;

            ViewBag.CurrentPageSize = currentPageSize;

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            var playlist = new List <MySongs>();

            var table = TableStorageService.ConnectToTable(Constants.MySongsTableName);
            TableContinuationToken tableContinuationToken = null;

            var channel = CookieService.Get(Request, Constants.ChannelCookieName);

            var filter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, channel);
            var query  = new TableQuery <MySongs>().Where(filter);

            do
            {
                var tableQuerySegment = await table.ExecuteQuerySegmentedAsync(query, tableContinuationToken);

                playlist.AddRange(tableQuerySegment.Results);
                tableContinuationToken = tableQuerySegment.ContinuationToken;
            }while (tableContinuationToken != null);

            var source = string.IsNullOrWhiteSpace(searchString)
                ? playlist
                         //: playlist.Where(x => x.Title.Contains(searchString));
                : EasyCustomSearch.SearchSong(searchString, playlist);

            switch (sortOrder)
            {
            case "title_desc":
                source = source.OrderByDescending(x => x.Title);
                break;

            case "duration":
                source = source.OrderBy(x => x.Duration).ThenBy(x => x.Title);
                break;

            case "duration_desc":
                source = source.OrderByDescending(x => x.Duration).ThenBy(x => x.Title);
                break;

            case "artist":
                source = source.OrderBy(x => x.Channel).ThenBy(x => x.Title);
                break;

            case "artist_desc":
                source = source.OrderByDescending(x => x.Channel).ThenBy(x => x.Title);
                break;

            default:
                source = source.OrderBy(x => x.Title);
                break;
            }

            var pageNumber = page ?? 1;

            return(View(new MyPageSongs()
            {
                MySongs = source.ToPagedList(pageNumber, currentPageSize)
            }));
        }
コード例 #2
0
        public async Task <ViewResult> Index(string sortOrder, string currentFilter, string searchString, int?page, int?pageSize, string currentSort, bool?checkNew)
        {
            ViewBag.CurrentSort = sortOrder ?? currentSort;
            sortOrder           = ViewBag.CurrentSort;

            ViewBag.SortTitle    = (string.IsNullOrEmpty(sortOrder) ? "title_desc" : "");
            ViewBag.SortDuration = ((sortOrder == "duration") ? "duration_desc" : "duration");
            ViewBag.SortCounter  = ((sortOrder == "counter") ? "counter_desc" : "counter");
            ViewBag.SortArtist   = ((sortOrder == "artist") ? "artist_desc" : "artist");
            ViewBag.SortNumber   = ((sortOrder == "number") ? "number_desc" : "number");

            var currentPageSize = pageSize.HasValue ? pageSize.Value : 10;

            ViewBag.CurrentPageSize = currentPageSize;

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            ViewBag.CheckNew = checkNew;

            var playlist = await TableStorageService.RetrieveAllEntities <AllSongs>(Constants.AllSongsTableName);

            var source = string.IsNullOrWhiteSpace(searchString)
                ? playlist
                : EasyCustomSearch.SearchSong(searchString, playlist);

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                var num = -1;

                if (int.TryParse(searchString, out num))
                {
                    var song = playlist.Where(x => x.RowKey == searchString || x.RowKey == num.ToString("D4"));
                    if (song != null)
                    {
                        if (!source.Any(x => x.RowKey == searchString || x.RowKey == num.ToString("D4")))
                        {
                            source = source.Union(song);
                        }
                    }
                }
            }

            if (checkNew.HasValue)
            {
                if (checkNew.Value)
                {
                    source = source.Where(x => x.Game == "NEW" || x.RecentlyAdded == "✓");
                }
            }

            switch (sortOrder)
            {
            case "title_desc":
                source = source.OrderByDescending(x => x.OriginalTitle);
                break;

            case "duration":
                source = source.OrderBy(x => x.Duration).ThenBy(x => x.OriginalTitle);
                break;

            case "duration_desc":
                source = source.OrderByDescending(x => x.Duration).ThenBy(x => x.OriginalTitle);
                break;

            case "counter":
                source = source.OrderBy(x => x.Counter).ThenBy(x => x.OriginalTitle);
                break;

            case "counter_desc":
                source = source.OrderByDescending(x => x.Counter).ThenBy(x => x.OriginalTitle);
                break;

            case "artist":
                source = source.OrderBy(x => x.Channel).ThenBy(x => x.OriginalTitle);
                break;

            case "artist_desc":
                source = source.OrderByDescending(x => x.Channel).ThenBy(x => x.OriginalTitle);
                break;

            case "number":
                source = source.OrderBy(x => x.RowKey);
                break;

            case "number_desc":
                source = source.OrderByDescending(x => x.RowKey);
                break;

            default:
                // no va para respetar la busqueda source = source.OrderBy(x => x.OriginalTitle);
                break;
            }

            var pageNumber = page ?? 1;

            return(View(new PageSongs()
            {
                AllSongs = source.ToPagedList(pageNumber, currentPageSize)
            }));
        }
コード例 #3
0
        public async Task <ActionResult> RequestSong(IFormCollection collection)
        {
            var searchString = collection["search"];

            var playlist = await TableStorageService.RetrieveAllEntities <AllSongs>(Constants.AllSongsTableName);

            var song = EasyCustomSearch.SearchSongFirst(searchString, playlist);

            if (song != null)
            {
                var tableSong = TableStorageService.ConnectToTable(Constants.CurrentSongTableName);
                var queryCS   = await tableSong.ExecuteQuerySegmentedAsync(new TableQuery <AzureTableSong>(), null);

                var currentSong = queryCS.Results.FirstOrDefault();

                if (currentSong.RowKey != song.RowKey)
                {
                    var position = 1;
                    var channel  = CookieService.Get(Request, Constants.ChannelCookieName);

                    var user = await userManager.GetUserAsync(User);

                    var userName = user.UserName;

                    var isModOwner = await userManager.IsInRoleAsync(user, "Moderator") ||
                                     await userManager.IsInRoleAsync(user, "Owner");

                    var queueSongs = await TableStorageService.RetrieveAllEntities <AzureTableSong>(Constants.QueueTableName);

                    if (queueSongs.Count > 0)
                    {
                        if (!isModOwner)
                        {
                            var friend = await TableStorageService.RetrieveEntity <Friends>(channel, "1", Constants.FriendsTableName);

                            if (friend != null)
                            {
                                var friendRequests = queueSongs.Count(x => x.RequestedById == channel);
                                if (friendRequests > 1)
                                {
                                    return(RedirectToAction("Index", "SongsQueue", new { ac = "Error. You already have two song requests on the queue.", type = "danger" }));
                                }
                            }
                            else
                            {
                                var userExists = queueSongs.Any(x => x.RequestedById == channel);
                                if (userExists)
                                {
                                    return(RedirectToAction("Index", "SongsQueue", new { ac = "Error. You already have a song request on the queue.", type = "danger" }));
                                }
                            }
                        }

                        var songExists = queueSongs.Any(x => x.RowKey == song.RowKey);
                        if (songExists)
                        {
                            return(RedirectToAction("Index", "SongsQueue", new { ac = $"Error. That song is already on the queue.", type = "danger" }));
                        }

                        queueSongs = queueSongs.OrderBy(x => x.Position).ToList();
                        position   = queueSongs.Last().Position + 1;
                    }

                    var lastRequest = (song.LastTimeRequested.HasValue)
                        ? MathFunctions.GetCooldownMinutes(song.LastTimeRequested.Value) : 100;

                    if (isModOwner || lastRequest > 60)
                    {
                        var updateSong = await TableStorageService.RetrieveEntity <AllSongs>(song.PartitionKey, song.RowKey, Constants.AllSongsTableName);

                        updateSong.Counter           = song.Counter0 + 1;
                        updateSong.LastTimeRequested = DateTime.UtcNow;
                        await TableStorageService.MergeEntity(updateSong, Constants.AllSongsTableName);

                        var newSongQueue = new AzureTableSong()
                        {
                            PartitionKey      = song.PartitionKey,
                            RowKey            = song.RowKey,
                            Title             = song.OriginalTitle,
                            OriginalGame      = song.OriginalGame,
                            LowerCaseTitle    = song.Title,
                            Channel           = song.Channel,
                            VideoId           = song.YouTubeLink.Replace("https://youtu.be/", string.Empty),
                            YouTubeLink       = song.YouTubeLink,
                            Duration          = song.Duration,
                            TotalTime         = 0,
                            RecentlyAdded     = song.RecentlyAdded,
                            RequestedBy       = userName,
                            RequestedById     = channel,
                            Counter           = song.Counter0 + 1,
                            Likes             = song.Likes0,
                            Position          = position,
                            LastTimeRequested = song.LastTimeRequested
                        };

                        await TableStorageService.InsertEntity(newSongQueue, Constants.QueueTableName);

                        return(RedirectToAction("Index", "SongsQueue", new { ac = $"The song was added to the queue in position {position}.", type = "success" }));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "SongsQueue", new { ac = $"Error. That song is in cooldown. Please wait {60 - lastRequest} minutes to request it again.", type = "danger" }));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "SongsQueue", new { ac = "Error. The song is currently playing.", type = "danger" }));
                }
            }
            else
            {
                return(RedirectToAction("Index", "SongsQueue", new { ac = "Error. The song does not exist.", type = "danger" }));
            }
        }