public async Task OnGetAsync(string sortOrder, string currentFilter, string searchString, int?pageIndex) { CurrentSort = sortOrder; NameSort = String.IsNullOrEmpty(sortOrder) ? "name" : "name_desc"; DateSort = sortOrder == "Date" ? "date_desc" : "Date"; PriceOrder = sortOrder == "price" ? "price_desc" : "price"; if (searchString != null) { pageIndex = 1; } else { searchString = currentFilter; } searchFilter = searchString; IQueryable <Product> products = from p in _context.Product select p; if (!String.IsNullOrEmpty(searchFilter)) { products = products.Where(p => p.name.Contains(searchFilter)); } switch (sortOrder) { case "name": products = products.OrderByDescending(p => p.name); break; case "Date": products = products.OrderBy(p => p.timeRetreived); break; case "date_desc": products = products.OrderBy(p => p.timeRetreived); break; case "name_desc": products = products.OrderBy(p => p.name); break; case "price": products = products.OrderBy(p => p.price); break; case "price_desc": products = products.OrderByDescending(p => p.price); break; default: products = products.OrderByDescending(p => p.timeRetreived); break; } int pageSize = 10; ProductsList = await Paginate <Product> .CreateAsync(products.AsNoTracking(), pageIndex ?? 1, pageSize); }
public async Task OnGetAsync(string sortOrder, string currentFilter, string searchString, int?pageIndex) { //Set pagination vars: CurrentSort = sortOrder; NameSort = String.IsNullOrEmpty(sortOrder) ? "name" : "name_desc"; NameIdSort = sortOrder == "id" ? "id_desc" : "id"; if (searchString != null) { pageIndex = 1; } else { searchString = currentFilter; } searchFilter = searchString; IQueryable <ProductMeta> productMetas = from p in _context.ProductMeta select p; if (!String.IsNullOrEmpty(searchFilter)) { productMetas = productMetas.Where(p => p.NameHtmlId.Contains(searchFilter)); } //Reorder list based on which button was clicked in the webpage: switch (sortOrder) { case "name": productMetas = productMetas.OrderBy(p => p.VanityName); break; case "name_desc": productMetas = productMetas.OrderByDescending(p => p.VanityName); break; case "id": productMetas = productMetas.OrderBy(p => p.NameHtmlId); break; case "id_desc": productMetas = productMetas.OrderByDescending(p => p.NameHtmlId); break; default: productMetas = productMetas.OrderBy(p => p.Id); break; } //max number of objects returned from database: int pageSize = 10; SavedProductsList = await Paginate <ProductMeta> .CreateAsync(productMetas.AsNoTracking(), pageIndex ?? 1, pageSize); }
public async Task OnGetAsync(string order, string search, string filter, int?indexPage) { Sort = order; SortByName = string.IsNullOrEmpty(order) ? "nombre_desc" : ""; SortByEMail = order == "email" ? "email_desc" : "email"; SortByRole = order == "role" ? "role_desc" : "role"; SortByDate = order == "date" ? "date_desc" : "date"; if (search != null) { indexPage = 1; } else { search = filter; } Filter = search; var userQuery = from user in _context.Users select user; if (!string.IsNullOrEmpty(search)) { userQuery = userQuery.Where(u => u.Name.Contains(search) || u.Email.Contains(search) || u.LastName.Contains(search)); } userQuery = order switch { "nombre_desc" => userQuery.OrderByDescending(u => u.Name), "email" => userQuery.OrderBy(u => u.Email), "email_desc" => userQuery.OrderByDescending(u => u.Email), "role" => userQuery.OrderBy(u => u.RoleUsers), "role_desc" => userQuery.OrderByDescending(u => u.RoleUsers), "date" => userQuery.OrderBy(u => u.RegistrationDate), "date_desc" => userQuery.OrderByDescending(u => u.RegistrationDate), _ => userQuery.OrderBy(u => u.Name) }; const int size = 5; Users = await Paginate <User> .CreateAsync(userQuery.AsNoTracking(), indexPage ?? 1, size); } }
public async Task OnGetAsync(string order, string search, string filter, int?indexPage) { /*RoleUser = await _context.RoleUsers * .Include(ru => ru.Role) * .Include(ru => ru.User).ToListAsync();*/ Sort = order; SortByRole = string.IsNullOrEmpty(order) ? "role_desc" : ""; SortByUser = order == "user" ? "user_desc" : "user"; if (search != null) { indexPage = 1; } else { search = filter; } Filter = search; var roleUserQuery = from roleUser in _context.RoleUsers.Include(ru => ru.Role).Include(ru => ru.User) select roleUser; if (!string.IsNullOrEmpty(search)) { roleUserQuery = roleUserQuery.Where(ru => ru.Role.Name.Contains(search) || ru.User.Name.Contains(search)); } roleUserQuery = order switch { "role_desc" => roleUserQuery.OrderByDescending(ru => ru.Role.Name), "user" => roleUserQuery.OrderBy(ru => ru.User.Name), "user_desc" => roleUserQuery.OrderByDescending(ru => ru.User.Name), _ => roleUserQuery.OrderBy(ru => ru.Role.Name) }; const int size = 5; RoleUsers = await Paginate <RoleUser> .CreateAsync(roleUserQuery.AsNoTracking(), indexPage ?? 1, size); } }
public async Task OnGetAsync(string order, string search, string filter, int?indexPage) { //Role = await _context.Roles.ToListAsync(); Sort = order; SortByName = string.IsNullOrEmpty(order) ? "nombre_desc" : ""; if (search != null) { indexPage = 1; } else { search = filter; } Filter = search; var roleQuery = from role in _context.Roles select role; if (!string.IsNullOrEmpty(search)) { roleQuery = roleQuery.Where(r => r.Name.Contains(search)); } roleQuery = order switch { "nombre_desc" => roleQuery.OrderByDescending(r => r.Name), _ => roleQuery.OrderBy(r => r.Name) }; const int size = 5; Roles = await Paginate <Role> .CreateAsync(roleQuery.AsNoTracking(), indexPage ?? 1, size); } }