public static bool DeleteProductFaqPidDetail(ProductFaqConfigModel model) { using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir"))) { return(dbHelper.ExecuteNonQuery(@" Delete from Configuration..ProductFaqPidDetail where Pid=@Pid;" , CommandType.Text, new SqlParameter[] { new SqlParameter("@Pid", model.Pid) }) >= 0); } }
public static int InsertProductFaqConfigModel(ProductFaqConfigModel model) { using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir"))) { return(Convert.ToInt32(dbHelper.ExecuteScalar(@" INSERT INTO Configuration..ProductFaqConfig( Status, QuestionDetail ) VALUES( 1, @QuestionDetail )SELECT @@IDENTITY;" , CommandType.Text, new SqlParameter[] { new SqlParameter("@QuestionDetail", model.QuestionDetail), }))); } }
public static bool InsertProductFaqPidDetail(ProductFaqConfigModel model, int fkId) { using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir"))) { return(dbHelper.ExecuteNonQuery(@" INSERT INTO Configuration..ProductFaqPidDetail ( Pid, FkFaqId ) VALUES( @Pid, @FkFaqId );" , CommandType.Text, new SqlParameter[] { new SqlParameter("@Pid", model.Pid), new SqlParameter("@FkFaqId", fkId), }) > 0); } }
public static bool UpdateProductFaqConfigAndDetailDetailModels(List <ProductFaqConfigDetailModel> models, List <string> pids) { try { var lisPids = pids; var questionDetais = string.Join(",", models.Select(r => r.Question).ToArray()); //var aa = , questionDetais); bool result = true; //1,插入问题表,一次只会插入一条,但是这个会对应多个问答列表,这个问题也会应用到多个产品信息里 var faqModel = new ProductFaqConfigModel { QuestionDetail = questionDetais }; var listpidModes = lisPids.Select(pid => new ProductFaqConfigModel { Pid = pid, }).ToList(); var returnId = DalFaqManage.InsertProductFaqConfigModel(faqModel); //2,不去管老的问题,新增一个问题关系 foreach (var model in models) { result = result && DalFaqManage.InsertProductFaqConfigDetailModels(model, returnId); } //3,对于产品的话,可以更新已经存在的,新增新选中过来的,或者直接删掉所有,重新新增一遍,新增的数据可能会很多,可以选择批量新增,这个看下性能问题再说 foreach (var patchs in lisPids.Split(100).Select(_ => _.ToList())) { result = result && DalFaqManage.DeleteProductFaqPidDetailForPatch(patchs); } result = result && DalFaqManage.InsertProductFaqPidDetailPatch(lisPids, returnId); return(result); } catch (Exception e) { Console.WriteLine(e); throw; } }