// 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 Delete(int id)
        {
            var product  = _productservice.GetProductByProductId(id);
            var category = _categoryService.GetCategoryByCategoryId(product.CategoryId);

            #region tree_delete_product
            PrepareCategoryHash categoryHash = new PrepareCategoryHash();
            categoryHash.CreateHashTableAndProductTree();
            Hashtable categoryTable             = categoryHash.GetCategoryTable;
            var       categories                = _categoryService.GetAllCategory().Where(x => x.CategoryType == (byte)CategoryType.Category);
            List <ProductItemModel> productList = new List <ProductItemModel>();
            foreach (var item in categories)
            {
                var tree = (ProductGroupTree)categoryTable[item.CategoryName];

                var treeNode = tree.GetProductTreeNodeByProductGroupName(tree.GetRoot(), category.CategoryName
                                                                         );
                if (treeNode.ProductBase != null)
                {
                    var anyProduct = treeNode.ProductBase.Products.Where(x => x.ModelName == product.ProductName && x.BrandName == product.BrandName).FirstOrDefault();
                    if (anyProduct != null)
                    {
                        treeNode.ProductBase.Products.Remove(anyProduct);
                    }
                }
            }
            #endregion
            _productservice.DeleteProduct(product);//database delete
            return(View());
        }
        public ActionResult ProductSearch(string ProductGroupName, string BrandName, string ModelName)
        {
            ProductSearchModel model = new ProductSearchModel();

            model.ProductGroupName = ProductGroupName;
            model.BrandName        = BrandName;
            model.ModelName        = ModelName;
            PrepareCategoryHash categoryHash = new PrepareCategoryHash();

            categoryHash.CreateHashTableAndProductTree();
            Hashtable categoryTable             = categoryHash.GetCategoryTable;
            var       categories                = _categoryService.GetAllCategory().Where(x => x.CategoryType == (byte)CategoryType.Category);
            List <ProductItemModel> productList = new List <ProductItemModel>();

            foreach (var item in categories)
            {
                var tree = (ProductGroupTree)categoryTable[item.CategoryName];

                var treeNode = tree.GetProductTreeNodeByProductGroupName(tree.GetRoot(), ProductGroupName);
                if (treeNode.ProductBase != null)
                {
                    var anyProduct = treeNode.ProductBase.Products.Where(x => x.ModelName == ModelName && x.BrandName == BrandName).ToList();
                    if (anyProduct.Count > 0)
                    {
                        productList.AddRange(anyProduct);
                    }
                }
            }

            model.Products = productList;
            return(View(model));
        }
        public ActionResult AddProduct(ProductAddModel model)
        {
            string role = CurrentUser.Role;

            if (role != Convert.ToString((byte)UserType.Admin))
            {
                return(RedirectToAction("index", "home"));
            }
            #region treeinsert
            var    category                  = _categoryService.GetCategoryByCategoryId(model.CategoryId);//tree insert product
            string productGroupName          = _categoryService.GetCategoryByCategoryId(model.ProductGroupId).CategoryName;
            PrepareCategoryHash categoryHash = new PrepareCategoryHash();
            categoryHash.CreateHashTableAndProductTree();
            var categoryTable = categoryHash.GetCategoryTable;
            var productGroupTreeForCategory  = (ProductGroupTree)categoryTable[category.CategoryName];
            ProductGroupTreeNode node        = productGroupTreeForCategory.GetProductTreeNodeByProductGroupName(productGroupTreeForCategory.GetRoot(), productGroupName);
            ProductItemModel     productItem = new ProductItemModel();
            productItem.BrandName          = model.BrandName;
            productItem.ModelName          = model.ModelName;
            productItem.ProductCost        = model.Cost;
            productItem.ProductDescription = model.ProductDescription;
            productItem.ProductPrice       = model.Price;
            productItem.Status             = true;
            productItem.ProductNumber      = model.ProductNumber;
            productItem.ProductName        = model.ProductName;
            node.ProductBase.Products.Add(productItem);

            #endregion
            #region databaseinsert
            string fileNameDt = "";
            if (Request.Files.Count > 0)//resim upload
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    fileNameDt = fileName;
                    var path = Path.Combine(Server.MapPath("~/ProductImages/"), fileName);
                    file.SaveAs(path);
                }
            }
            Product product = new Product();//database adding
            product.BrandName          = model.BrandName;
            product.CategoryId         = model.ProductGroupId;
            product.ModelName          = model.ModelName;
            product.ProductCost        = model.Cost;
            product.ProductDescription = model.ProductDescription;
            product.ProductName        = model.ProductName;
            product.ProductNumber      = model.ProductNumber;
            product.ProductPrice       = model.Price;
            product.ProductImagePath   = fileNameDt;
            product.Status             = true;
            _productservice.AddProduct(product);
            #endregion
            return(RedirectToAction("AddProduct", new { message = "success" }));
        }
Beispiel #5
0
        public ActionResult TreeDepth()
        {
            PrepareCategoryHash categoryHash = new PrepareCategoryHash();

            categoryHash.CreateHashTableAndProductTree();
            var categories = _categoryService.GetAllCategory().Where(x => x.CategoryType == (byte)CategoryType.Category);
            List <TreeDepthModel> model = new List <TreeDepthModel>();

            foreach (var item in categories)
            {
                var            productGroupTree = (ProductGroupTree)categoryHash.GetCategoryTable[item.CategoryName];
                TreeDepthModel s = new TreeDepthModel();
                productGroupTree.findTreeInfo(productGroupTree.GetRoot(), productGroupTree.TreeSize);
                s.Depth          = productGroupTree.maxDepth;
                s.DepthItemCount = productGroupTree.elementCountForEachDepth;
                s.TreeSize       = productGroupTree.TreeSize;
                s.CategoryName   = item.CategoryName;
                model.Add(s);
            }
            return(View(model));
        }
Beispiel #6
0
        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 nAdetUrunGet(string categoryName,int count)
 {
     NAdetUrunGetModel model = new NAdetUrunGetModel();
     PrepareCategoryHash categoryHash = new PrepareCategoryHash();
     model.CategoryName = categoryName;
     model.Coun = count;
     categoryHash.CreateHashTableAndProductTree();
     var ProductTree=(ProductGroupTree)categoryHash.GetCategoryTable[categoryName];
     if (ProductTree != null)
     {
        //var productList = ProductTree.ProductHeap.GetProductByCount(count,ProductTree.TreeSize);
         ProductHeap heap = new ProductHeap();
         ProductTree.inOrderForProductsAllProduct(ProductTree.GetRoot());
         var productList = ProductTree.AllProductByCategoryName;
         foreach (var item in productList)
         {
             heap.insert(item);
         }
         var productsLowPrice = heap.GetProductByCount(count,ProductTree.ProductTotalSize);//get lower product by count
         ProductTree.DeleteProducts(ProductTree.GetRoot(), productsLowPrice.Select(x => x.ProductId).ToList());//update products in tree
         model.Products = productsLowPrice;
         foreach (var item in productsLowPrice)
         {
             Invoice invoice = new Invoice();
             invoice.ProductId = item.ProductId;
             invoice.CustomerID = CurrentUser.CustmerID;
             invoice.DateTime = DateTime.Now;
             invoice.Approval = false;
             invoice.ProductNumber = 1;
             _checkoutService.AddInvoice(invoice);//sepete eklendi
             var product = _productService.GetProductByProductId(item.ProductId);//entitiy update
             product.ProductNumber = product.ProductNumber - 1;
             _productService.UpdateProduct(product);
         }
     }
     return View(model);
 }
Beispiel #8
0
        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));
        }
        public ActionResult Edit(ProductAddModel model, int hdnCategoryId)
        {
            var product      = _productservice.GetProductByProductId(model.ProductId);
            var categoryLast = _categoryService.GetCategoryByCategoryId(product.CategoryId);
            var categoryTop  = _categoryService.GetCategoryByCategoryId(categoryLast.CategoryParentId);

            if (hdnCategoryId != model.ProductGroupId)//kategori ve ürün grubu aynı değilse
            {
                //önce ağaçdaki ürün bulunur ve silinir daha sonra yeni yerine eklenir
                var newProductGroupName = _categoryService.GetCategoryByCategoryId(model.ProductGroupId).CategoryName;
                #region tree_delete_product
                PrepareCategoryHash categoryHash = new PrepareCategoryHash();
                categoryHash.CreateHashTableAndProductTree();
                Hashtable categoryTable             = categoryHash.GetCategoryTable;
                var       categories                = _categoryService.GetAllCategory().Where(x => x.CategoryType == (byte)CategoryType.Category);
                List <ProductItemModel> productList = new List <ProductItemModel>();

                var tree = (ProductGroupTree)categoryTable[categoryTop.CategoryName];

                var treeNode = tree.GetProductTreeNodeByProductGroupName(tree.GetRoot(), categoryLast.CategoryName
                                                                         );
                if (treeNode.ProductBase != null)
                {
                    var anyProduct = treeNode.ProductBase.Products.Where(x => x.ProductId == model.ProductId).FirstOrDefault();
                    if (anyProduct != null)
                    {
                        treeNode.ProductBase.Products.Remove(anyProduct);
                    }
                }


                #endregion

                #region treeinsert
                var    category         = _categoryService.GetCategoryByCategoryId(model.CategoryId);//tree insert product
                string productGroupName = _categoryService.GetCategoryByCategoryId(model.ProductGroupId).CategoryName;

                var productGroupTreeForCategory  = (ProductGroupTree)categoryTable[categoryTop.CategoryName];
                ProductGroupTreeNode node        = productGroupTreeForCategory.GetProductTreeNodeByProductGroupName(productGroupTreeForCategory.GetRoot(), newProductGroupName);
                ProductItemModel     productItem = new ProductItemModel();
                productItem.BrandName          = model.BrandName;
                productItem.ModelName          = model.ModelName;
                productItem.ProductCost        = model.Cost;
                productItem.ProductDescription = model.ProductDescription;
                productItem.ProductPrice       = model.Price;
                productItem.Status             = true;
                productItem.ProductNumber      = model.ProductNumber;
                productItem.ProductName        = model.ProductName;
                node.ProductBase.Products.Add(productItem);

                #endregion
            }
            else
            {
                //ürün bilgileri değiştirilir

                PrepareCategoryHash categoryHash = new PrepareCategoryHash();
                categoryHash.CreateHashTableAndProductTree();
                Hashtable categoryTable             = categoryHash.GetCategoryTable;
                var       categories                = _categoryService.GetAllCategory().Where(x => x.CategoryType == (byte)CategoryType.Category);
                List <ProductItemModel> productList = new List <ProductItemModel>();

                var tree = (ProductGroupTree)categoryTable[categoryTop.CategoryName];

                var treeNode = tree.GetProductTreeNodeByProductGroupName(tree.GetRoot(), categoryLast.CategoryName
                                                                         );
                if (treeNode.ProductBase != null)
                {
                    var anyProduct = treeNode.ProductBase.Products.Where(x => x.ProductId == model.ProductId).FirstOrDefault();
                    if (anyProduct != null)
                    {
                        anyProduct.ModelName          = model.ModelName;
                        anyProduct.ProductCost        = model.Cost;
                        anyProduct.ProductDescription = model.ProductDescription;
                        anyProduct.ProductName        = model.ProductName;
                        anyProduct.ProductNumber      = model.ProductNumber;
                        anyProduct.ProductPrice       = model.Price;
                        anyProduct.BrandName          = model.BrandName;
                    }
                }
            }
            #region databaseEdit
            if (model.CategoryId != hdnCategoryId)
            {
                product.CategoryId = model.ProductGroupId;
            }
            product.BrandName          = model.BrandName;
            product.ModelName          = model.ModelName;
            product.ProductCost        = model.Cost;
            product.ProductDescription = model.ProductDescription;
            product.ProductName        = model.ProductName;
            product.ProductNumber      = model.ProductNumber;
            product.ProductPrice       = model.Price;
            _productservice.UpdateProduct(product);
            #endregion

            return(RedirectToAction("Edit", new { id = model.ProductId, message = "success" }));
        }