private IQueryable <Character> SortCharacters(IQueryable <Character> charactersQueryable, string sortingDefition, JqGridSortingOrders sortingOrder) { IOrderedEnumerable <Character> orderedCharacters = null; if (!String.IsNullOrWhiteSpace(sortingDefition)) { sortingDefition = sortingDefition.ToLowerInvariant(); string[] subSortingDefinitions = sortingDefition.Split(','); foreach (string subSortingDefinition in subSortingDefinitions) { string[] sortingDetails = subSortingDefinition.Trim().Split(' '); string sortingDetailsName = sortingDetails[0]; JqGridSortingOrders sortingDetailsOrder = (sortingDetails.Length > 1) ? (JqGridSortingOrders)Enum.Parse(typeof(JqGridSortingOrders), sortingDetails[1], true) : sortingOrder; Func <Character, object> sortingExpression = GetCharacterSortingExpression(sortingDetailsName, sortingDetailsOrder); if (sortingExpression != null) { if (orderedCharacters != null) { orderedCharacters = (sortingDetailsOrder == JqGridSortingOrders.Asc) ? orderedCharacters.ThenBy(sortingExpression) : orderedCharacters.ThenByDescending(sortingExpression); } else { orderedCharacters = (sortingDetailsOrder == JqGridSortingOrders.Asc) ? charactersQueryable.OrderBy(sortingExpression) : charactersQueryable.OrderByDescending(sortingExpression); } } } } return(orderedCharacters.AsQueryable()); }
private IQueryable <Planet> SortPlanets(IQueryable <Planet> planetsQueryable, string sortingName, JqGridSortingOrders sortingOrder) { IOrderedEnumerable <Planet> orderedPlanets = null; if (!String.IsNullOrWhiteSpace(sortingName)) { sortingName = sortingName.ToLowerInvariant(); Func <Planet, object> sortingExpression = GetPlanetSortingExpression(sortingName, sortingOrder); if (sortingExpression != null) { orderedPlanets = (sortingOrder == JqGridSortingOrders.Asc) ? planetsQueryable.OrderBy(sortingExpression) : planetsQueryable.OrderByDescending(sortingExpression); } } return(orderedPlanets.AsQueryable()); }
/// <summary> /// Initializes a new instance of the <see cref="PagedList{T}"/> class that divides the supplied superset into subsets the size of the supplied pageSize. The instance then only containes the objects contained in the subset specified by index. /// </summary> /// <param name="superset">The collection of objects to be divided into subsets. If the collection implements <see cref="IOrderedEnumerable{T}"/>, it will be treated as such.</param> /// <param name="pageNumber">The one-based index of the subset of objects to be contained by this instance.</param> /// <param name="pageSize">The maximum size of any individual subset.</param> /// <exception cref="ArgumentOutOfRangeException">The specified index cannot be less than zero.</exception> /// <exception cref="ArgumentOutOfRangeException">The specified page size cannot be less than one.</exception> public PagedList(IOrderedEnumerable <T> superset, int pageNumber, int pageSize) : this(superset.AsQueryable() as IOrderedQueryable <T>, pageNumber, pageSize) { }
public static IOrderedQueryable <TEntity> AsOrderedQueryable <TEntity>(this IOrderedEnumerable <TEntity> collection) { return(collection.AsQueryable().OrderBy(s => s)); }
/// <summary> /// Filter Shipping Weight Records /// </summary> /// <param name="shippingMethodId">Shipping method identifier</param> /// <param name="storeId">Store identifier</param> /// <param name="warehouseId">Warehouse identifier</param> /// <param name="countryId">Country identifier</param> /// <param name="stateProvinceId">State identifier</param> /// <param name="zip">Zip postal code</param> /// <param name="weight">Weight</param> /// <param name="orderSubtotal">Order subtotal</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>List of the shipping by weight record</returns> public virtual IPagedList <ShippingByWeightByTotalRecord> FindRecords(int shippingMethodId, int storeId, int warehouseId, int countryId, int stateProvinceId, string zip, decimal?weight, decimal?orderSubtotal, int pageIndex, int pageSize) { zip = zip?.Trim() ?? string.Empty; //filter by weight and shipping method System.Collections.Generic.List <ShippingByWeightByTotalRecord> existingRates = GetAll() .Where(sbw => sbw.ShippingMethodId == shippingMethodId && (!weight.HasValue || (weight >= sbw.WeightFrom && weight <= sbw.WeightTo))) .ToList(); //filter by order subtotal System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedBySubtotal = !orderSubtotal.HasValue ? existingRates : existingRates.Where(sbw => orderSubtotal >= sbw.OrderSubtotalFrom && orderSubtotal <= sbw.OrderSubtotalTo); //filter by store System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByStore = storeId == 0 ? matchedBySubtotal : matchedBySubtotal.Where(r => r.StoreId == storeId || r.StoreId == 0); //filter by warehouse System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByWarehouse = warehouseId == 0 ? matchedByStore : matchedByStore.Where(r => r.WarehouseId == warehouseId || r.WarehouseId == 0); //filter by country System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByCountry = countryId == 0 ? matchedByWarehouse : matchedByWarehouse.Where(r => r.CountryId == countryId || r.CountryId == 0); //filter by state/province System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByStateProvince = stateProvinceId == 0 ? matchedByCountry : matchedByCountry.Where(r => r.StateProvinceId == stateProvinceId || r.StateProvinceId == 0); //filter by zip System.Collections.Generic.IEnumerable <ShippingByWeightByTotalRecord> matchedByZip = string.IsNullOrEmpty(zip) ? matchedByStateProvince : matchedByStateProvince.Where(r => string.IsNullOrEmpty(r.Zip) || r.Zip.Equals(zip, StringComparison.InvariantCultureIgnoreCase)); //sort from particular to general, more particular cases will be the first IOrderedEnumerable <ShippingByWeightByTotalRecord> foundRecords = matchedByZip.OrderBy(r => r.StoreId == 0).ThenBy(r => r.WarehouseId == 0) .ThenBy(r => r.CountryId == 0).ThenBy(r => r.StateProvinceId == 0) .ThenBy(r => string.IsNullOrEmpty(r.Zip)); PagedList <ShippingByWeightByTotalRecord> records = new PagedList <ShippingByWeightByTotalRecord>(foundRecords.AsQueryable(), pageIndex, pageSize); return(records); }
/// <summary> /// 共通分页类 /// </summary> /// <typeparam name="T">查询返回类</typeparam> /// <param name="allItems">要查询的数据</param> /// <param name="pageIndex">要查询的页码</param> /// <param name="pageSize">每页大小</param> /// <returns></returns> public static CommonPagedList <T> ToCommonPagedList <T>(this IOrderedEnumerable <T> allItems, int pageIndex, int pageSize) where T : class { CommonPagedList <T> Result = new CommonPagedList <T>(allItems.AsQueryable(), pageIndex, pageSize); return(Result); }
public TBusinessComponent GetComponentRecord(string propertyName, string propertyValue) { TDataBUSFactory dataBUSFactory = new TDataBUSFactory(); return(dataBUSFactory.DataToBusiness(orderedEntities.AsQueryable().FirstOrDefault($"{propertyName} = \"{propertyValue}\""), context)); }
/// <summary> /// 分页结果集 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="linq"></param> /// <param name="pp"></param> /// <returns></returns> public static PagedList <T> ToPagedList <T>(this IOrderedEnumerable <T> linq, PageParameters pp) { return(new PagedList <T>(linq.AsQueryable(), pp.PageIndex, pp.PageSize)); }
/// <summary> /// 分页结果集 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="linq"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public static PagedList <T> ToPagedList <T>(this IOrderedEnumerable <T> linq, int pageIndex, int pageSize) { return(new PagedList <T>(linq.AsQueryable(), pageIndex, pageSize)); }
public ActionResult <object> GetRecord(string appletName) { // Если в представлении не установлена текущая запись if (viewInfo.CurrentRecord == null && orderedEntities.FirstOrDefault() != null) { viewInfo.CurrentRecord = orderedEntities.FirstOrDefault().Id.ToString(); } TBUSUIFactory busUIFactory = new TBUSUIFactory(); TDataBUSFactory dataBUSFactory = new TDataBUSFactory(); TBusinessComponent businessEntity; ViewItem viewItem = viewInfo.ViewItems.FirstOrDefault(n => n.Applet.Name == appletName); BusinessComponent busComp = viewInfo.ViewBCs.FirstOrDefault(i => i.Id == viewItem.Applet.BusCompId); BusinessObjectComponent objectComponent = viewInfo.BOComponents.FirstOrDefault(bcId => bcId.BusCompId == busComp.Id); string selectedRecordId = GetSelectedRecord(busComp?.Name); if (viewInfo.AppletsSortedByLinks.LastOrDefault()?.Id == viewItem.Applet?.Id) { viewInfo.EndInitialize(); } // Если у апплета установлена кастомная инициализация if ((viewInfo.CurrentApplet?.Initflag == true && viewInfo.CurrentApplet.Name == appletName) || (viewInfo.CurrentPopupApplet?.Initflag == true && viewInfo.CurrentPopupApplet.Name == appletName)) { TBusinessComponent initComponent = busUIFactory.Init(context); ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, initComponent); return(JsonConvert.SerializeObject(busUIFactory.BusinessToUI(initComponent), Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); } // Выделенная запись if (selectedRecordId != null) { businessEntity = dataBUSFactory.DataToBusiness(orderedEntities.FirstOrDefault(i => i.Id.ToString() == selectedRecordId), context); } // Запись по умолчанию, в случае, если на бизнес компонете апплета нет выделенной записи else { // Если у записи есть ограничение по родительской string searchSpecificationByParent = GetSearchSpecification(objectComponent.Name, SearchSpecTypes.SearchSpecificationByParent); if (searchSpecificationByParent == null) { // Если количество отображаемых записей больше нуля if (orderedEntities?.Count() > 0) { businessEntity = dataBUSFactory.DataToBusiness(orderedEntities.ElementAtOrDefault(viewItem.AutofocusRecord), context); } else { businessEntity = new TBusinessComponent() { }; return(null); } } else { // Если количество отображаемых записей больше нуля if (orderedEntities.AsQueryable().Where(searchSpecificationByParent)?.Count() != 0) { businessEntity = dataBUSFactory.DataToBusiness(orderedEntities.ElementAtOrDefault(viewItem.AutofocusRecord), context); } else { businessEntity = new TBusinessComponent() { }; return(null); } } } ComponentsContext <TBusinessComponent> .SetComponentContext(busComp.Name, businessEntity); return(Ok(JsonConvert.SerializeObject(busUIFactory.BusinessToUI(businessEntity), Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }))); }
public static IQueryable <T> Paging <T>(this IOrderedEnumerable <T> query, int?current, int?take) where T : class => query.AsQueryable().Paging(current, take);