public bool InsertCategory(b2bCategory Category)
        {
            var svCategory = new CategoryService();
            var Cate       = svCategory.SelectData <b2bCategory>(" * ", "IsDelete = 0 AND RowFlag > 0 AND CategoryLevel = " + Category.CategoryLevel + " AND CategoryName = '" + Category.CategoryName + "'");

            if (Cate.Count() != 1)
            {
                Category.CreatedDate  = DateTimeNow;
                Category.ModifiedDate = DateTimeNow;
                Category.CreatedBy    = "sa";
                Category.ModifiedBy   = "sa";

                using (var trans = new TransactionScope())
                {
                    qDB.b2bCategories.InsertOnSubmit(Category);
                    qDB.SubmitChanges();
                    trans.Complete();
                    IsResult = true;
                }
            }
            else
            {
                IsResult = false;
            }
            return(IsResult);
        }
        public ActionResult InsertCategory(int ParentCateID, int CateLV, string CateName, string CateNameEN, int CateType)
        {
            var svCategory = new CategoryService();

            try
            {
                var model = new b2bCategory();

                if (ParentCateID != 0)
                {
                    var Category = svCategory.SelectData <b2bCategory>("CategoryID,ParentCategoryPath", "CategoryID = " + ParentCateID).First();
                    model.ParentCategoryPath = Category.ParentCategoryPath + " >> " + CateName;
                    model.CategoryType       = CateType;
                }
                else
                {
                    model.ParentCategoryPath = CateName;
                    model.CategoryType       = CateType;
                }

                string NumParent = "0000";
                string NumID     = "0000";
                if (CateLV != 1)
                {
                    var svCate = new CategoryService();
                    if (CateLV == 2)
                    {
                        var CategoryLV2 = svCate.SelectData <b2bCategory>("CategoryID,ParentCategoryPath", "CategoryID = " + ParentCateID).First();
                        NumParent = String.Format("{0:0000}", CategoryLV2.CategoryID);
                    }
                    if (CateLV == 3)
                    {
                        var Categories  = svCate.SelectData <b2bCategory>(" * ", "CategoryID = " + ParentCateID).First();
                        var CategoryLV3 = svCate.SelectData <b2bCategory>("CategoryID", "CategoryID = " + Categories.ParentCategoryID).First();
                        NumParent = String.Format("{0:0000}", CategoryLV3.CategoryID);
                        NumID     = String.Format("{0:0000}", ParentCateID);
                    }
                }

                if (CateNameEN != "")
                {
                    var CateNameENTrim = CateNameEN.Trim();
                    var NameEN         = CateNameENTrim.ToUpper().Substring(0, 4);
                    model.CategoryCode    = NameEN + "01-" + CateLV + "-" + NumParent + "-" + NumID;
                    model.CategoryNameEng = CateNameEN;
                }
                model.CategoryName     = CateName;
                model.RowFlag          = 1;
                model.RowVersion       = 1;
                model.BuyLeadCount     = 0;
                model.ProductCount     = 0;
                model.SupplierCount    = 0;
                model.CategoryKeyword  = CateName;
                model.CategoryLevel    = (byte)CateLV;
                model.ParentCategoryID = ParentCateID;
                model.IsDelete         = false;
                model.IsShow           = false;

                svCategory.InsertCategory(model);
            }
            catch (Exception ex)
            {
                CreateLogFiles(ex);
            }
            return(Json(new { IsResult = svCategory.IsResult, MsgError = res.Admin.lblCate_duplicate }));
        }