public async Task <IActionResult> Sort(SortState sortOrder = SortState.NameAsc) { IIncludableQueryable <MetanitExampleCoreMVC.Models.User, Company> users = dbUsers.Users.Include(x => x.Company); IQueryable <MetanitExampleCoreMVC.Models.User> usersResult; ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc; ViewData["AgeSort"] = sortOrder == SortState.AgeAsc ? SortState.AgeDesc : SortState.AgeAsc; ViewData["CompanySort"] = sortOrder == SortState.CompanyAsc ? SortState.CompanyDesc : SortState.CompanyAsc; switch (sortOrder) { case SortState.NameDesc: usersResult = users.OrderByDescending(s => s.Name); break; case SortState.AgeAsc: usersResult = users.OrderBy(s => s.Name); break; case SortState.AgeDesc: usersResult = users.OrderByDescending(s => s.Name); break; case SortState.CompanyAsc: usersResult = users.OrderBy(s => s.Name); break; case SortState.CompanyDesc: usersResult = users.OrderByDescending(s => s.Company.Name); break; default: usersResult = users.OrderBy(s => s.Name); break; } IndexSortViewModel viewModel = new IndexSortViewModel { Users = await usersResult.AsNoTracking().ToListAsync(), SortViewModel = new SortViewModel(sortOrder) }; return(View(viewModel)); }
private void CheckoutToEarliestHold(int assetId, IIncludableQueryable <Hold, bool> currentHolds) { var earliestHold = currentHolds.OrderBy(holds => holds.HoldPlaced).FirstOrDefault(); var card = earliestHold.LibraryCard; _context.Remove(earliestHold); _context.SaveChanges(); CheckOutItem(assetId, card.Id); }
public async Task <ReadOnlyCollection <Position> > Search(string searchText, int maxResults, CancellationToken cancellationToken) { Position[] positions; if (string.IsNullOrEmpty(searchText)) { positions = await _positionsIncludableGetQuery .OrderBy(x => x.DaysOpen) .Take(maxResults) .ToArrayAsync(cancellationToken); } else { searchText = searchText.ToLowerInvariant(); positions = await _positionsIncludableGetQuery .Where(x => x.Title.ToLowerInvariant().Contains(searchText) || x.PositionExternalId.ToLowerInvariant().Contains(searchText)) .OrderBy(x => x.DaysOpen) .Take(maxResults) .ToArrayAsync(cancellationToken); } return(Array.AsReadOnly(positions)); }
// [Authorize(oAppConst.AccessPolicies.LevelTwo)] /// Done public async Task <IActionResult> Get( int selectedPage, int maxNumberPerItemsPage, int filterProductStoreId, string filterProductCategory, string searchValue = "", string filterProductUnit = "", string filterStatus = "", bool isAccendingSort = true, SortByType sortByType = SortByType.product) { try { bool.TryParse(filterStatus, out bool boolFilterStatus); int.TryParse(filterProductCategory, out int filterProductCategoryId); ProductUnitType productUnitType = ProductUnitType.Grams; switch (filterProductUnit) { case nameof(ProductUnitType.Grams): productUnitType = ProductUnitType.Grams; break; case nameof(ProductUnitType.Kg): productUnitType = ProductUnitType.Kg; break; case nameof(ProductUnitType.PerItem): productUnitType = ProductUnitType.PerItem; break; default: filterProductUnit = oAppConst.GetAllRecords; break; } int totalCount = await DbContext.StoreProducts .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId) .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType) .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId) .CountAsync(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue))) .ConfigureAwait(false); /// Include the necessary properties IIncludableQueryable <oStoreProduct, oCategory> product = DbContext.StoreProducts .Include(sp => sp.Store) .Include(sp => sp.Product) .ThenInclude(p => p.Category); IQueryable sortedList; if (isAccendingSort) { sortedList = sortByType switch { SortByType.category => product.OrderBy(sp => sp.Product.Category.Name), SortByType.price => product.OrderBy(sp => sp.Product.Price), SortByType.unit => product.OrderBy(sp => sp.Product.Unit), SortByType.unitQuantity => product.OrderBy(sp => sp.Product.UnitQuantity), SortByType.status => product.OrderBy(sp => sp.Status), _ => product.OrderBy(sp => sp.Product.Name), } } ; else { sortedList = sortByType switch { SortByType.category => product.OrderByDescending(sp => sp.Product.Category.Name), SortByType.price => product.OrderByDescending(sp => sp.Product.Price), SortByType.unit => product.OrderByDescending(sp => sp.Product.Unit), SortByType.unitQuantity => product.OrderByDescending(sp => sp.Product.UnitQuantity), SortByType.status => product.OrderByDescending(sp => sp.Status), _ => product.OrderByDescending(sp => sp.Product.Name), } }; List <oStoreProduct> list = await product .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId) .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType) .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId) .Where(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue))) .Skip((selectedPage - 1) * maxNumberPerItemsPage) .Take(maxNumberPerItemsPage) .ToListAsync() .ConfigureAwait(false); //int totalCount = await DbContext.Products // .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType) // .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId) // .CountAsync(c => searchValue.Equals(oAppConst.GetAllRecords) ? true : c.Name.Contains(searchValue)) // .ConfigureAwait(false); //List<oProduct> list = await DbContext.Products // .OrderBy(c => c.Name) // .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType) // .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId) // .Include(t => t.StoreProducts) // .Skip((selectedPage - 1) * maxNumberPerItemsPage) // .Take(maxNumberPerItemsPage) // .ToListAsync() // .ConfigureAwait(false); //foreach (oProduct product in list) //{ // product.StoreProducts = product.StoreProducts.Where(t => t.StoreId == filterProductStoreId).ToList(); //} /// return the list of Categories return(Ok(new { list, totalCount })); }
public IEnumerable <Calendar> GetMany() { return(_calendars.OrderBy(c => c.SchoolYear)); }