public object UpdateProductCategoryByCategoryId()
 {
     var model = new ProductCategoryInfo();
     model.Id =  Convert.ToInt32(HttpContext.Current.Request.Params["CategoryId"]);
     model.Name = HttpContext.Current.Request.Params["CategoryName"];
     model.Desc = (string)HttpContext.Current.Request.Params["desc"];
     model.BigPicture = HttpContext.Current.Request.Params["BigPicture"];
     model.SmallPicture = HttpContext.Current.Request.Params["SmallPicture"];
     model.MediumPicture = HttpContext.Current.Request.Params["mediumpicture"];
     model.Content = HttpContext.Current.Request.Params["desc"];
     var display = 0;
     if (int.TryParse(HttpContext.Current.Request.Form["DisplayOrder"], out display))
     {
         model.DisplayOrder = display;
     }
     else
     {
         model.DisplayOrder = display;
     }
     //model.ParentId = int.Parse(HttpContext.Current.Request.Form["parentSelect"]);
     IProductCategoryService productCategoryService = new ProductCategoryService();
     return productCategoryService.Update(model);
 }
        public object DeleteProductCategoryById(int id)
        {
            IProductCategoryService productCategoryService=new ProductCategoryService();

            var productCategory = productCategoryService.GetProductCategoryById(id);
            if(productCategory!=null)
            {
                //WHERE Lft BETWEEN @MyLeft AND @MyRight;
                var all =
                    productCategoryService.GetProductCategory().Where(
                        s => s.Lft >= productCategory.Lft && s.Rgt <= productCategory.Rgt);
                IProductService productService=new ProductService();
                foreach (ProductCategoryInfo productCategoryInfo in all)
                {
                    productService.DeleteProductByCategoryId(productCategory.Id);
                }
            }

            return productCategoryService.DeleteById(id);
        }
 public bool InsertProductCategory()
 {
     //var option = int.Parse(HttpContext.Current.Request.Form["parentSelect"]);
     var model = new ProductCategoryInfo();
     model.Name=HttpContext.Current.Request.Form["CategoryName"];
     model.Desc = HttpContext.Current.Request.Form["desc"];
     model.MediumPicture = HttpContext.Current.Request.Form["mediumpicture"];
     model.ParentId = int.Parse(HttpContext.Current.Request.Form["parentSelect"]);
     var display = 0;
     if(int.TryParse(HttpContext.Current.Request.Form["DisplayOrder"],out display))
     {
         model.DisplayOrder = display;
     }
     else
     {
         model.DisplayOrder = display;
     }
     IProductCategoryService productCategoryService=new ProductCategoryService();
     return productCategoryService.Insert(model, 1) > 0;
 }
        public object GetProductCategory()
        {
            IProductCategoryService productCategoryService=new ProductCategoryService();

            var data = productCategoryService.GetProductCategory();

            // 每页显示记录数
            int pageSize = 10;
            // 记录总数
            int rowCount = data.Count;
            // 总页数
            int pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1;

            var resultObj = new JQGridDataResult
            {
                // 总页数
                PageCount = pageCount,
                // 当前页
                PageIndex = 1,
                // 总记录数
                Total = rowCount,
                // 数据
                Data =from item in data
                      select new
                          {
                              cell=new string[]
                                  {
                                     item.Id.ToString(),
                                     item.Name,
                                     item.Desc,
                                     item.CategoryId.ToString(),
                                     item.MediumPicture,

                                     item.Depth.ToString(),
                                     item.Parent,
                                     (item.Rgt==item.Lft+1).ToString(),
                                     "true",
                                     "true"
                                  }
                          }
            };
            return resultObj;
        }
        public List<ComboTree> GetComboTreeCategory(int id)
        {
            IProductCategoryService productCategoryService = new ProductCategoryService();
            var data = productCategoryService.GetProductCategory();
            List<ComboTree> result=new List<ComboTree>();

            var root = data.Where(s => s.Depth == id);
            foreach (var categoryInfo in root)
            {
                var comboTree = new ComboTree();
                comboTree.Id = categoryInfo.Id;
                comboTree.Text = categoryInfo.Name;
                comboTree.Children = GetComboTreeChildren(comboTree, categoryInfo, data);
                result.Add(comboTree);
            }
            return result;
        }
        public object GetAllProductCategory()
        {
            IProductCategoryService productCategoryService = new ProductCategoryService();

            return productCategoryService.GetProductCategory().Where(s=>s.Depth!=0).ToList();
        }
 public object DeleteProductCategoryOnlyById(int id)
 {
     IProductCategoryService productCategoryService = new ProductCategoryService();
     return productCategoryService.DeleteCurrentNodeOnlyById(id);
 }