public ShopCategory CreateShopCategory(ShopCategory parent, bool merge = false) { ShopCategory shopCategory = null; if (merge && Parent != null) // принудительное слитие { shopCategory = parent; } else { ShopCategory mergeSubCat = FindMergeCat(parent, this); if (mergeSubCat != null) // слитие если в родительской категории есть похожая категория { shopCategory = mergeSubCat; } else // если не сливаем, то создаем новую { shopCategory = new ShopCategory(parent); shopCategory.Title = this.Title; } } CreateShopProducts(shopCategory, Products.ToList(), true); CreateShopCategories(shopCategory, Childs.ToList()); return shopCategory; }
public ShopCategory(ShopCategory parent) : this() { if (parent != null) { parent.Childs.Add(this); this.Parent = parent; } Context.Inst.ShopCategorySet.Add(this); }
public static List<ShopCategory> CreateShopCategories(ShopCategory parentShopCat, List<SupplierCategory> supCats) { List<ShopCategory> shopCategories = new List<ShopCategory>(); foreach (var supCat in supCats) { ShopCategory shopCategory = supCat.CreateShopCategory(parentShopCat); shopCategories.Add(shopCategory); } return shopCategories; }
private static ShopCategory FindMergeCat(ShopCategory parentShopCat, SupplierCategory supCat) { IEnumerable<ShopCategory> sameParentCats; if (parentShopCat == null) { sameParentCats = Context.Inst.ShopCategorySet.Where(c => c.Parent == null); } else { sameParentCats = parentShopCat.Childs; } if (sameParentCats == null) return null; // проверяем есть ли в этой категории уже подгатегории похожие на создаваемую ShopCategory mergeSubCat = sameParentCats.FirstOrDefault( c => (supCat.ShopCategory != null && supCat.ShopCategory.Id == c.Id) || c.Title == supCat.Title); return mergeSubCat; }
public static void CreateShopProducts(ShopCategory parentShopCat, List<SupplierProduct> supProds, bool merge) { foreach (var supProd in supProds) { bool isMergeProd = merge; if (isMergeProd) { isMergeProd = parentShopCat.Products.Any( p => p.Id == supProd.Id || p.Title == supProd.Title); } if (isMergeProd) { continue; } var shopProduct = supProd.CreateShopProduct(parentShopCat); parentShopCat.Products.Add(shopProduct); } }
public List<ShopCategory> CreateShopCategories(ShopCategory parentShopCat) { var shopCategories = SupplierCategory.CreateShopCategories(parentShopCat, GetRootCategories()); return shopCategories; }
private void CreateShopCatNode(TreeListNode parent) { ITreeNode data = GetData(parent); ShopCatNode parentShopCatNode = null; if (data is ShopProdNode) { parentShopCatNode = (data as ShopProdNode).Parent as ShopCatNode; } else { parentShopCatNode = data as ShopCatNode; } ShopCategory parentShopCat = parentShopCatNode.Base; var shopCategory = new ShopCategory(parentShopCat); shopCategory.Title = "Новая категория"; context.SaveChanges(); var shopCatNode = new ShopCatNode(shopCategory, parentShopCatNode); parentShopCatNode.Childs.Add(shopCatNode); parent.TreeList.RefreshDataSource(); foreach (TreeListNode treeListNode in parent.Nodes) { ShopCatNode neighbourCat = GetData(treeListNode) as ShopCatNode; if (neighbourCat == null) continue; if (neighbourCat.Base.Id != shopCategory.Id) continue; var treeList = treeListNode.TreeList; treeList.MakeNodeVisible(treeListNode); treeListNode.TreeList.FocusedNode = treeListNode; //treeListNode.TreeList.SetFocusedNode(treeListNode); treeListNode.TreeList.ShowEditor(); break; } }
public void Move(ShopCategory newCategory) { if (newCategory==null) { throw new ArgumentNullException(); } Category.Products.Remove(this); newCategory.Products.Add(this); Category = newCategory; }
IEnumerable<Image> SameCategoryImages(ShopCategory cat) { var ci = images[cat.Id]; var childsImages = ci.Childs.AsParallel().SelectMany(SameCategoryImages); return ci.Images.Union(childsImages); }
public void Move(ShopCategory newParent) { if (Parent != null) { Parent.Childs.Remove(this); } if (newParent != null) { newParent.Childs.Add(this); } Parent = newParent; }
public void Merge(ShopCategory newParent) { if (newParent == null) { throw new ArgumentNullException(); } foreach (ShopProduct shopProduct in Products) { shopProduct.Move(newParent); } foreach (ShopCategory shopCategory in Childs) { shopCategory.Move(newParent); } }
public ShopCatNode(ShopCategory @base, ShopCatNode parentShopCatNode) { Base = @base; Parent = parentShopCatNode; }