Exemplo n.º 1
0
        private CategoryPeerSet GetPeerSet(List <CategorySnapshot> allCats, CategorySnapshot cat)
        {
            var result = new CategoryPeerSet();

            var parent = Category.FindInList(allCats, cat.ParentId);

            if (parent != null)
            {
                result.Parents = Category.FindChildrenInList(allCats, parent.ParentId, false);
            }
            result.Peers    = Category.FindChildrenInList(allCats, cat.ParentId, false);
            result.Children = Category.FindChildrenInList(allCats, cat.Bvin, false);

            return(result);
        }
Exemplo n.º 2
0
        private CategoryMenuItemViewModel BuildPeersAndChildren(CategoryPeerSet neighbors,
                                                                CategorySnapshot currentCategory, bool isDisplayProductsCount)
        {
            var result = new CategoryMenuItemViewModel();

            foreach (var peer in neighbors.Peers)
            {
                var item = new CategoryMenuItemViewModel();

                item.Title       = peer.Name;
                item.Description = peer.Description;
                item.Url         = UrlRewriter.BuildUrlForCategory(peer);
                if (peer.Bvin == currentCategory.Bvin)
                {
                    item.IsCurrent = true;
                    // Load Children
                    foreach (var c in neighbors.Children)
                    {
                        var childItem = new CategoryMenuItemViewModel();
                        childItem.Title       = c.Name;
                        childItem.Description = c.Description;
                        if (isDisplayProductsCount)
                        {
                            item.Bvin          = c.Bvin;
                            item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(c.Bvin, false);
                        }
                        childItem.Url = UrlRewriter.BuildUrlForCategory(c);
                        item.Items.Add(childItem);
                    }
                }
                if (isDisplayProductsCount)
                {
                    item.Bvin          = peer.Bvin;
                    item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(peer.Bvin, false);
                }

                result.Items.Add(item);
            }
            return(result);
        }
Exemplo n.º 3
0
        private CategoryMenuItemViewModel BuildParentsPeersChildren(CategoryPeerSet neighbors,
                                                                    CategorySnapshot currentCategory, bool isDisplayProductsCount)
        {
            CategoryMenuItemViewModel result;

            if (neighbors.Parents.Count > 0)
            {
                result = new CategoryMenuItemViewModel();

                foreach (var parent in neighbors.Parents)
                {
                    CategoryMenuItemViewModel item;

                    if (parent.Bvin == currentCategory.ParentId)
                    {
                        item = BuildPeersAndChildren(neighbors, currentCategory, isDisplayProductsCount);
                    }
                    else
                    {
                        item = new CategoryMenuItemViewModel();
                    }
                    item.Title       = parent.Name;
                    item.Description = parent.Description;
                    item.Url         = UrlRewriter.BuildUrlForCategory(parent);
                    if (isDisplayProductsCount)
                    {
                        item.Bvin          = parent.Bvin;
                        item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(parent.Bvin, false);
                    }

                    result.Items.Add(item);
                }
            }
            else
            {
                result = BuildPeersAndChildren(neighbors, currentCategory, isDisplayProductsCount);
            }

            return(result);
        }
        private void RenderPeersChildren(CategoryMenuViewModel model, CategoryPeerSet neighbors, CategorySnapshot currentCategory, List <CategorySnapshot> allCats)
        {
            // No Parents, start with peers
            foreach (CategorySnapshot peer in neighbors.Peers)
            {
                if (!peer.Hidden)
                {
                    AddSingleLink(model, peer, allCats);
                    if (peer.Bvin == currentCategory.Bvin)
                    {
                        // Load Children
                        if (neighbors.Children.Count > 0)
                        {
                            bool initialized = false;
                            foreach (CategorySnapshot child in neighbors.Children)
                            {
                                if (!child.Hidden)
                                {
                                    if (!initialized)
                                    {
                                        model.sb.Append("<ul>" + System.Environment.NewLine);
                                        initialized = true;
                                    }

                                    AddSingleLink(model, child, allCats);
                                    model.sb.Append("</li>" + System.Environment.NewLine);
                                }
                            }
                            if (initialized)
                            {
                                model.sb.Append("</ul>" + System.Environment.NewLine);
                            }
                        }
                    }
                    model.sb.Append("</li>" + System.Environment.NewLine);
                }
            }
        }
        private void RenderParentsPeersChildren(CategoryMenuViewModel model, CategoryPeerSet neighbors, CategorySnapshot currentCategory, List <CategorySnapshot> allCats)
        {
            if (neighbors.Parents.Count < 1)
            {
                RenderPeersChildren(model, neighbors, currentCategory, allCats);
            }
            else
            {
                // Add Parents
                foreach (CategorySnapshot parent in neighbors.Parents)
                {
                    if (!parent.Hidden)
                    {
                        AddSingleLink(model, parent, allCats);

                        // Add Peers
                        if (parent.Bvin == currentCategory.ParentId)
                        {
                            bool peerInitialized = false;

                            foreach (CategorySnapshot peer in neighbors.Peers)
                            {
                                if (!peer.Hidden)
                                {
                                    if (!peerInitialized)
                                    {
                                        model.sb.Append("<ul>");
                                        peerInitialized = true;
                                    }
                                    AddSingleLink(model, peer, allCats);
                                    if (peer.Bvin == currentCategory.Bvin)
                                    {
                                        // Load Children
                                        if (neighbors.Children.Count > 0)
                                        {
                                            bool childInitialized = false;
                                            foreach (CategorySnapshot child in neighbors.Children)
                                            {
                                                if (!child.Hidden)
                                                {
                                                    if (!childInitialized)
                                                    {
                                                        model.sb.Append("<ul>" + System.Environment.NewLine);
                                                        childInitialized = true;
                                                    }
                                                    AddSingleLink(model, child, allCats);
                                                    model.sb.Append("</li>" + System.Environment.NewLine);
                                                }
                                            }
                                            if (childInitialized)
                                            {
                                                model.sb.Append("</ul>" + System.Environment.NewLine);
                                            }
                                        }
                                    }
                                    model.sb.Append("</li>" + System.Environment.NewLine);
                                }
                            }

                            if (peerInitialized)
                            {
                                model.sb.Append("</ul>" + System.Environment.NewLine);
                            }
                        }
                    }
                    model.sb.Append("</li>" + System.Environment.NewLine);
                }
            }
        }
        private void LoadPeersAndChildren(CategoryMenuViewModel model)
        {
            List <CategorySnapshot> allCats = MTApp.CatalogServices.Categories.FindAll();

            // Get Current Category
            CategorySnapshot currentCategory = Category.FindInList(allCats, model.CurrentId);

            // Trick system into accepting root category of zero which never exists in database
            if (model.CurrentId == "0")
            {
                currentCategory      = new CategorySnapshot();
                currentCategory.Bvin = "0";
            }



            if (currentCategory != null)
            {
                if (currentCategory.Bvin != string.Empty)
                {
                    model.CurrentId = currentCategory.Bvin;
                }

                // Find the trail from this category back to the root of the site
                List <CategorySnapshot> trail = new List <CategorySnapshot>();
                BuildParentTrail(allCats, model.CurrentId, ref trail);
                if (trail == null)
                {
                    trail = new List <CategorySnapshot>();
                }

                if (trail.Count < 1)
                {
                    // Load Roots Only
                    LoadRoots(model);
                }
                else
                {
                    CategoryPeerSet neighbors = GetPeerSet(allCats, currentCategory);

                    if (trail.Count == 1)
                    {
                        // special case where we want only peers and children
                        RenderPeersChildren(model, neighbors, currentCategory, allCats);
                    }
                    else
                    {
                        if (trail.Count >= 3)
                        {
                            if (neighbors.Children.Count < 1)
                            {
                                // Special case where we are at the end of the tree and have
                                // no children. Reset neighbors to parent's bvin

                                CategorySnapshot parent = Category.FindInList(allCats, currentCategory.ParentId);
                                if (parent == null)
                                {
                                    parent = new CategorySnapshot();
                                }

                                neighbors = GetPeerSet(allCats, parent);
                                RenderParentsPeersChildren(model, neighbors, trail[1], allCats);
                            }
                            else
                            {
                                RenderParentsPeersChildren(model, neighbors, currentCategory, allCats);
                            }
                        }
                        else
                        {
                            // normal load of peers
                            RenderParentsPeersChildren(model, neighbors, currentCategory, allCats);
                        }
                    }
                }
            }

            else
            {
                model.sb.Append("Invalid Category Id. Contact Administrator");
            }
        }