//public CategoryPeerSet FindAllNeighbors(string bvin) //{ // CategoryPeerSet result = new CategoryPeerSet(); // long storeId = context.CurrentStore.Id; // int totalRows = 0; // Category main = Find(new PrimaryKey(bvin)); // if (main == null) return result; // if (bvin == "0") // Requested Root Categories, so children only // { // IQueryable<Data.EF.bvc_Category> peers = repository.Find().Where(y => y.ParentID == "0") // .Where(y => y.StoreId == storeId) // .OrderBy(y => y.SortOrder); // if (peers != null) result.Peers = ListPoco(peers); // result.Children = FindChildren(bvin, 1, int.MaxValue, ref totalRows); // return result; // } // else // { // Category parent = Find(new PrimaryKey(main.ParentId)); // if (parent != null) // { // result.Parents = FindChildren(parent.ParentId, 1, int.MaxValue, ref totalRows); // } // IQueryable<Data.EF.bvc_Category> peers = repository.Find().Where(y => y.ParentID == main.ParentId) // .Where(y => y.StoreId == storeId) // .OrderBy(y => y.SortOrder); // if (peers != null) result.Peers = ListPoco(peers); // result.Children = FindChildren(bvin, 1, int.MaxValue, ref totalRows); // return result; // } //} public CategoryPeerSet FindVisibleNeighbors(string bvin) { CategoryPeerSet result = new CategoryPeerSet(); long storeId = context.CurrentStore.Id; int totalRows = 0; Category main = Find(new PrimaryKey(bvin)); if (main == null) { return(result); } if (bvin == "0") // Requested Root Categories, so children only { IQueryable <Data.EF.bvc_Category> peers = repository.Find().Where(y => y.ParentID == "0") .Where(y => y.StoreId == storeId) .Where(y => y.Hidden == 0) .OrderBy(y => y.SortOrder); if (peers != null) { result.Peers = ListPocoSnapshot(peers); } result.Children = FindVisibleChildren(bvin, 1, int.MaxValue, ref totalRows); return(result); } else { Category parent = Find(new PrimaryKey(main.ParentId)); if (parent != null) { result.Parents = FindVisibleChildren(parent.ParentId, 1, int.MaxValue, ref totalRows); } IQueryable <Data.EF.bvc_Category> peers = repository.Find().Where(y => y.ParentID == main.ParentId) .Where(y => y.StoreId == storeId) .Where(y => y.Hidden == 0) .OrderBy(y => y.SortOrder); if (peers != null) { result.Peers = ListPocoSnapshot(peers); } result.Children = FindVisibleChildren(bvin, 1, int.MaxValue, ref totalRows); 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 CategoryPeerSet GetPeerSet(List<CategorySnapshot> allCats, CategorySnapshot cat) { CategoryPeerSet result = new CategoryPeerSet(); CategorySnapshot 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; }