示例#1
0
 public DISTRICT DistrictSingle(string loginKey, ref ErrorInfo err, int id)
 {
     if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
     {
         return(null);
     }
     using (DBEntities db = new DBEntities())
     {
         var reEnt = db.fa_district.SingleOrDefault(x => x.ID == id);
         return(Mapper.Map <DISTRICT>(reEnt));
     }
 }
示例#2
0
        public TRole RoleSingle(string loginKey, ref ErrorInfo err, int id)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                var        reEnt   = db.fa_role.SingleOrDefault(x => x.ID == id);
                TRole      tmp     = new TRole();
                IList <KV> allPara = new List <KV>();

                if (reEnt != null)
                {
                    tmp = Mapper.Map <TRole>(reEnt);
                }
                return(tmp);
            }
        }
示例#3
0
 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));
     }
 }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
                }
            }
        }