/// <summary> /// 更新和新增字典 /// </summary> /// <param name="input"></param> /// <returns></returns> public DictionaryModel InsertOrUpdateDictionary(DictionaryModel input) { if (_DictionaryCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!"); } if (input.Id == input.ParentId) { throw new UserFriendlyException("名为【" + input.Name + "】的对象已不能做自身的上级!"); } //父级类型要和自身类型一样 if (input.DictionaryTypeId != null && input.ParentId != null) { if (_DictionaryCase.Get((long)input.ParentId).DictionaryTypeId != input.DictionaryTypeId) { throw new UserFriendlyException("操作失败!名为【" + input.Name + "】的对象类型和父级的类型不相同!"); } } //var entObj =input.MapTo<Dictionary>(); var type = _DictionaryCase.GetAll().FirstOrDefault(a => a.Id == input.Id) ?? new Dictionary(); type = Fun.ClassToCopy(input, type, (new string[] { "Id" }).ToList()); var resObj = _DictionaryCase.InsertOrUpdate(type); if (resObj == null) { throw new UserFriendlyException("新增或更新失败!"); } else { return(resObj.MapTo <DictionaryModel>()); } }
/* 2017-5-6 22:57:48 */ public FaUserInfo UserInfoSingle(ref ErrorInfo err, ApiRequesEntityBean <FaUserInfo> inEnt) { GlobalUser gu = Global.GetUser(inEnt.authToken); if (gu == null) { err.IsError = true; err.Message = "登录超时"; return(null); } using (DBEntities db = new DBEntities()) { ApiRequesEntityBean <TUser> userEnt = Fun.ClassToCopy <ApiRequesEntityBean <FaUserInfo>, ApiRequesEntityBean <TUser> >(inEnt); var user = api.UserApi.UserSingle(db, inEnt.authToken, ref err, userEnt); if (user == null) { return(null); } var userInfo = db.fa_user_info.FirstOrDefault(x => x.ID == user.ID); if (userInfo == null) { return(Mapper.Map <FaUserInfo>(user)); } var reEnt = Mapper.Map <FaUserInfo>(user); reEnt = Mapper.Map(userInfo, reEnt); return(reEnt); } }
public void SavePost(DistrictInput input) { //var depart = Fun.ClassToCopy<DistrictInput, District>(input); //var depart = AutoMapper.Mapper.Map<District>(input); var depart = _districtManagerManager.GetDistrict(input.Id) ?? new District(); depart = Fun.ClassToCopy(input, depart, (new string[] { "Id" }).ToList()); _districtManagerManager.SaveOrUpdateDistrict(depart); }
/// <summary> /// 新增或修改报表信息 /// </summary> /// <param name="report"></param> /// <returns></returns> public bool InsertOrUpdateReport(ReportInput report) { if (report != null) { if (_reportRepository.GetAll().Any(p => p.Id != report.Id && (p.Name == report.Name || p.Code == report.Code))) { throw new System.Exception("报表名称或编码重复"); } // var ent = AutoMapper.Mapper.Map<Report>(report); var ent = _reportRepository.GetAll().FirstOrDefault(x => x.Id == report.Id) ?? new Report(); ent = Fun.ClassToCopy(report, ent, (new string[] { "Id" }).ToList()); //var currReport = _reportRepository.InsertOrUpdate(ent); //更新主报表(基础信息) var reportId = _reportRepository.InsertOrUpdateAndGetId(ent); //更新子报表信息 if (report.ChildReportListJson != null && report.ChildReportListJson.Length > 0) { var reportList = JSON.EncodeToEntity <List <ChildReportModel> >(report.ChildReportListJson); if (reportList != null && reportList.Count > 0) { foreach (var rp in reportList) { //表格式报表保存逻辑 if (rp.ChildReportType == (short)ReportEnum.ReportType.KeyValue || rp.ChildReportType == (short)ReportEnum.ReportType.Table) { //调用表格报表的保存逻辑 _tbReportApp.SaveTbReport(rp, reportId, report.Code); } //RDLC报表保存逻辑 if (rp.ChildReportType == (short)ReportEnum.ReportType.Rdlc) { //调用RDLC报表保存逻辑 _rdlcReportApp.SaveRdlcReport(rp, reportId, report.Code); } //图形报表保存 else if (rp.ChildReportType == (short)ReportEnum.ReportType.Chart) { _chartReportApp.SaveChartReport(rp, reportId, report.Code); } } } } return(true); } else { throw new UserFriendlyException("传入信息为空!"); } }
public void UpdateScript(EditScript input) { //var model = input.MapTo<Script>(); //_script.Update(model); var type = _script.GetAll().FirstOrDefault(x => x.Id == input.Id); type = Fun.ClassToCopy(input, type, (new string[] { "Id" }).ToList()); _script.Update(type); DelNodeLinePosition(input.Id); AddNodeLinePosition(input); }
/// <summary> /// 新增或修改一个全局变量 /// </summary> /// <param name="gloVar"></param> public void SaveGlobalVar(GlobalVarModel gloVar) { // var global = AutoMapper.Mapper.Map<GlobalVar>(gloVar); try { var type = _globalVarRepository.GetAll().FirstOrDefault(x => x.Id == gloVar.Id) ?? new GlobalVar(); type = Fun.ClassToCopy(gloVar, type, (new string[] { "Id" }).ToList()); _globalVarRepository.InsertOrUpdate(type); } catch (Exception ex) { throw new UserFriendlyException("更新失败:" + ex.Message); } }
/* 2017年5月6日16:16:54 */ public FaUserInfo UserInfoSave(DBEntities db, ref ErrorInfo err, ApiRequesSaveEntityBean <FaUserInfo> inEnt) { GlobalUser gu = Global.GetUser(inEnt.authToken); if (gu == null) { err.IsError = true; err.Message = "登录超时"; return(null); } if (string.IsNullOrEmpty(inEnt.saveKeys)) { inEnt.saveKeys = ""; } var allPar = inEnt.saveKeys.Split(','); //调用用户保存 var user = api.UserApi.UserSave(db, inEnt.authToken, ref err, inEnt.entity, allPar); if (err.IsError) { return(null); } var userInfo = db.fa_user_info.SingleOrDefault(x => x.ID == user.ID); if (userInfo == null) { userInfo = Mapper.Map <fa_user_info>(inEnt.entity); userInfo.ID = user.ID; userInfo.STATUS = "正常"; userInfo.CREATE_TIME = DateTime.Now; userInfo.CREATE_USER_ID = gu.UserId; userInfo.CREATE_USER_NAME = gu.UserName; userInfo.UPDATE_TIME = DateTime.Now; userInfo.UPDATE_USER_ID = gu.UserId; userInfo.UPDATE_USER_NAME = gu.UserName; UpdataLog <FaUserInfo> updataLog = new UpdataLog <FaUserInfo>(db); updataLog.UpdataLogSaveCreate(gu, Mapper.Map <FaUserInfo>(userInfo)); db.fa_user_info.Add(userInfo); } else { UpdataLog <FaUserInfo> updataLog = new UpdataLog <FaUserInfo>(db, Mapper.Map <FaUserInfo>(userInfo)); userInfo = Fun.ClassToCopy <FA_USER_INFO, fa_user_info>(inEnt.entity, userInfo, allPar); //userInfo.UPDATE_TIME = DateTime.Now; userInfo.UPDATE_USER_ID = gu.UserId; userInfo.UPDATE_USER_NAME = gu.UserName; updataLog.UpdataLogSaveUdate(gu, Mapper.Map <FaUserInfo>(userInfo)); } return(Mapper.Map <FaUserInfo>(userInfo)); }
/// <summary> /// 更新和新增属性 /// </summary> /// <param name="input"></param> /// <returns></returns> public AttrModel InsertOrUpdateAttr(AttrModel input) { if (_AttrCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!"); } //var entObj =input.MapTo<Attr>(); var entObj = _AttrCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new Attr(); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); //var entObj= AutoMapper.Mapper.Map<Attr>(input); var id = _AttrCase.InsertOrUpdateAndGetId(entObj); return(entObj.MapTo <AttrModel>()); }
/// <summary> /// 更新和新增文件上传 /// </summary> /// <param name="input"></param> /// <returns></returns> public FileUploadModel InsertOrUpdateFileUpload(FileUploadModel input) { try { //var entObj =input.MapTo<FileUpload>(); var entObj = _FileUploadCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new FileUpload(); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); //var entObj= AutoMapper.Mapper.Map<FileUpload>(input); var id = _FileUploadCase.InsertOrUpdateAndGetId(entObj); return(entObj.MapTo <FileUploadModel>()); } catch (Exception ex) { return(null); throw ex; } }
/// <summary> /// 新增/修改脚本类型 /// </summary> /// <param name="input"></param> public void editScriptType(ScriptTypeInput input) { if (_scriptType.GetAll().Any(x => x.Name == input.Name && x.Id != input.Id)) { throw new System.Exception("已有类型:" + input.Name); } // var model = input.MapTo<ScriptType>(); var model = _scriptType.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new ScriptType(); model = Fun.ClassToCopy(input, model, (new string[] { "Id" }).ToList()); var res = _scriptType.InsertOrUpdate(model); if (res == null) { throw new System.Exception("保存失败!"); } }
/// <summary> /// 更新和新增数据库 /// </summary> /// <param name="input"></param> /// <returns></returns> public void InsertOrUpdateDbServer(DbServerInput input) { if (_dbServerRepository.GetAll().Any(p => p.Id != input.Id && p.ByName == input.ByName)) { throw new System.Exception("数据库别名重复"); } //var dbServer = AutoMapper.Mapper.Map<DbServerInput, DbServer>(input); var dbServer = _dbServerRepository.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new DbServer(); dbServer = Fun.ClassToCopy(input, dbServer, (new string[] { "Id" }).ToList()); var server = _dbServerRepository.InsertOrUpdate(dbServer); if (server == null) { throw new UserFriendlyException("新增或者更新失败!"); } }
/// <summary> /// 更新和新增终端共享文件夹 /// </summary> /// <param name="input"></param> /// <returns></returns> public FolderModel InsertOrUpdateFolder(FolderModel input) { try { if (_FolderCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name && p.ComputerId == input.ComputerId)) { throw new Exception("名为【" + input.Name + "】的对象已存在!"); } //var entObj =input.MapTo<Folder>(); var entObj = _FolderCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new Folder(); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); //var entObj= AutoMapper.Mapper.Map<Folder>(input); var id = _FolderCase.InsertOrUpdateAndGetId(entObj); return(entObj.MapTo <FolderModel>()); } catch (Exception ex) { //return null; throw ex; } }
public bool DistrictSave(string loginKey, ref ErrorInfo err, DISTRICT inEnt, IList <string> allPar = null) { if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(false); } using (DBEntities db = new DBEntities()) { var ent = db.fa_district.SingleOrDefault(a => a.ID == inEnt.ID); if (ent == null) { ent = Mapper.Map <fa_district>(inEnt); db.fa_district.Add(ent); } else { ent = Fun.ClassToCopy <DISTRICT, fa_district>(inEnt, ent, allPar); } return(Fun.DBEntitiesCommit(db, ref err)); } }
/// <summary> /// 更新和新增节点类型 /// </summary> /// <param name="input"></param> /// <returns></returns> public ScriptNodeTypeOutput InsertOrUpdateScriptNodeType(ScriptNodeTypeInput input) { if (_scriptNodeTypeRepository.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new System.Exception("节点类型重复"); } //var type = AutoMapper.Mapper.Map<ScriptNodeTypeInput, ScriptNodeType>(input); var type = _scriptNodeTypeRepository.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new ScriptNodeType(); type = Fun.ClassToCopy(input, type, (new string[] { "Id" }).ToList()); var nodeType = _scriptNodeTypeRepository.InsertOrUpdate(type); if (nodeType != null) { return(AutoMapper.Mapper.Map <ScriptNodeTypeOutput>(nodeType)); } else { throw new UserFriendlyException("更新失败!"); } }
/// <summary> /// 更新和新增月度总奖金 /// </summary> /// <param name="input"></param> /// <returns></returns> public MonthBonusModel InsertOrUpdateMonthBonus(MonthBonusModel input) { if (_MonthBonusCase.GetAll().Any(p => p.Id != input.Id && p.Month == input.Month)) { throw new UserFriendlyException("月份【" + input.Month + "】的对象已存在!"); } // var entObj =input.MapTo<MonthBonus>(); var entObj = _MonthBonusCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new MonthBonus(); //var entObj= AutoMapper.Mapper.Map<MonthBonus>(input); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); var resObj = _MonthBonusCase.InsertOrUpdate(entObj); if (resObj == null) { throw new UserFriendlyException("新增或更新失败!"); } else { return(resObj.MapTo <MonthBonusModel>()); } }
/// <summary> /// 更新和新增指标标识 /// </summary> /// <param name="input"></param> /// <returns></returns> public TargetTagModel InsertOrUpdateTargetTag(TargetTagModel input) { if (_TargetTagCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!"); } //var entObj =input.MapTo<TargetTag>(); var entObj = _TargetTagCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new TargetTag(); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); //var entObj= AutoMapper.Mapper.Map<TargetTag>(input); var resObj = _TargetTagCase.InsertOrUpdate(entObj); if (resObj == null) { throw new UserFriendlyException("新增或更新失败!"); } else { return(resObj.MapTo <TargetTagModel>()); } }
/// <summary> /// 更新和新增文件库 /// </summary> /// <param name="input"></param> /// <returns></returns> public FileLibraryModel InsertOrUpdateFileLibrary(FileLibraryModel input) { try { if (_FileLibraryCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { return(_FileLibraryCase.GetAll().FirstOrDefault(x => x.Name == input.Name).MapTo <FileLibraryModel>()); } //var entObj =input.MapTo<FileLibrary>(); var entObj = _FileLibraryCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new FileLibrary(); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); //var entObj= AutoMapper.Mapper.Map<FileLibrary>(input); var id = _FileLibraryCase.InsertOrUpdateAndGetId(entObj); return(entObj.MapTo <FileLibraryModel>()); } catch (Exception ex) { return(null); throw ex; } }
/// <summary> /// 更新和新增文件格式 /// </summary> /// <param name="input"></param> /// <returns></returns> public FileFormatModel InsertOrUpdateFileFormat(FileFormatModel input) { try { if (_FileFormatCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!"); } //var entObj =input.MapTo<FileFormat>(); var entObj = _FileFormatCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new FileFormat(); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); //var entObj= AutoMapper.Mapper.Map<FileFormat>(input); var id = _FileFormatCase.InsertOrUpdateAndGetId(entObj); return(entObj.MapTo <FileFormatModel>()); } catch (Exception ex) { return(null); throw ex; } }
/// <summary> /// 更新和新增字典类型 /// </summary> /// <param name="input"></param> /// <returns></returns> public DictionaryTypeModel InsertOrUpdateDictionaryType(DictionaryTypeModel input) { if (_DictionaryTypeCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!"); } //使用MapTo和 Map会把没有传值过来的字段清空 //var entObj = AutoMapper.Mapper.Map<DictionaryType>(input); //var entObj = input.MapTo<DictionaryType>(); //使用框架方法Fun.ClassToCopy,复制一个类到另一个类进行赋值备注:需要排除ID(主键) var type = _DictionaryTypeCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new DictionaryType(); type = Fun.ClassToCopy(input, type, (new string[] { "Id" }).ToList()); var res = _DictionaryTypeCase.InsertOrUpdate(type); if (res == null) { throw new UserFriendlyException("新增或更新失败!"); } else { return(res.MapTo <DictionaryTypeModel>()); } }
public TUser UserSave(object dbObject, string loginKey, ref ErrorInfo err, TUser inEnt, IList <string> allPar) { GlobalUser gu = Global.GetUser(loginKey); if (gu == null) { err.IsError = true; err.Message = "登录超时"; return(null); } DBEntities db = dbObject as DBEntities; if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(null); } #region 判断登录名是否有效 if (!string.IsNullOrEmpty(inEnt.LOGIN_NAME)) { err.IsError = true; err.Message = "该用户不能有账号"; return(null); } #endregion var userEnt = db.fa_user.SingleOrDefault(a => a.ID == inEnt.ID); #region 修改&&添加user bool isAdd = false; if (userEnt == null) { isAdd = true; userEnt = Mapper.Map <fa_user>(inEnt); if (userEnt.ID == 0) { userEnt.ID = Fun.GetSeqID <fa_user>(); } var dis = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID); if (dis != null) { userEnt.REGION = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID).REGION; } } else { userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt, userEnt, allPar); } #endregion #region 根据:RoleAllIDStr 修改用户角色 if (allPar.Contains("RoleAllIDStr") && !string.IsNullOrEmpty(inEnt.RoleAllIDStr)) { IList <int> allRoleId = new List <int>(); allRoleId = inEnt.RoleAllIDStr.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList(); userEnt.fa_role.Clear(); userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList(); } #endregion #region 根据:UserDistrict 修改用户管辖区域 if (allPar.Contains("UserDistrict") && !string.IsNullOrEmpty(inEnt.UserDistrict)) { userEnt.fa_district1.Clear(); var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList(); userEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList(); } #endregion if (isAdd) { db.fa_user.Add(userEnt); } GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit); inEnt.ID = userEnt.ID; return(inEnt); }
public ApiPagingDataBean <FILES> FileList(ref ErrorInfo err, ApiRequesPageBean <ApiPagingDataBean <FILES> > inEnt) { GlobalUser gu = Global.GetUser(inEnt.authToken); if (gu == null) { err.IsError = true; err.Message = "登录超时"; return(null); } if (inEnt.pageSize == 0) { inEnt.pageSize = 10; } if (inEnt == null) { err.IsError = true; err.Message = "参数有误"; return(null); } ApiPagingDataBean <FILES> reEnt = new ApiPagingDataBean <FILES>(); int skip = 0; if (inEnt.currentPage > 1) { skip = (inEnt.currentPage - 1) * inEnt.pageSize; } using (DBEntities db = new DBEntities()) { var allData = db.fa_files.Where(x => x.USER_ID == gu.UserId).OrderByDescending(x => x.ID).AsEnumerable(); #region 过虑条件 if (inEnt.searchKey != null) { foreach (var filter in inEnt.searchKey) { allData = Fun.GetListWhere(allData, filter.K, filter.T, filter.V, ref err); } } #endregion #region 排序 if (allData == null) { err.IsError = true; return(null); } foreach (var filter in inEnt.orderBy) { allData = Fun.GetListOrder(allData, filter.K, filter.V, ref err); } #endregion var allList = allData.Skip(skip).Take(inEnt.pageSize).ToList(); reEnt.currentPage = inEnt.currentPage; reEnt.pageSize = inEnt.pageSize; reEnt.totalCount = allData.Count(); reEnt.totalPage = reEnt.totalCount / reEnt.pageSize; if (reEnt.totalCount % reEnt.pageSize != 0) { reEnt.totalPage++; } IList <FILES> reList = new List <FILES>(); foreach (var t in allList) { var single = Fun.ClassToCopy <fa_files, FILES>(t); reList.Add(single); } reEnt.data = reList; } return(reEnt); }
/// <summary> /// 更新和新增节点 /// </summary> /// <param name="input"></param> /// <returns></returns> public ScriptNodeOutput InsertOrUpdateScriptNode(ScriptNodeInput input) { if (_scriptNodeRepository.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new System.Exception("节点重复"); } if (_scriptNodeRepository.GetAll().Any(p => p.Id != input.Id && p.ScriptModel == (short)PubEnum.ScriptModel.CreateTb && p.EnglishTabelName == input.EnglishTabelName)) { throw new System.Exception("表名重复"); } //var dbServer = _dbServerRepository.Get(input.Id) ?? new DbServer(); //var dbServer = AutoMapper.Mapper.Map<DbServer>(input); // var node = AutoMapper.Mapper.Map<ScriptNodeInput, ScriptNode>(input); var node = _scriptNodeRepository.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new ScriptNode(); node = Fun.ClassToCopy(input, node, (new string[] { "Id" }).ToList()); #region 修改节点的时候是否修改实例节点 if (input.Id != 0 && input.IsUpdateExample == 1) { #region 查询是否有节点在执行中 var scriptNodeCaseTemp = _scriptNodeCase.GetAllList(x => x.RunStatus == 2 && x.ScriptNodeId == input.Id); #endregion try { if (scriptNodeCaseTemp.Count != 0) { string nodeId = string.Empty; for (int i = 0; i < scriptNodeCaseTemp.Count; i++) { nodeId = nodeId + scriptNodeCaseTemp[i].Id + ","; } throw new UserFriendlyException("更新失败,有节点实例正在执行!节点ID:" + nodeId); } var temp = _scriptNodeCase.GetAllList(x => x.ScriptNodeId == input.Id); for (int i = 0; i < temp.Count; i++) { temp[i].DbServerId = input.DbServerId; temp[i].ScriptModel = input.ScriptModel; temp[i].Content = input.Content; temp[i].Remark = input.Remark; temp[i].EnglishTabelName = input.EnglishTabelName; temp[i].ChineseTabelName = input.ChineseTabelName; temp[i].TableType = input.TableType; temp[i].TableModel = input.TableModel; _scriptNodeCase.Update(temp[i]); } } catch (Exception e) { throw new UserFriendlyException("更新节点实例失败!" + e.Message); } } #endregion //修改节点 var scriptNode = _scriptNodeRepository.InsertOrUpdate(node); #region 写入节点的调整日志 var log = AutoMapper.Mapper.Map <ScriptNodeInput, ScriptNodeLog>(input); log.ScriptNodeId = scriptNode.Id; log.LogModel = (short)(input.Id == 0 ? 1 : 2); log.Id = 0; _scriptNodeLogRepository.Insert(log); #endregion if (scriptNode != null) { return(AutoMapper.Mapper.Map <ScriptNodeOutput>(scriptNode)); } else { throw new UserFriendlyException("更新失败!"); } }
public bool RoleSave(string loginKey, ref ErrorInfo err, TRole inEnt, IList <string> allPar = null) { if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(false); } using (DBEntities db = new DBEntities()) { try { var ent = db.fa_role.SingleOrDefault(a => a.ID == inEnt.ID); bool isAdd = false; if (ent == null) { isAdd = true; ent = Mapper.Map <fa_role>(inEnt); ent.ID = Fun.GetSeqID <fa_role>(); } else { ent = Fun.ClassToCopy <ProInterface.Models.ROLE, fa_role>(inEnt, ent, allPar); } ent.fa_module.Clear(); if (!string.IsNullOrEmpty(inEnt.ModuleAllStr)) { IList <int> moduleID = inEnt.ModuleAllStr.Split(',').Select(x => Convert.ToInt32(x)).ToList(); ent.fa_module = db.fa_module.Where(x => moduleID.Contains(x.ID)).ToList(); } if (!string.IsNullOrEmpty(inEnt.RoleConfigsStr)) { inEnt.RoleConfigs = JSON.EncodeToEntity <IList <ROLE_CONFIG> >(inEnt.RoleConfigsStr); foreach (var t in inEnt.RoleConfigs) { var cfg = ent.fa_role_config.SingleOrDefault(x => x.NAME == t.NAME); if (cfg == null) { ent.fa_role_config.Add(new fa_role_config { NAME = t.NAME, ROLE_ID = ent.ID, VALUE = t.VALUE }); } else { cfg.VALUE = t.VALUE; } } } foreach (var t in ent.fa_role_config.ToList()) { if (inEnt.RoleConfigs.SingleOrDefault(x => x.NAME == t.NAME) == null) { db.fa_role_config.Remove(t); } } if (isAdd) { db.fa_role.Add(ent); } Fun.DBEntitiesCommit(db, ref err); GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit); return(true); } catch (DbEntityValidationException e) { err.IsError = true; err.Message = e.Message; err.Excep = e; return(false); } } }
/// <summary> /// 给指定脚本节点添加一个实例 /// </summary> /// <param name="scriptNodeID"></param> /// <param name="scriptCaseID"></param> /// <param name="db"></param> /// <param name="err"></param> /// <returns></returns> public static EM_SCRIPT_NODE_CASE AddScriptNodeCase(long?scriptNodeID, long?scriptCaseID, DBEntities db, ref ErrorInfo err, int isFirst = 0) { if (scriptCaseID == null || scriptNodeID == null) { err.IsError = true; err.Message = "传入的脚本节点ID或脚本流实例ID为空"; return(null); } var _scriptNode = new ScriptNode(); if (isFirst == 1) { var sn = db.EM_SCRIPT_NODE.Find(scriptNodeID); if (sn == null) { err.IsError = true; err.Message = "未找到传入的脚本节点[" + scriptNodeID.ToString() + "]"; return(null); } else { _scriptNode = Fun.ClassToCopy(sn, _scriptNode); } } else { //var sn = db.EM_SCRIPT_NODE_FORCASE.Find(scriptNodeID); var sn = db.EM_SCRIPT_NODE_FORCASE.FirstOrDefault(p => p.SCRIPT_CASE_ID == scriptCaseID && p.SCRIPT_NODE_ID == scriptNodeID); if (sn == null) { err.IsError = true; err.Message = "未找到传入的脚本节点[" + scriptNodeID.ToString() + "]"; return(null); } else { _scriptNode = Fun.ClassToCopy(sn, _scriptNode); } } EM_SCRIPT_NODE_CASE scriptNodeCase = new EM_SCRIPT_NODE_CASE { ID = Fun.GetSeqID <EM_SCRIPT_NODE_CASE>(), SCRIPT_CASE_ID = scriptCaseID, SCRIPT_ID = db.EM_SCRIPT_CASE.Find(scriptCaseID).SCRIPT_ID, SCRIPT_NODE_ID = scriptNodeID, DB_SERVER_ID = _scriptNode.DB_SERVER_ID, SCRIPT_MODEL = _scriptNode.SCRIPT_MODEL, CONTENT = _scriptNode.CONTENT, REMARK = _scriptNode.REMARK, E_TABLE_NAME = _scriptNode.E_TABLE_NAME, C_TABLE_NAME = _scriptNode.C_TABLE_NAME, TABLE_TYPE = _scriptNode.TABLE_TYPE, TABLE_MODEL = _scriptNode.TABLE_MODEL, CREATE_TIME = DateTime.Now, TABLE_SUFFIX = DateTime.Now.Ticks,//赋值方式改为:去获取脚本流实例的ID RUN_STATUS = (short)PubEnum.RunStatus.Wait, }; db.EM_SCRIPT_NODE_CASE.Add(scriptNodeCase); return(scriptNodeCase); //try //{ // db.SaveChanges(); // return scriptNodeCase.ID; //} //catch (Exception e) //{ // err.IsError = true; // err.Message = e.Message; // err.Excep = e; // return null; //} }
/// <summary> /// 复制脚本流节点配置信息(FOR ScriptCase) /// </summary> /// <param name="scriptCaseID">脚本流实例ID</param> /// <param name="scriptID">脚本流ID</param> /// <param name="db"></param> /// <param name="err"></param> /// <returns></returns> public static void CopyScriptNodeForCase(long?scriptCaseID, long?scriptID, string scriptName, DBEntities db, ref ErrorInfo err) { if (scriptID == null || scriptCaseID == null) { err.IsError = true; err.Message = "传入的scriptID和scriptCaseID值不能为空"; return; } var srnList = db.EM_SCRIPT_REF_NODE.Where(p => p.SCRIPT_ID == scriptID).ToList(); if (srnList == null || srnList.Count == 0) { err.IsError = true; err.Message = string.Format(@"未找到脚本流【{0}】的节点配置信息", scriptName); return; } #region 逐个复制脚本节点流程配置 foreach (var srn in srnList) { EM_SCRIPT_REF_NODE_FORCASE srnCase = new EM_SCRIPT_REF_NODE_FORCASE(); Fun.ClassToCopy(srn, srnCase); srnCase.ID = Fun.GetSeqID <EM_SCRIPT_REF_NODE_FORCASE>();//避免ID重复 srnCase.SCRIPT_CASE_ID = scriptCaseID; db.EM_SCRIPT_REF_NODE_FORCASE.Add(srnCase); } #endregion #region 逐个复制连接线信息 var lineList = db.EM_CONNECT_LINE.Where(p => p.SCRIPT_ID == scriptID).ToList(); if (lineList != null && lineList.Count > 0) { foreach (var line in lineList) { EM_CONNECT_LINE_FORCASE lineForcase = new EM_CONNECT_LINE_FORCASE(); Fun.ClassToCopy(line, lineForcase); lineForcase.ID = Fun.GetSeqID <EM_CONNECT_LINE_FORCASE>(); lineForcase.SCRIPT_CASE_ID = scriptCaseID; db.EM_CONNECT_LINE_FORCASE.Add(lineForcase); } } #endregion #region 逐个复制脚本节点内容 var nodeIDList = srnList.Select(p => p.CURR_NODE_ID).Distinct(); foreach (var nid in nodeIDList) { var node = db.EM_SCRIPT_NODE.Find(nid); EM_SCRIPT_NODE_FORCASE snforc = new EM_SCRIPT_NODE_FORCASE(); Fun.ClassToCopy(node, snforc); snforc.ID = Fun.GetSeqID <EM_SCRIPT_NODE_FORCASE>();//避免ID重复 snforc.SCRIPT_NODE_ID = nid; snforc.SCRIPT_CASE_ID = scriptCaseID; db.EM_SCRIPT_NODE_FORCASE.Add(snforc); } #endregion #region 逐个复制节点位置信息 var positionList = db.EM_NODE_POSITION.Where(p => p.SCRIPT_ID == scriptID).ToList(); if (positionList != null && positionList.Count > 0) { foreach (var pos in positionList) { EM_NODE_POSITION_FORCASE posForcase = new EM_NODE_POSITION_FORCASE(); Fun.ClassToCopy(pos, posForcase); posForcase.ID = Fun.GetSeqID <EM_NODE_POSITION_FORCASE>(); posForcase.SCRIPT_CASE_ID = scriptCaseID; db.EM_NODE_POSITION_FORCASE.Add(posForcase); } } #endregion //try //{ // db.SaveChanges(); // return true; //} //catch (Exception e) //{ // err.IsError = false; // err.Message = e.Message; // err.Excep = e; // return false; //} }
public TUser UserAndLoginSave(object dbObject, string loginKey, ref ErrorInfo err, TUser inEnt, IList <string> allPar) { GlobalUser gu = Global.GetUser(loginKey); if (gu == null) { err.IsError = true; err.Message = "登录超时"; return(null); } DBEntities db = dbObject as DBEntities; if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(null); } #region 除参数里有ID的参数 var idPar = allPar.SingleOrDefault(x => x == "ID"); if (idPar != null) { allPar.Remove(idPar); } #endregion #region 判断登录名是否有效 if (string.IsNullOrEmpty(inEnt.LOGIN_NAME)) { err.IsError = true; err.Message = "登录名不能为空"; return(null); } if (db.fa_user.Count(x => x.LOGIN_NAME == inEnt.LOGIN_NAME && x.ID != inEnt.ID) > 0) { err.IsError = true; err.Message = "登录名已经存在,请重新选择"; return(null); } #endregion //用于修改登录名: var oldLoginName = inEnt.LOGIN_NAME; var userEnt = db.fa_user.SingleOrDefault(a => a.ID == inEnt.ID); #region 修改&&添加user bool isAdd = false; if (userEnt == null) { isAdd = true; userEnt = Mapper.Map <fa_user>(inEnt); if (userEnt.ID == 0) { userEnt.ID = Fun.GetSeqID <fa_user>(); } var dis = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID); if (dis != null) { userEnt.REGION = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID).REGION; } } else { oldLoginName = userEnt.LOGIN_NAME; userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt, userEnt, allPar); } #endregion #region 根据:RoleAllIDStr 修改用户角色 if (allPar.Contains("RoleAllIDStr") && !string.IsNullOrEmpty(inEnt.RoleAllIDStr)) { IList <int> allRoleId = new List <int>(); allRoleId = inEnt.RoleAllIDStr.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList(); userEnt.fa_role.Clear(); userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList(); } #endregion #region 根据:UserDistrict 修改用户管辖区域 if (allPar.Contains("UserDistrict") && !string.IsNullOrEmpty(inEnt.UserDistrict)) { userEnt.fa_district1.Clear(); var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList(); userEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList(); } #endregion var loginEnt = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == oldLoginName); #region 修改&&添加登录工号 if (loginEnt == null) { if (inEnt.Login == null) { inEnt.Login = new LOGIN() { LOGIN_NAME = inEnt.LOGIN_NAME, PASSWORD = AppSet.DefaultPwd.Md5() }; } loginEnt = Mapper.Map <fa_login>(inEnt.Login); loginEnt.ID = Fun.GetSeqID <fa_login>(); db.fa_login.Add(loginEnt); } else { loginEnt = Fun.ClassToCopy <TUser, fa_login>(inEnt, loginEnt, allPar); loginEnt.PHONE_NO = inEnt.LOGIN_NAME; } #endregion if (isAdd) { db.fa_user.Add(userEnt); } GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit); inEnt.ID = userEnt.ID; return(inEnt); }