Пример #1
0
 private IEnumerable <FashionVariant> GetVariants(PackageContent currentContent)
 {
     return(_contentLoader
            .GetItems(currentContent.GetEntries(_relationRepository), _languageResolver.GetPreferredCulture())
            .OfType <FashionVariant>()
            .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v))
            .ToArray());
 }
Пример #2
0
 private IEnumerable <FashionVariant> GetVariations(FashionProduct currentContent)
 {
     return(_contentLoader
            .GetItems(currentContent.GetVariants(_relationRepository), _languageResolver.GetPreferredCulture())
            .Cast <FashionVariant>()
            .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v)));
 }
 private IEnumerable <BaseVariant> GetVariations(BaseProduct currentContent)
 {
     return(_contentLoader
            .GetItems(currentContent.GetVariants(_relationRepository), _preferredCulture)
            .Cast <BaseVariant>()
            .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v)));
 }
Пример #4
0
 public virtual IEnumerable <T> GetVariants <T>(IEnumerable <ContentReference> contentLinks, CultureInfo cultureInfo) where T : VariationContent
 {
     return(_contentLoader
            .GetItems(contentLinks, cultureInfo)
            .OfType <T>()
            .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v)));
 }
Пример #5
0
        /// <summary>
        /// Gets the latest updated threads. Will search through all the forums beneath the supplied root.
        /// </summary>
        /// <param name="pageRef">The root page to look for threads under.</param>
        /// <param name="nrOfThreads">The number of threads to return.</param>
        /// <returns>A PageDataCollection containing threads.</returns>
        public static PageDataCollection GetLatestUpdatedThreads(PageReference pageRef, int nrOfThreads)
        {
            PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();

            criterias.Add("PageTypeName", ThreadContainerPageTypeName, CompareCondition.Equal);
            PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria(pageRef, criterias);

            PageDataCollection threads         = new PageDataCollection();
            FilterPublished    publishedFilter = new FilterPublished();

            foreach (PageData threadContainer in pages)
            {
                foreach (PageData page in DataFactory.Instance.GetChildren(threadContainer.PageLink, LanguageSelector.AutoDetect(), 0, nrOfThreads))
                {
                    if (!publishedFilter.ShouldFilter(page))
                    {
                        threads.Add(page);
                    }
                }
            }

            new FilterPropertySort("PageChanged", FilterSortDirection.Descending).Filter(threads);
            new FilterCount(nrOfThreads).Filter(threads);

            return(threads);
        }
        /// <summary>
        /// Returns all the content items of <typeparamref name="T"/> from <paramref name="contentAreaItems"/>
        /// </summary>
        /// <typeparam name="T">Type of <see cref="IContentData"/> items to extract.</typeparam>
        /// <param name="contentAreaItems">The <see cref="IEnumerable{ContentAreaItem}"/> to extract <see cref="IContent"/> instances of type <typeparamref name="T"/> from.</param>
        /// <param name="language">The <see cref="CultureInfo"/> to use. If none is specified, current culture will be used.</param>
        /// <param name="contentLoader">The <see cref="IContentLoader"/> to use</param>
        /// <returns>A <see cref="IEnumerable{T}"/> containing all <see cref="IContent"/> items found in the <paramref name="contentAreaItems"/> collection.</returns>
        public static IEnumerable <T> GetContentItems <T>(this IEnumerable <ContentAreaItem> contentAreaItems, CultureInfo language = null,
                                                          IContentLoader contentLoader = null)
            where T : IContentData
        {
            if (contentAreaItems == null)
            {
                return(Enumerable.Empty <T>());
            }

            if (contentLoader == null)
            {
                contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>();
            }

            if (language == null)
            {
                language = LanguageSelector.AutoDetect().Language;
            }


            var items = contentLoader.GetItems(contentAreaItems.Select(i => i.ContentLink), language).OfType <T>();

            var publishedFilter = new FilterPublished();
            var accessFilter    = new FilterAccess();

            var filterItems = items.OfType <IContent>().Where(x => !publishedFilter.ShouldFilter(x) && !accessFilter.ShouldFilter(x));

            return(filterItems.OfType <T>());
        }
        protected IRedirect ResolveRule <T>(RedirectRule rule, Func <RedirectRule, T> constructRedirect) where T : IRedirect
        {
            if (rule == null)
            {
                return(new NullRedirectRule());
            }

            if (!rule.ContentId.HasValue)
            {
                return(constructRedirect(rule));
            }

            if (!_contentLoader.TryGet <PageData>(new ContentReference(rule.ContentId.Value), out var content))
            {
                return(new NullRedirectRule());
            }

            var filter = new FilterPublished();

            if (filter.ShouldFilter(content))
            {
                return(new NullRedirectRule());
            }

            return(constructRedirect(rule));
        }
Пример #8
0
        /// <summary>
        ///     Filters content which should not be visible to the user.
        /// </summary>
        /// <typeparam name="T">Type of content (IContent).</typeparam>
        /// <param name="content">Enumeration of content instances to filter.</param>
        /// <param name="requirePageTemplate">Mark if should include only content with template.</param>
        /// <param name="requireVisibleInMenu">Mark if should include only pages with mark VisibleInMenu = true.</param>
        /// <returns>Returns enumeration of filtered content.</returns>
        public static IEnumerable <T> FilterForDisplay <T>(this IEnumerable <T> content, bool requirePageTemplate = false, bool requireVisibleInMenu = false)
            where T : IContent
        {
            if (content == null)
            {
                return(Enumerable.Empty <T>());
            }

            var publishedFilter = new FilterPublished();
            var accessFilter    = new FilterAccess();

            content = content.Where(x => !publishedFilter.ShouldFilter(x) && !accessFilter.ShouldFilter(x));

            if (requirePageTemplate)
            {
                var templateFilter = ServiceLocator.Current.GetInstance <FilterTemplate>();
                templateFilter.TemplateTypeCategories = TemplateTypeCategories.Page;
                content = content.Where(x => !templateFilter.ShouldFilter(x));
            }

            if (requireVisibleInMenu)
            {
                content = content.Where(x => VisibleInMenu(x));
            }

            return(content);
        }
Пример #9
0
        public static bool ShouldIndexPage(this IContent content)
        {
            var filterPublished = new FilterPublished();
            var filterTemplate  = new FilterTemplate();
            var hasTemplate     = !filterTemplate.ShouldFilter(content);
            var isPublished     = !filterPublished.ShouldFilter(content);

            return(hasTemplate && isPublished);
        }
Пример #10
0
        private IEnumerable <TVariant> GetVariants <TVariant, TEntryBase>(TEntryBase currentContent) where TVariant : VariationContent where TEntryBase : EntryContentBase
        {
            var bundle = currentContent as BundleContent;

            if (bundle != null)
            {
                return(_contentLoader
                       .GetItems(bundle.GetEntries(_relationRepository), _languageResolver.GetPreferredCulture())
                       .OfType <TVariant>()
                       .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v))
                       .ToArray());
            }

            var package = currentContent as PackageContent;

            if (package != null)
            {
                return(_contentLoader
                       .GetItems(package.GetEntries(_relationRepository), _languageResolver.GetPreferredCulture())
                       .OfType <TVariant>()
                       .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v))
                       .ToArray());
            }

            var product = currentContent as ProductContent;

            if (product != null)
            {
                return(_contentLoader
                       .GetItems(product.GetVariants(_relationRepository), _languageResolver.GetPreferredCulture())
                       .OfType <TVariant>()
                       .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v))
                       .ToArray());
            }

            return(Enumerable.Empty <TVariant>());
        }
Пример #11
0
        private IEnumerable <MenuItem> GetMenuItemsRecursive(ContentReference contentLink)
        {
            var publishedFilter = new FilterPublished();
            var accessFilter    = new FilterAccess();

            var menuItems = _contentLoader
                            .GetChildren <BasePageData>(contentLink)
                            .Where(p => p.VisibleInSiteMap && !publishedFilter.ShouldFilter(p) && !accessFilter.ShouldFilter(p))
                            .Select(p => new MenuItem
            {
                Name        = p.Name,
                ContentLink = p.ContentLink,
                Children    = GetMenuItemsRecursive(p.ContentLink)
            });

            return(menuItems);
        }
Пример #12
0
        public static IEnumerable <T> FilterForDisplay <T>(
            this IEnumerable <T> contents,
            bool requirePageTemplate  = false,
            bool requireVisibleInMenu = false) where T : IContent
        {
            var accessFilter    = new FilterAccess();
            var publishedFilter = new FilterPublished();

            contents = contents.Where(x =>
                                      !publishedFilter.ShouldFilter(x) &&
                                      !accessFilter.ShouldFilter(x));

            if (requireVisibleInMenu)
            {
                contents = contents.Where(x => VisibleInMenu(x));
            }

            return(contents);
        }
Пример #13
0
        /// <summary>
        /// Finds all blocks of a block type below <paramref name="reference"/>, and runs it through FilterForVisitor.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reference">ContentReference to search below</param>
        /// <param name="recursive">Whether to search recursively</param>
        /// <returns>A list containing items of type <typeparam name="T">T</typeparam>, or null</returns>
        public IEnumerable <T> FindFilteredBlocksOfType <T>(ContentReference reference, bool recursive) where T : BlockData
        {
            if (reference == null || reference.ID == 0)
            {
                return(new List <T>());
            }

            var subPages = FindBlocksOfType <T>(reference, recursive).Cast <BlockData>();

            var filterAcces     = new FilterAccess(AccessLevel.Read);
            var publishedFilter = new FilterPublished();

            var filteredBlocks = subPages
                                 .Where(b => !filterAcces.ShouldFilter((IContent)b))
                                 .Where(b => !publishedFilter.ShouldFilter((IContent)b));

            // FilterForVisitor.Filter doesn't work for some reason.
            //It returns null, even if the exact code it uses (tested through reflection) does return the correct list of items.
            //var filteredSubPages = FilterForVisitor.Filter(subPages);

            return(filteredBlocks.Cast <T>());
        }
Пример #14
0
        /// <summary>
        /// Finds all pages of a page type below <paramref name="pageLink"/>, and runs it through FilterForVisitor.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageLink">PageReference to search below</param>
        /// <param name="recursive">Whether to search recursively</param>
        /// <param name="culture"></param>
        /// <returns>A list containing items of type <typeparam name="T">T</typeparam> or an empty list</returns>
        public IEnumerable <T> FindFilteredPagesOfType <T>(ContentReference pageLink, bool recursive, CultureInfo culture) where T : IContent
        {
            if (pageLink == null || pageLink.ID == 0)
            {
                return(new List <T>());
            }

            var subPages = FindPagesOfType <T>(pageLink, recursive, culture).Cast <IContent>();

            var filterAcces     = new FilterAccess(AccessLevel.Read);
            var publishedFilter = new FilterPublished();

            var filteredSubPages = subPages
                                   .Where(p => !filterAcces.ShouldFilter(p))
                                   .Where(p => !publishedFilter.ShouldFilter(p));

            // FilterForVisitor.Filter doesn't work for some reason.
            //It returns null, even if the exact code it uses (tested through reflection) does return the correct list of items.
            //var filteredSubPages = FilterForVisitor.Filter(subPages);

            return(filteredSubPages.Cast <T>());
        }
Пример #15
0
        public async Task <JsonResult> AddToCart(RequestParamsToCart param) // only use Code
        {
            if (WishList.Cart == null)
            {
                _wishlist = new CartWithValidationIssues
                {
                    Cart             = _cartService.LoadOrCreateCart(_cartService.DefaultWishListName),
                    ValidationIssues = new Dictionary <ILineItem, List <ValidationIssue> >()
                };
            }

            // return 0 if the variant already exist in wishlist
            // return 1 if added susscessfully
            var result       = new AddToCartResult();
            var allLineItems = WishList.Cart.GetAllLineItems();
            var contentLink  = _referenceConverter.GetContentLink(param.Code);
            var message      = "";
            var productName  = "";
            var entryLink    = _referenceConverter.GetContentLink(param.Code);

            productName = _contentLoader.Get <EntryContentBase>(entryLink).DisplayName;

            if (_contentLoader.Get <EntryContentBase>(contentLink) is GenericBundle bundle) // Add bundle
            {
                var variantCodes = _contentLoader
                                   .GetItems(bundle.GetEntries(_relationRepository), _languageResolver.GetPreferredCulture())
                                   .OfType <VariationContent>()
                                   .Where(v => v.IsAvailableInCurrentMarket(_currentMarket) && !_filterPublished.ShouldFilter(v))
                                   .Select(x => x.Code);
                var allLineItemCodes = allLineItems.Select(x => x.Code);
                var allNewCodes      = variantCodes.Where(x => !allLineItemCodes.Contains(x));
                if (!allNewCodes.Any())
                {
                    return(Json(new ChangeCartJsonResult {
                        StatusCode = 0, Message = productName + " already exist in the wishlist."
                    }));
                }
                else
                {
                    foreach (var v in allNewCodes)
                    {
                        result = _cartService.AddToCart(WishList.Cart, new RequestParamsToCart {
                            Code = v, Quantity = 1, Store = "delivery", SelectedStore = ""
                        });
                        if (result.ValidationMessages.Count > 0)
                        {
                            message += string.Join("\n", result.ValidationMessages);
                        }
                    }
                }
            }
            else // Add variant
            {
                if (allLineItems.Any(item => item.Code.Equals(param.Code, StringComparison.OrdinalIgnoreCase)))
                {
                    return(Json(new ChangeCartJsonResult {
                        StatusCode = 0, Message = productName + " already exist in the wishlist."
                    }));
                }

                result = _cartService.AddToCart(WishList.Cart,
                                                new RequestParamsToCart {
                    Code = param.Code, Quantity = 1, Store = "delivery", SelectedStore = ""
                });
            }

            if (result.EntriesAddedToCart)
            {
                _orderRepository.Save(WishList.Cart);
                await _trackingService.TrackWishlist(HttpContext);

                return(Json(new ChangeCartJsonResult
                {
                    StatusCode = 1,
                    CountItems = (int)WishList.Cart.GetAllLineItems().Sum(x => x.Quantity),
                    Message = productName + " is added to the wishlist successfully.\n" + message
                }));
            }
            return(Json(new ChangeCartJsonResult {
                StatusCode = -1, Message = result.GetComposedValidationMessage()
            }));
        }
Пример #16
0
 private IEnumerable <VariationContent> GetAvailableVariants(IEnumerable <ContentReference> contentLinks)
 {
     return(_contentLoader.GetItems(contentLinks, _preferredCulture)
            .OfType <VariationContent>()
            .Where(v => v.IsAvailableInCurrentMarket(_currentMarketService) && !_filterPublished.ShouldFilter(v)));
 }