/// <summary> /// get data child for insert update /// </summary> /// <param name="contdescObj"></param> /// <returns></returns> private PNK_ProductCategoryDesc GetDataObjectChild(PNK_ProductCategoryDesc productcatdescObj, int lang) { switch (lang) { case 1: productcatdescObj.MainId = this.productcategoryId; productcatdescObj.LangId = Constant.DB.LangId; productcatdescObj.Name = SanitizeHtml.Sanitize(txtName.Value); productcatdescObj.NameUrl = Utils.RemoveUnicode(SanitizeHtml.Sanitize(txtName.Value)); productcatdescObj.Brief = SanitizeHtml.Sanitize(txtIntro.Text); productcatdescObj.MetaTitle = txtMetaTitle.Text.Trim(); productcatdescObj.MetaKeyword = txtMetaKeyword.Text.Trim(); productcatdescObj.MetaDecription = txtMetaDescription.Text.Trim(); productcatdescObj.H1 = txtH1.Text.Trim(); productcatdescObj.H2 = txtH2.Text.Trim(); productcatdescObj.H3 = txtH3.Text.Trim(); productcatdescObj.Detail = SanitizeHtml.Sanitize(txtDetail.Text); break; case 2: productcatdescObj.MainId = this.productcategoryId; productcatdescObj.LangId = Constant.DB.LangId_En; string name = !string.IsNullOrEmpty(txtNameEng.Value) ? SanitizeHtml.Sanitize(txtNameEng.Value) : SanitizeHtml.Sanitize(txtName.Value); productcatdescObj.Name = name; productcatdescObj.NameUrl = Utils.RemoveUnicode(SanitizeHtml.Sanitize(name)); productcatdescObj.Brief = SanitizeHtml.Sanitize(txtIntroEng.Text); productcatdescObj.MetaTitle = txtMetaTitleEng.Text.Trim(); productcatdescObj.MetaKeyword = txtMetaKeywordEng.Text.Trim(); productcatdescObj.MetaDecription = txtMetaDescriptionEng.Text.Trim(); productcatdescObj.H1 = txtH1Eng.Text.Trim(); productcatdescObj.H2 = txtH2Eng.Text.Trim(); productcatdescObj.H3 = txtH3Eng.Text.Trim(); productcatdescObj.Detail = SanitizeHtml.Sanitize(txtDetailEng.Text); break; } return(productcatdescObj); }
/// <summary> /// Save newscategory /// </summary> private void SaveProduct() { TreeNodeCollection nodes = TreeView1.Nodes; foreach (TreeNode n in nodes) { GetNodeRecursive(n); } //Xoá cache trước khi lưu CacheHelper.ClearContains("Product"); PNK_ProductCategory productcatObj = new PNK_ProductCategory(); PNK_ProductCategoryDesc productcatObjVn = new PNK_ProductCategoryDesc(); PNK_ProductCategoryDesc productcatObjEn = new PNK_ProductCategoryDesc(); if (this.productcategoryId == int.MinValue) { //get data insert productcatObj = this.GetDataObjectParent(productcatObj); productcatObj.PostDate = DateTime.Now; productcatObj.PathTree = "1"; productcatObjVn = this.GetDataObjectChild(productcatObjVn, Constant.DB.LangId); productcatObjEn = this.GetDataObjectChild(productcatObjEn, Constant.DB.LangId_En); List <PNK_ProductCategoryDesc> lst = new List <PNK_ProductCategoryDesc>(); lst.Add(productcatObjVn); lst.Add(productcatObjEn); //excute this.productcategoryId = generic2CBLL.Insert(productcatObj, lst); //update pathtree sau khi insert DGCParameter[] param = new DGCParameter[2]; param[0] = new DGCParameter("@parentId", DbType.Int32, productcatObj.ParentId); param[1] = new DGCParameter("@productCategoryId", DbType.Int32, productcategoryId); DBHelper.ExcuteFromStoreNonQuery("ProductCategory_UpdatePathTree", param); } else { string[] fields = { "Id" }; productcatObj.Id = this.productcategoryId; productcatObj = genericBLL.Load(productcatObj, fields); string publisheddOld = productcatObj.Published; //get data update productcatObj = this.GetDataObjectParent(productcatObj); productcatObjVn = this.GetDataObjectChild(productcatObjVn, Constant.DB.LangId); productcatObjEn = this.GetDataObjectChild(productcatObjEn, Constant.DB.LangId_En); List <PNK_ProductCategoryDesc> lst = new List <PNK_ProductCategoryDesc>(); lst.Add(productcatObjVn); lst.Add(productcatObjEn); //excute generic2CBLL.Update(productcatObj, lst, fields); //update pathtree sau khi edit DGCParameter[] param = new DGCParameter[2]; param[0] = new DGCParameter("@parentId", DbType.Int32, productcatObj.ParentId); param[1] = new DGCParameter("@productCategoryId", DbType.Int32, productcategoryId); DBHelper.ExcuteFromStoreNonQuery("ProductCategory_UpdatePathTree", param); //update tất cả Page của danh mục con sau khi edit param = new DGCParameter[2]; param[0] = new DGCParameter("@productCategoryId", DbType.Int32, productcategoryId); param[1] = new DGCParameter("@page", DbType.String, productcatObj.PageDetail); DBHelper.ExcuteFromStoreNonQuery("Product_UpdatePage", param); } }