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) })); }
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) })); }