public static bool AddModel(string pdict_key, string dict_key, out string errMsg) { errMsg = string.Empty; //开启EF事务 using (TransactionScope ts = new TransactionScope()) { try { if (!DictSystemBusiness.IsEffectiveDict("客户等级")) { errMsg = "关键字类别不在字典表中"; return(false); } if (DictSystemBusiness.IsEffectiveDict("客户等级", dict_key)) { errMsg = "关键字已存在字典表中"; return(false); } var dictSystemList = DictSystemBusiness.GetDicts("客户等级"); var no = 0; var dictValue = dictSystemList.Max(p => p.DictValue); int.TryParse(dictValue, out no); no++; var dictSystemMode = new DictSystemModel(); dictSystemMode.DictKey = dict_key; dictSystemMode.PID = DictSystemBusiness.GetDictModel("客户等级").ID; dictSystemMode.DictValue = no.ToString(); var dict_System = Utils.GetCopy <Dict_System, DictSystemModel>(dictSystemMode); if (!dict_SystemService.Add(dict_System)) { errMsg = "数据库更新失败"; return(false); } dictSystemMode.ID = dict_System.ID; dictSystemMode.PDictKey = pdict_key; DictSystemList.Add(dictSystemMode); ts.Complete(); } catch (Exception ex) { errMsg = ex.Message; return(false); } } return(true); }
public object AddSub(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string id = dicParas.ContainsKey("id") ? dicParas["id"].ToString() : string.Empty; string dictKey = dicParas.ContainsKey("dictKey") ? dicParas["dictKey"].ToString() : string.Empty; string dictValue = dicParas.ContainsKey("dictValue") ? dicParas["dictValue"].ToString() : string.Empty; string comment = dicParas.ContainsKey("comment") ? dicParas["comment"].ToString() : string.Empty; string enabled = dicParas.ContainsKey("enabled") ? dicParas["enabled"].ToString() : string.Empty; string merchId = dicParas.ContainsKey("merchId") ? dicParas["merchId"].ToString() : string.Empty; XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel]; if (userTokenKeyModel.LogType == (int)RoleType.MerchUser) { merchId = userTokenKeyModel.DataModel.MerchID; } if (string.IsNullOrWhiteSpace(id)) { errMsg = "选中节点id不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } try { Convert.ToInt32(id); } catch (Exception ex) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message)); } //验证参数信息 if (!checkParams(dicParas, out errMsg)) { return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } IDict_SystemService dict_SystemService = BLLContainer.Resolve <IDict_SystemService>(); int iId = Convert.ToInt32(id); if (!dict_SystemService.Any(p => p.ID.Equals(iId))) { errMsg = "主节点id数据库不存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (dict_SystemService.Any(p => p.PID.Value.Equals(iId) && p.DictKey.Equals(dictKey, StringComparison.OrdinalIgnoreCase))) { errMsg = "同一级别下存在重名的节点"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrWhiteSpace(merchId)) { if (dict_SystemService.Any(p => p.DictKey.Equals(dictKey, StringComparison.OrdinalIgnoreCase) && (p.MerchID == null || p.MerchID.Trim() == string.Empty))) { errMsg = "不能与公有节点重名"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } Dict_System dict_System = new Dict_System(); dict_System.PID = iId; dict_System.DictKey = dictKey; dict_System.DictValue = dictValue; dict_System.Comment = comment; dict_System.Enabled = Convert.ToInt32(enabled); if (dicParas.ContainsKey("merchId")) { dict_System.MerchID = dicParas["merchId"].ToString(); } if (!dict_SystemService.Add(dict_System)) { errMsg = "添加子节点失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }