Exemple #1
0
        /// <summary>
        /// 创建新的用户
        /// </summary>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public static SysManagerUser create(ViewModelUserRegisterRequest condtion)
        {
            SysValidata.valiData(condtion);
            int c = getLoginNameCount(condtion.loginname);

            if (c > 0)
            {
                throw new SysException("登录名已存在", condtion);
            }
            using (var db = new SysModelContainer()) {
                Db_ManagerUser dbuser = new Db_ManagerUser()
                {
                    createdOn   = DateTime.Now,
                    fullName    = condtion.fullName,
                    isDeleted   = false,
                    isDisabled  = false,
                    jobTitle    = condtion.jobTitle,
                    loginName   = condtion.loginname,
                    mobilePhone = condtion.mobilePhone,
                    passWord    = defaultPwd,
                    role        = condtion.role
                };
                db.Db_SysUserSet.Add(dbuser);
                db.SaveChanges();
            }
            SysManagerUser newuser = new SysManagerUser(condtion.loginname);

            SysUserLog.saveLog(condtion, SysUserLogType.编辑, newuser.loginName);
            return(newuser);
        }
Exemple #2
0
        /// <summary>
        /// 验证登陆
        /// </summary>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public static SysManagerUser checkLogin(ViewModelLoginReqeust condtion)
        {
            SysValidata.valiData(condtion);
            using (var db = new SysModelContainer()) {
                //如果还没有用户则需要初始化一个第一个管理员
                int c = (from x in db.Db_SysUserSet.OfType <Db_ManagerUser>() select x.loginName).Count();
                if (c == 0)
                {
                    create(new ViewModelUserRegisterRequest()
                    {
                        fullName  = "管理员",
                        loginname = "admin",
                        role      = "admin"
                    });
                }

                var d = db.Db_SysUserSet.OfType <Db_ManagerUser>().SingleOrDefault(p => p.loginName.Equals(condtion.loginName) && p.passWord.ToLower().Equals(condtion.pwd.ToLower()) && !p.isDeleted && !p.isDisabled);
                if (d == null)
                {
                    throw new SysException("用户名或密码不正确", condtion);
                }
                d.lastLoginTime = DateTime.Now;
                db.SaveChanges();
                SysManagerUser user = new SysManagerUser(condtion.loginName);
                SysUserLog.saveLoginLog(user.loginName);
                return(user);
            }
        }
Exemple #3
0
 /// <summary>
 /// 修改后台用户的信息
 /// </summary>
 /// <param name="condtion"></param>
 public SysManagerUser saveInfo(ViewModelUserEditReqeust condtion)
 {
     SysValidata.valiData(condtion);
     using (var db = new SysModelContainer()) {
         var d = db.Db_SysUserSet.OfType <Db_ManagerUser>().Single(p => p.loginName.Equals(this.loginName));
         d.fullName    = condtion.fullName;
         d.jobTitle    = condtion.jobTitle;
         d.mobilePhone = condtion.mobilePhone;
         d.role        = condtion.role;
         db.SaveChanges();
     }
     SysUserLog.saveLog(condtion, SysUserLogType.编辑, this.loginName);
     getInfo(this.loginName);
     return(this);
 }
Exemple #4
0
 /// <summary>
 /// 设置一个新密码
 /// </summary>
 public void reSetNewPwd(ViewModelChangePwdRequest condtion)
 {
     SysValidata.valiData(condtion);
     using (var db = new SysModelContainer()) {
         var d = db.Db_SysUserSet.Single(p => p.loginName.Equals(this.loginName));
         if (d.passWord.ToLower().Equals(condtion.oldPwd.ToLower()))
         {
             changePwd(condtion.newPwd);
             SysUserLog.saveLog("用户设置了新的密码", SysUserLogType.编辑);
         }
         else
         {
             throw new SysException("旧密码不正确", condtion);
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// 创建/编辑
        /// </summary>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public static SysCatTree edit(VMTreeEditCatTreeRequest condtion)
        {
            SysValidata.valiData(condtion);//验证请求

            //自定义验证当添加根节点时 参数中的 fun必填
            if (string.IsNullOrEmpty(condtion._parentId) && string.IsNullOrEmpty(condtion.fun))
            {
                throw new SysException("添加/编辑根节点时,参数fun必填", condtion);
            }

            if (string.IsNullOrEmpty(condtion.Id))
            {
                //新增
                using (var db = new SysModelContainer())
                {
                    Db_CatTree d = new Db_CatTree()
                    {
                        fun       = condtion.fun,
                        createdOn = DateTime.Now,
                        Id        = SysHelp.getNewId(),
                        name      = condtion.name,
                        parentId  = condtion._parentId,
                        isDeleted = false,
                        sort      = condtion.sort
                    };
                    Db_SysTree newrow = db.Db_SysTreeSet.Add(d);
                    db.SaveChanges();
                    SysCatTree newtree = new SysCatTree(newrow.Id);
                    return(newtree);
                }
            }
            else
            {
                //编辑
                SysCatTree tree = new SysCatTree(condtion.Id, false);
                tree.name      = condtion.name;
                tree._parentId = condtion._parentId;
                tree.fun       = condtion.fun;
                tree.sort      = condtion.sort;
                tree.save();
                tree = new SysCatTree(condtion.Id, false);
                return(tree);
            }
        }