public async Task GetAsync_Pagination_With_First_10_Entities_Test() { var token = default(TablePaginationToken); var entity = new MessageEntity(); var entities = new List <MessageEntity>(); var options = new TableQueryOptions { SelectProperties = "Message", Top = 10 }; //optional do { var result = await Client.QueryAsync <MessageEntity>(entity, token, options); entities.AddRange(result.Results); token = result.TablePaginationToken; if (result.Results.Count <= 10) { break; } } while (token != null); Assert.IsTrue(entities.Count <= 10); }
// GET: FuelReceipts public async Task <ActionResult> Index(int?id, [Form] TableQueryOptions queryOptions, string searchString) { ViewBag.QueryOptions = queryOptions; var start = QueryOptionsCalculator.CalculateStartPage(queryOptions); ViewBag.CarId = id; if (id != null) { var results = await dbReceipt.GetAll(); var resultsCar = await dbCar.Get(id.GetValueOrDefault()); ViewBag.CarName = $"{resultsCar.CarProducer} {resultsCar.CarModel}"; ViewBag.NumberOfEntries = results.Count(); var receiptViewModels = results.Where(m => m.FueledCarId == id).Select(vm => vm.ToViewModel()).AsQueryable <FuelReceiptViewModel>(); ViewBag.NumberOfEntries = receiptViewModels.Count(); if (!String.IsNullOrEmpty(searchString)) { searchString = searchString.ToUpper(); receiptViewModels = receiptViewModels.Where(r => r.RefuelingDate.ToString().Contains(searchString) || r.PetrolStationName.ToUpper().Contains(searchString) || r.FuelPrice.ToString().Contains(searchString) || r.FuelAmount.ToString().Contains(searchString) || r.FuelConsumption.ToString().Contains(searchString) || r.PriceFor100km.ToString().Contains(searchString)); } queryOptions.TotalPages = QueryOptionsCalculator.CalculateTotalPages(receiptViewModels.Count(), queryOptions.PageSize); return(View(receiptViewModels.OrderBy(queryOptions.Sort).Skip(start).Take(queryOptions.PageSize).ToList())); } return(RedirectToAction("Index", "Cars")); }
public async Task FilterCondition_Two_Property_Test() { var token = default(TablePaginationToken); var entity = new UserEntity(); var entities = new List <MessageEntity>(); var options = new TableQueryOptions { Filters = new[] { new FilterCondition(FilterOperator.And) { Conditions = new[] { new CompareCondition("PartitionKey", CompareOperator.Equal, "Smith"), new CompareCondition("Email", CompareOperator.Equal, "*****@*****.**"), } } } }; do { var result = await Client.QueryAsync <MessageEntity>(entity, token, options); entities.AddRange(result.Results); token = result.TablePaginationToken; } while (token != null); Assert.IsTrue(entities.Count > 0); }
private static object BuildSortIcon(bool isCurrentSortField, TableQueryOptions queryOptions) { string sortIcon = "fa-sort"; if (isCurrentSortField) { sortIcon += (queryOptions.SortOrder == SortOrder.descending) ? "-asc" : "-desc"; } return(string.Format("<i class=\"{0} {1}\"></i>", "fa", sortIcon)); }
private static string BuildNextLink(UrlHelper urlHelper, TableQueryOptions queryOptions, string actionName) { return(string.Format( "<a class=\"page-link\" href=\"{0}\">{1}</a>", urlHelper.Action(actionName, new { SortOrder = queryOptions.SortOrder, SortField = queryOptions.SortField, CurrentPage = queryOptions.CurrentPage + 1, PageSize = queryOptions.PageSize }), RGlobal.Next)); }
public async Task <ActionResult> Logs([Form] TableQueryOptions queryOptions, string searchString) { ViewBag.QueryOptions = queryOptions; var start = QueryOptionsCalculator.CalculateStartPage(queryOptions); var logsModel = await _db.GetUsersData(); ViewBag.NumberOfEntries = logsModel.Count(); if (!String.IsNullOrEmpty(searchString)) { searchString = searchString.ToUpper(); logsModel = logsModel.Where(l => l.UserName.ToUpper().Contains(searchString) || l.LogTime.ToString().Contains(searchString) || l.LogMessage.ToUpper().Contains(searchString)); } queryOptions.TotalPages = QueryOptionsCalculator.CalculateTotalPages(logsModel.Count(), queryOptions.PageSize); return(View(logsModel.OrderBy(queryOptions.Sort).Skip(start).Take(queryOptions.PageSize).ToList())); }
public async Task <ActionResult> Index([Form] TableQueryOptions queryOptions, string searchString) { ViewBag.QueryOptions = queryOptions; var start = QueryOptionsCalculator.CalculateStartPage(queryOptions); var model = await db.GetAll(); ViewBag.NumberOfEntries = model.Count(); var viewModels = model.Select(m => m.ToViewModel()); if (!String.IsNullOrEmpty(searchString)) { searchString = searchString.ToUpper(); viewModels = viewModels.Where(c => c.CarModel.ToUpper().Contains(searchString) || c.CarProducer.ToUpper().Contains(searchString) || c.CarProductionYear.ToString().Contains(searchString) || c.LpgInstallationModel.ToUpper().Contains(searchString) || c.LpgInstallationProducer.ToUpper().Contains(searchString)); } queryOptions.TotalPages = QueryOptionsCalculator.CalculateTotalPages(viewModels.Count(), queryOptions.PageSize); return(View(viewModels.OrderBy(queryOptions.Sort).Skip(start).Take(queryOptions.PageSize).ToList())); }
private static string BuildPageNumbers(UrlHelper urlHelper, TableQueryOptions queryOptions, string actionName) { string paginationPagesButtons = string.Empty; for (int i = 1; i <= queryOptions.TotalPages; i++) { paginationPagesButtons = paginationPagesButtons + string.Format( "<li class=\"page-item {2}\">" + " <a class=\"page-link\" href=\"{0}\">{1}</a>" + "</li>", urlHelper.Action(actionName, new { SortOrder = queryOptions.SortOrder, SortField = queryOptions.SortField, CurrentPage = i, PageSize = queryOptions.PageSize }), i, (i == queryOptions.CurrentPage) ? "active" : string.Empty); } return(paginationPagesButtons); }
private static string IsNextDisabled(TableQueryOptions queryOptions) { return((queryOptions.CurrentPage == queryOptions.TotalPages) ? "disabled" : string.Empty); }
private static string IsPreviousDisabled(TableQueryOptions queryOptions) { return((queryOptions.CurrentPage == 1) ? "disabled" : string.Empty); }
public static MvcHtmlString BuildNextPreviousLinks(this HtmlHelper htmlHelper, TableQueryOptions queryOptions, string actionName) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); return(new MvcHtmlString(string.Format( "<div class=\"navbar\">" + " <nav aria-label=\"...\">" + " <ul class=\"pagination pagination-sm\">" + " <li class=\"page-item {0}\">{1}</li>" + " {4}" + " <li class=\"page-item {2}\">{3}</li>" + " </ul>" + " </nav>" + "</div>" , IsPreviousDisabled(queryOptions), BuildPreviousLink(urlHelper, queryOptions, actionName), IsNextDisabled(queryOptions), BuildNextLink(urlHelper, queryOptions, actionName), BuildPageNumbers(urlHelper, queryOptions, actionName) ))); }
public static MvcHtmlString BuildSortableLink(this HtmlHelper htmlHelper, string fieldName, string actionName, string sortField, TableQueryOptions queryOptions) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); var isCurrentSortField = queryOptions.SortField == sortField; return(new MvcHtmlString(string.Format("<a href=\"{0}\" class = \"text-dark font-weight-bold\">{1} {2}</a>", urlHelper.Action(actionName, new { SortField = sortField, SortOrder = (isCurrentSortField && queryOptions.SortOrder == SortOrder.ascending ? SortOrder.descending : SortOrder.ascending) }), fieldName, BuildSortIcon(isCurrentSortField, queryOptions)))); }
public static MvcHtmlString BuildPaginationDetails(this HtmlHelper htmlHelper, TableQueryOptions queryOptions, string actionName) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); return(new MvcHtmlString(string.Format( " <div>{5} " + " <button class=\"btn btn-light btn-sm dropdown-toggle\" data-toggle=\"dropdown\">" + " <span class=\"page-size\">" + " {4}" + " </span>" + " <span class=\"caret\">" + " </span>" + " </button>" + " <div class=\"dropdown-menu\">" + " <a class=\"dropdown-item\" href=\"{0}\">10</a>" + " <a class=\"dropdown-item\" href=\"{1}\">25</a>" + " <a class=\"dropdown-item\" href=\"{2}\">50</a>" + " <a class=\"dropdown-item\" href=\"{3}\">100</a>" + " </div> {6}" + " </div>" , urlHelper.Action(actionName, new { SortOrder = queryOptions.SortOrder, SortField = queryOptions.SortField, CurrentPage = queryOptions.CurrentPage, PageSize = 10 }), urlHelper.Action(actionName, new { SortOrder = queryOptions.SortOrder, SortField = queryOptions.SortField, CurrentPage = queryOptions.CurrentPage, PageSize = 25 }), urlHelper.Action(actionName, new { SortOrder = queryOptions.SortOrder, SortField = queryOptions.SortField, CurrentPage = queryOptions.CurrentPage, PageSize = 50 }), urlHelper.Action(actionName, new { SortOrder = queryOptions.SortOrder, SortField = queryOptions.SortField, CurrentPage = queryOptions.CurrentPage, PageSize = 100 }), queryOptions.PageSize, RGlobal.Show, RGlobal.Entries ))); }
public static int CalculateStartPage(TableQueryOptions queryOptions) { return((queryOptions.CurrentPage - 1) * queryOptions.PageSize); }