/// <summary> /// 添加模板配置 /// </summary> /// <param name="etModel"></param> /// <returns></returns> public bool AddTemplate(ExamineTemplate etModel) { //using (CRDatabase _context = new CRDatabase()) //{ // UserInfo currentUser = new UserInfoService().GetCurrentUser(); // etModel.TEMPLATEID = Guid.NewGuid().ToString(); // etModel.CREATEDATETIME = System.DateTime.Now; // etModel.EDITDATETIME = System.DateTime.Now; // etModel.CREATEUSERID = currentUser.UserId; // etModel.EDITUSERID = currentUser.UserId; // etModel.OWNERID = currentUser.UserId; // etModel.ISDELETED = "0"; // _context.HR_EXAMINETEMPLATE.Add(ModelToEntity(etModel)); // foreach (var templateItem in etModel.TemplateItems) // { // templateItem.TEMPLATEID = etModel.TEMPLATEID; // templateItem.ITEMID = Guid.NewGuid().ToString(); // _context.HR_TEMPLATEITEM.Add(ModelToEntity(templateItem)); // } // return _context.SaveChanges() > 0; //} var context = DbSessionFactory.GetCurrentDbContext(); etModel.TEMPLATEID = Guid.NewGuid().ToString(); //1.添加主表 context.Set <HR_EXAMINETEMPLATE>().Add(ModelToEntity(etModel)); //2.添加项 foreach (var item in etModel.TemplateItems ?? new List <HR_TemplateItemDTO>()) { item.TEMPLATEID = etModel.TEMPLATEID; context.Set <HR_TEMPLATEITEM>().Add(ModelToEntity(item)); //3.添加项单位 foreach (var unitDto in item.ItemUnit ?? new List <HR_TemplateItemUnitDTO>()) { unitDto.ITEMID = item.TEMPLATEID; context.Set <HR_TEMPLATEITEMUNIT>().Add(ModelToEntity(unitDto)); } } return(context.SaveChanges() > 0); }
/// <summary> /// 添加依据模板 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool SaveBaseOnTemplate(string historyId, List <BaseTemplateResult> list) { if (list == null) { LogService.WriteInfoLog(logTitle, "试图查找为空的CTMS_BASETEMPLATERESULT实体!"); return(false); } using (var db = DbSessionFactory.GetCurrentDbContext()) { var oldList = db.Set <CTMS_BASETEMPLATERESULT>().Where(p => p.HISTORYID == historyId).ToList(); foreach (var item in oldList) { db.Set <CTMS_BASETEMPLATERESULT>().Remove(item); db.Set <CTMS_IMAGEEXAMINEREPORTDETAIL>().Where(p => p.REPORTID == item.BASETEMPLATEID) .ForEachAsync(k => db.Set <CTMS_IMAGEEXAMINEREPORTDETAIL>().Remove(k)); } foreach (var baseTemplateResult in list) { db.Set <CTMS_BASETEMPLATERESULT>().Add(ModelToEntity(baseTemplateResult)); //结果不序列化成json的存放 Dictionary <string, string> dic = JsonConvert.DeserializeObject <Dictionary <string, string> >(baseTemplateResult.RESULT); if (dic.Count > 0) { foreach (string key in dic.Keys) { CTMS_IMAGEEXAMINEREPORTDETAIL detail = new CTMS_IMAGEEXAMINEREPORTDETAIL(); detail.ID = Guid.NewGuid().ToString(); detail.REPORTID = baseTemplateResult.BASETEMPLATEID; detail.OPTIONID = key; detail.VALUE = dic[key]; db.Set <CTMS_IMAGEEXAMINEREPORTDETAIL>().Add(detail); } } } return(db.SaveChanges() > 0); } }