// GET: ProductManager public ActionResult Index() { string role = CurrentUser.Role; if (role != Convert.ToString((byte)UserType.Admin)) { return(RedirectToAction("index", "home")); } var categories = _categoryService.GetAllCategory(); PrepareCategoryHash categoryHash = new PrepareCategoryHash(); //kategori ağaç class categoryHash.CreateHashTableAndProductTree(); //kategori ve ürün agacını oluştur Hashtable hashTable = categoryHash.GetCategoryTable; List <ProductManagmentHomeModel> model = new List <ProductManagmentHomeModel>(); foreach (var item in categories) //ürün ağacından verileri modele atama { ProductGroupTree treeGroup = (ProductGroupTree)hashTable[item.CategoryName]; //product group agacı tipine casting işlemi if (treeGroup != null) { treeGroup.inOrder(treeGroup.GetRoot());//urun grubu ağacı inorder dolanır var treeNode = treeGroup.ProductNode; model.Add(new ProductManagmentHomeModel { ProductGroupTree = treeNode, CategoryName = item.CategoryName }); } } return(View(model)); }
public ActionResult TraverByType(string type) { var categories = _categoryService.GetAllCategory(); PrepareCategoryHash categoryHash = new PrepareCategoryHash(); //kategori ağaç class categoryHash.CreateHashTableAndProductTree(); //kategori ve ürün agacını oluştur Hashtable hashTable = categoryHash.GetCategoryTable; List <ProductManagmentHomeModel> model = new List <ProductManagmentHomeModel>(); ViewBag.type = type; List <ProductGroupTreeNode> treeNode1 = new List <ProductGroupTreeNode>(); foreach (var item in categories) //ürün ağacından verileri modele atama { ProductGroupTree treeGroup = (ProductGroupTree)hashTable[item.CategoryName]; //product group agacı tipine casting işlemi if (treeGroup != null) { if (type == "inorder") { treeGroup.inOrder(treeGroup.GetRoot()); } else if (type == "preorder") { treeGroup.preOrder(treeGroup.GetRoot()); } else if (type == "postorder") { treeGroup.postOrder(treeGroup.GetRoot()); } //urun grubu ağacı inorder dolanır var treeNode = treeGroup.ProductNode; treeNode1.AddRange(treeNode); } } return(View(treeNode1)); }
public ActionResult ProductCategorie(string productGoupName, string PriceBegin, string PriceLast) { HomeModel1 model = new HomeModel1(); ViewBag.CategoryName = productGoupName; ViewBag.PriceBegin = PriceBegin; ViewBag.PriceLast = PriceLast; var categories = _categoryService.GetAllCategory(); PrepareCategoryHash categoryHash = new PrepareCategoryHash(); //kategori ağaç class categoryHash.CreateHashTableAndProductTree(); //kategori ve ürün agacını oluştur Hashtable hashTable = categoryHash.GetCategoryTable; if (string.IsNullOrEmpty(PriceBegin)) { List <ProductItemModel> list = new List <ProductItemModel>(); var category = _categoryService.GetAllCategory().Where(x => x.CategoryName == productGoupName).FirstOrDefault(); var categoryParent = _categoryService.GetCategoryByCategoryId(category.CategoryParentId); ProductGroupTree treeGroup = (ProductGroupTree)hashTable[categoryParent.CategoryName]; //product group agacı tipine casting işlemi var treeNode = treeGroup.GetProductTreeNodeByProductGroupName(treeGroup.GetRoot(), productGoupName); if (treeNode != null) { model.Products.AddRange(treeNode.ProductBase.Products); } } else { decimal priceBegin = Convert.ToDecimal(PriceBegin); decimal priceLast = Convert.ToDecimal(PriceLast); if (string.IsNullOrEmpty(productGoupName)) { var categories1 = _categoryService.GetAllCategory().Where(x => x.CategoryType == (byte)CategoryType.Category); foreach (var item in categories1) { ProductGroupTree treeGroup = (ProductGroupTree)hashTable[item.CategoryName]; treeGroup.GetAllProductPriceBetween(treeGroup.GetRoot(), priceBegin, priceLast); model.Products.AddRange(treeGroup.ProductsBetween); } } else { List <ProductItemModel> list = new List <ProductItemModel>(); var category = _categoryService.GetAllCategory().Where(x => x.CategoryName == productGoupName).FirstOrDefault(); var categoryParent = _categoryService.GetCategoryByCategoryId(category.CategoryParentId); ProductGroupTree treeGroup = (ProductGroupTree)hashTable[categoryParent.CategoryName];//product group agacı tipine casting işlemi var treeNode = treeGroup.GetProductTreeNodeByProductGroupName(treeGroup.GetRoot(), productGoupName); if (treeNode != null) { foreach (var item in treeNode.ProductBase.Products.ToList()) { if (item.ProductPrice > priceBegin && item.ProductPrice < priceLast) { model.Products.AddRange(treeNode.ProductBase.Products); } } } } } return(View(model)); }