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);
        }
예제 #2
0
        public static string GetUserLvl(int?id)
        {
            var userInfo = GetUser(id);

            return(userInfo != null?DictSystemBusiness.GetDictKey("客户等级", userInfo.UserLvl + "") : string.Empty);
        }