Esempio n. 1
0
        public static Task WithMenuLinksAsync(this IWorkContextBuilder builder, Store store, Language language)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (language == null)
            {
                throw new ArgumentNullException(nameof(language));
            }

            var serviceProvider = builder.HttpContext.RequestServices;
            var linkListService = serviceProvider.GetRequiredService <IMenuLinkListService>();

            Func <int, int, IEnumerable <SortInfo>, IPagedList <MenuLinkList> > factory = (pageNumber, pageSize, sorInfos) =>
            {
                var linkLists = Task.Factory.StartNew(() => linkListService.LoadAllStoreLinkListsAsync(store, language), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
                return(new StaticPagedList <MenuLinkList>(linkLists, pageNumber, pageSize, linkLists.Count()));
            };

            return(builder.WithMenuLinksAsync(() => new MutablePagedList <MenuLinkList>(factory, 1, 20)));
        }
        public static Task WithMenuLinksAsync(this IWorkContextBuilder builder, Store store, Language language)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (language == null)
            {
                throw new ArgumentNullException(nameof(language));
            }

            var serviceProvider = builder.HttpContext.RequestServices;
            var linkListService = serviceProvider.GetRequiredService <IMenuLinkListService>();

            Func <int, int, IEnumerable <SortInfo>, IPagedList <MenuLinkList> > factory = (pageNumber, pageSize, sorInfos) =>
            {
                var linkLists = linkListService.LoadAllStoreLinkLists(store, language);
                return(new StaticPagedList <MenuLinkList>(linkLists, pageNumber, pageSize, linkLists.Count()));
            };

            return(builder.WithMenuLinksAsync(new MutablePagedList <MenuLinkList>(factory, 1, 20)));
        }