/// <summary> /// Sorts the elements of an array by a given attribute of an element in the array. /// {% assign sorted = pages | sort:"date:desc;name" %} /// </summary> /// <param name="input"></param> /// <param name="sort"></param> /// <returns></returns> public static object SortList(object input, string sort) { var retVal = input; IEnumerable enumerable = retVal as IEnumerable; IMutablePagedList muttablePagedList = input as IMutablePagedList; var sortInfos = SortInfo.Parse(sort).ToList(); if (muttablePagedList != null) { muttablePagedList.Slice(muttablePagedList.PageNumber, muttablePagedList.PageSize, sortInfos); } if (enumerable != null) { //Queryable.Cast<T>(input).OrderBySortInfos(sortInfos) call by reflection var queryable = enumerable.AsQueryable(); var elementType = enumerable.GetType().GetEnumerableType(); MethodInfo castMethodInfo = typeof(Queryable).GetMethods().Where(x => x.Name == "Cast" && x.IsGenericMethod).First(); castMethodInfo = castMethodInfo.MakeGenericMethod(new Type[] { elementType }); var genericQueryable = castMethodInfo.Invoke(null, new object[] { queryable }); var orderBySortInfosMethodInfo = typeof(IQueryableExtensions).GetMethod("OrderBySortInfos"); orderBySortInfosMethodInfo = orderBySortInfosMethodInfo.MakeGenericMethod(new Type[] { elementType }); retVal = orderBySortInfosMethodInfo.Invoke(null, new object[] { genericQueryable, sortInfos.ToArray() }); } return(retVal); }
public virtual Search ToLiquidSearch(IMutablePagedList <storefrontModel.Product> products, WorkContext workContext) { var factory = ServiceLocator.Current.GetInstance <ShopifyModelFactory>(); var result = factory.CreateSearch(); result.Performed = true; result.Terms = workContext.CurrentProductSearchCriteria.Keyword; result.Results = new MutablePagedList <dotLiquid.Drop>((pageNumber, pageSize, sortInfos) => { products.Slice(pageNumber, pageSize, sortInfos); return(new StaticPagedList <dotLiquid.Drop>(products.Select(x => x.ToShopifyModel()), products)); }); if (workContext.Aggregations != null) { result.AllTags = new TagCollection(new MutablePagedList <Tag>((pageNumber, pageSize, sortInfos) => { workContext.Aggregations.Slice(pageNumber, pageSize, sortInfos); var tags = workContext.Aggregations .Where(a => a.Items != null) .SelectMany(a => a.Items.Select(item => item.ToShopifyModel(a.Field, a.Label))); return(new StaticPagedList <Tag>(tags, workContext.Aggregations)); }, workContext.Aggregations.PageNumber, workContext.Aggregations.PageSize)); } return(result); }
public ItemCollection(IEnumerable <T> superset) { if (superset == null) { superset = Enumerable.Empty <T>(); } _mutablePagedList = superset as IMutablePagedList <T>; if (_mutablePagedList == null) { _mutablePagedList = new MutablePagedList <T>(superset); } }
/// <summary> /// Loads current page and returns total items count. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="list"></param> /// <returns></returns> public static int GetTotalCount <T>(this IMutablePagedList <T> list) { var result = 0; if (list != null) { using (list.GetEnumerator()) { } result = list.TotalItemCount; } return(result); }
public static Search ToShopifyModel(this IMutablePagedList <Storefront.Model.Catalog.Product> products, string terms) { var retVal = new Search { Results = new MutablePagedList <Drop>((pageNumber, pageSize) => { products.Slice(pageNumber, pageSize); return(new StaticPagedList <Drop>(products.Select(x => x.ToShopifyModel()).OfType <Drop>(), products)); }), Terms = terms, Performed = true }; return(retVal); }
public static Task WithUserQuotesAsync(this IWorkContextBuilder builder, IMutablePagedList <Model.Quote.QuoteRequest> quotes) { builder.WorkContext.CurrentUser.QuoteRequests = quotes; return(Task.CompletedTask); }
public static Task WithUserOrdersAsync(this IWorkContextBuilder builder, IMutablePagedList <CustomerOrder> orders) { builder.WorkContext.CurrentUser.Orders = orders; return(Task.CompletedTask); }
public static Task WithBlogsAsync(this IWorkContextBuilder builder, IMutablePagedList <Blog> blogs) { builder.WorkContext.Blogs = blogs; return(Task.CompletedTask); }
public static Task WithPagesAsync(this IWorkContextBuilder builder, IMutablePagedList <ContentItem> pages) { builder.WorkContext.Pages = pages; return(Task.CompletedTask); }
public static Task WithMenuLinksAsync(this IWorkContextBuilder builder, IMutablePagedList <MenuLinkList> linlitsts) { builder.WorkContext.CurrentLinkLists = linlitsts; return(Task.CompletedTask); }
public static Search ToShopifyModel(this IMutablePagedList <storefrontModel.Product> products, WorkContext workContext) { var converter = ServiceLocator.Current.GetInstance <ShopifyModelConverter>(); return(converter.ToLiquidSearch(products, workContext)); }
public static Task WithPricelistsAsync(this IWorkContextBuilder builder, IMutablePagedList <Pricelist> pricelists) { builder.WorkContext.CurrentPricelists = pricelists; return(Task.CompletedTask); }
public static Task WithFulfillmentCentersAsync(this IWorkContextBuilder builder, IMutablePagedList <FulfillmentCenter> centers) { builder.WorkContext.FulfillmentCenters = centers; return(Task.CompletedTask); }
public static Search ToShopifyModel(this IMutablePagedList <storefrontModel.Product> products, WorkContext workContext) { var converter = new ShopifyModelConverter(); return(converter.ToLiquidSearch(products, workContext)); }
public static Task WithUserSubscriptionsAsync(this IWorkContextBuilder builder, IMutablePagedList <Subscription> subscriptions) { builder.WorkContext.CurrentUser.Subscriptions = subscriptions; return(Task.CompletedTask); }