protected void gvBanners_Sorting(object sender, GridViewSortEventArgs e) { BannerSortingType orderBy = BannerSortingType.IdAsc; switch (e.SortExpression) { case "Priority": orderBy = BannerSortingType.PriorityDesc; if (e.SortDirection == SortDirection.Ascending) { orderBy = BannerSortingType.PriorityAsc; } break; case "Title": orderBy = BannerSortingType.TitleDesc; if (e.SortDirection == SortDirection.Ascending) { orderBy = BannerSortingType.TitleAsc; } break; case "Id": default: orderBy = BannerSortingType.IdDesc; if (e.SortDirection == SortDirection.Ascending) { orderBy = BannerSortingType.IdAsc; } break; } SetState("OrderBy", (int)orderBy); LoadBanners(); }
private void LoadBanners() { string title = null; bool? enabled = null; string fromDate = null; string toDate = null; BannerSortingType orderBy = BannerSortingType.IdAsc; if (HasState(TITLE_FILTER)) { title = GetStringState(TITLE_FILTER); } if (HasState(STATUS_CODE_FILTER)) { enabled = Convert.ToBoolean(GetStringState(STATUS_CODE_FILTER)); } if (HasState(FROM_DATE_FILTER)) { fromDate = GetStringState(FROM_DATE_FILTER); } if (HasState(TO_DATE_FILTER)) { toDate = GetStringState(TO_DATE_FILTER); } if (HasState("OrderBy")) { orderBy = (BannerSortingType)GetIntState("OrderBy"); } var result = CampaignService.GetOfferBannerLoadPaged( pageIndex: gvBanners.CustomPageIndex, pageSize: gvBanners.PageSize, title: title, enabled: enabled, fromDate: fromDate, toDate: toDate, orderBy: orderBy); if (result != null) { gvBanners.DataSource = result.Items; gvBanners.RecordCount = result.TotalCount; gvBanners.CustomPageCount = result.TotalPages; } gvBanners.DataBind(); if (gvBanners.Rows.Count <= 0) { enbNotice.Message = "No records found."; } }
public PagedList <LargeBanner> GetLargeBannerLoadPaged( int pageIndex = 0, int pageSize = 2147483647, string title = null, bool?enabled = null, string fromDate = null, string toDate = null, BannerSortingType orderBy = BannerSortingType.IdAsc) { var query = _largeBannerRepository.Table; if (!string.IsNullOrEmpty(title)) { query = query.Where(x => x.Title.Contains(title)); } if (enabled.HasValue) { query = query.Where(x => x.Enabled == enabled.Value); } DateTime startDate; if (!string.IsNullOrEmpty(fromDate) && DateTime.TryParseExact(fromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out startDate)) { query = query.Where(x => startDate >= x.StartDate); } DateTime endDate; if (!string.IsNullOrEmpty(toDate) && DateTime.TryParseExact(toDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out endDate)) { query = query.Where(x => endDate <= x.EndDate); } int totalRecords = query.Count(); switch (orderBy) { default: case BannerSortingType.IdAsc: query = query.OrderBy(x => x.Id); break; case BannerSortingType.IdDesc: query = query.OrderByDescending(x => x.Id); break; case BannerSortingType.TitleAsc: query = query.OrderBy(x => x.Title); break; case BannerSortingType.TitleDesc: query = query.OrderByDescending(x => x.Title); break; case BannerSortingType.PriorityAsc: query = query.OrderBy(x => x.Priority); break; case BannerSortingType.PriorityDesc: query = query.OrderByDescending(x => x.Priority); break; } query = query.Skip(pageIndex * pageSize).Take(pageSize); var list = query.ToList(); return(new PagedList <LargeBanner>(list, pageIndex, pageSize, totalRecords)); }