public static bool UpdateModel(int id, string dict_key, out string errMsg)
        {
            errMsg = string.Empty;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    if (!DictSystemList.Any(p => p.ID == id))
                    {
                        errMsg = "关键字不在字典表中";
                        return(false);
                    }

                    var dictSystemMode = DictSystemList.Where(p => p.ID == id).FirstOrDefault();
                    dictSystemMode.DictKey = dict_key;
                    if (!dict_SystemService.Update(Utils.GetCopy <Dict_System, DictSystemModel>(dictSystemMode)))
                    {
                        errMsg = "数据库更新失败";
                        return(false);
                    }

                    ts.Complete();
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        public object SetSub(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 == iId))
                {
                    errMsg = "选中节点数据库不存在";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                Dict_System dict_System = dict_SystemService.GetModels(p => p.ID == iId).FirstOrDefault <Dict_System>();
                if (dict_System.PID == null || !dict_SystemService.Any(p => p.ID == dict_System.PID))
                {
                    errMsg = "主节点不可修改";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int pId = Convert.ToInt32(dict_System.PID.Value);
                if (dict_SystemService.Any(p => p.ID != iId && p.PID.Value == pId && 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.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.Update(dict_System))
                {
                    errMsg = "修改子节点失败";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                return(ResponseModelFactory.CreateAnonymousSuccessModel(isSignKeyReturn, default(Dict_System)));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }