Ejemplo n.º 1
0
        public static async Task WithPricelistsAsync(this IWorkContextBuilder builder)
        {
            var serviceProvider = builder.HttpContext.RequestServices;
            var pricingService  = serviceProvider.GetRequiredService <IPricingService>();

            var pricelists = await pricingService.EvaluatePricesListsAsync(builder.WorkContext.ToPriceEvaluationContext(), builder.WorkContext);

            await builder.WithPricelistsAsync(pricelists);
        }
        public static Task WithPricelistsAsync(this IWorkContextBuilder builder)
        {
            var serviceProvider = builder.HttpContext.RequestServices;
            var pricingService  = serviceProvider.GetRequiredService <IPricingService>();

            Func <int, int, IEnumerable <SortInfo>, IPagedList <Pricelist> > factory = (pageNumber, pageSize, sortInfos) =>
            {
                var pricelists = pricingService.EvaluatePricesLists(builder.WorkContext.ToPriceEvaluationContext(null), builder.WorkContext);
                return(new StaticPagedList <Pricelist>(pricelists, pageNumber, pageSize, pricelists.Count));
            };

            return(builder.WithPricelistsAsync(new MutablePagedList <Pricelist>(factory, 1, int.MaxValue)));
        }
        public static Task WithPricelistsAsync(this IWorkContextBuilder builder)
        {
            var serviceProvider = builder.HttpContext.RequestServices;
            var pricingService  = serviceProvider.GetRequiredService <IPricingService>();

            Func <int, int, IEnumerable <SortInfo>, IPagedList <Pricelist> > factory = (pageNumber, pageSize, sortInfos) =>
            {
                IList <Pricelist> pricelists = new List <Pricelist>();
                //Do not evaluate price lists for anonymous user
                if (builder.WorkContext.CurrentUser.IsRegisteredUser)
                {
                    var priceListEvaluationContext = builder.WorkContext.ToPriceEvaluationContext(null);
                    priceListEvaluationContext.CertainDate = DateTime.UtcNow;
                    pricelists = pricingService.EvaluatePricesLists(priceListEvaluationContext, builder.WorkContext);
                }
                return(new StaticPagedList <Pricelist>(pricelists, pageNumber, pageSize, pricelists.Count));
            };

            return(builder.WithPricelistsAsync(new MutablePagedList <Pricelist>(factory, 1, int.MaxValue)));
        }