Beispiel #1
0
        /// <summary>
        /// 创建用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public User CreateUserInfo(SvrModels.SvrUserInfo user)
        {
            var checkModel = QWF.Framework.Validation.ValidationHelper.Validate(user);

            if (!checkModel.IsValid)
            {
                throw new UIValidateException("数据验证失败!" + checkModel.ToString());
            }

            if (user.UserName.Length < 3)
            {
                throw new UIValidateException("账号长度至少3位");
            }

            if (user.PassWord.StrValidatorHelper().StrIsNullOrEmpty())
            {
                throw new UIValidateException("密码不能空");
            }


            //逻辑验证
            var userNameCount = DbContext.T_QWF_User.Where(w => w.UserName == user.UserName && w.IsDelete == 0).Count();

            if (userNameCount > 0)
            {
                throw new GlobalException.UIValidateException(string.Format("用户【{0}】已经存在,不能添加!", user.UserName));
            }

            //用户CODE 规则
            if (user.UserCode.StrValidatorHelper().StrIsNullOrEmpty())
            {
                var common = new SeqServices(this.SvrUser);
                user.UserCode = common.CreateNewSeqNo("system.userCode");
            }
            //验证用户CODE
            var userCodeCount = DbContext.T_QWF_User.Where(w => w.UserCode == user.UserCode && w.IsDelete == 0).Count();

            if (userCodeCount > 0)
            {
                throw new UIValidateException(string.Format("用户CODE:【{0}】已经存在,不能添加!", user.UserCode));
            }


            var dbUser = new DbAccess.T_QWF_User();

            dbUser.UserCode    = user.UserCode;
            dbUser.UserName    = user.UserName;
            dbUser.PassWord    = user.PassWord;
            dbUser.OrgId       = user.OrgId;
            dbUser.Leader      = user.Leader?1:0;
            dbUser.UserStatus  = (int)SvrModels.SvrUserInfo.UserStatusEnum.正常;
            dbUser.IsDelete    = 0;
            dbUser.QQ          = user.Realname;
            dbUser.Realname    = user.Realname;
            dbUser.Tel         = user.Tel;
            dbUser.Phone       = user.Phone;
            dbUser.Email       = user.Email;
            dbUser.Position    = user.Position;
            dbUser.Weixin      = user.Weixin;
            dbUser.Fax         = user.Fax;
            dbUser.UserRemarks = user.UserRemarks;

            dbUser.CreateUserId = SvrUser.UserId;
            dbUser.CreateTime   = SvrUser.CurrentTime;

            this.DbContext.T_QWF_User.Add(dbUser);

            return(new User(dbUser, DbContext, this));
        }
Beispiel #2
0
 public User(DbAccess.T_QWF_User dbModel, DbAccess.DbFrameworkContext db, UserHelper helper)
 {
     //初始化数据
     this.helper  = helper;
     this.dbModel = dbModel;
 }