Exemple #1
0
        /// <summary>
        /// 更新用户数据
        /// </summary>
        /// <param name="svrUserInfo"></param>
        /// <returns></returns>
        public int UpdateUser(SvrUserInfo svrUserInfo)
        {
            if (svrUserInfo.OrgId == 0)
            {
                throw new QWF.Framework.GlobalException.UIValidateException("机构ID为NULL");
            }

            //开始
            using (var db = DbAccess.DbFrameworkContext.Create())
            {
                var userHelper = new BLL.UserHelper(db, this.svrUser);

                BLL.User user = userHelper.GetUserInfoById(svrUserInfo.UserId);
                if (user == null)
                {
                    throw new QWF.Framework.GlobalException.UIValidateException(string.Format("用户ID=【{0}】不存在!", svrUserInfo.UserId));
                }


                //密码不为空则修改密码
                if (!svrUserInfo.PassWord.StrValidatorHelper().StrIsNullOrEmpty())
                {
                    user.DbModel.PassWord = svrUserInfo.PassWord;
                }

                if (!svrUserInfo.UserCode.StrValidatorHelper().StrIsNullOrEmpty())
                {
                    user.DbModel.UserCode = svrUserInfo.UserCode;
                }

                //必要字段

                user.DbModel.OrgId       = svrUserInfo.OrgId;
                user.DbModel.Leader      = svrUserInfo.Leader ? 1 : 0;
                user.DbModel.QQ          = svrUserInfo.Realname;
                user.DbModel.Realname    = svrUserInfo.Realname;
                user.DbModel.Tel         = svrUserInfo.Tel;
                user.DbModel.Phone       = svrUserInfo.Phone;
                user.DbModel.Email       = svrUserInfo.Email;
                user.DbModel.Position    = svrUserInfo.Position;
                user.DbModel.Weixin      = svrUserInfo.Weixin;
                user.DbModel.Fax         = svrUserInfo.Fax;
                user.DbModel.UserRemarks = svrUserInfo.UserRemarks;

                if (svrUserInfo.UserStatus == SvrUserInfo.UserStatusEnum.正常 || svrUserInfo.UserStatus == SvrUserInfo.UserStatusEnum.禁用)
                {
                    user.DbModel.UserStatus = (int)svrUserInfo.UserStatus;
                }

                //修改者
                user.DbModel.UpdateUserId = this.svrUser.UserId;
                user.DbModel.UpdateTime   = DateTime.Now;
                //保存修改
                db.SaveChanges();

                return(user.GetNewUserId());
            }
        }
        /// <summary>
        /// /
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="userName"></param>
        /// <param name="passWord">由客户端决定加密的方式</param>
        /// <returns></returns>
        public bool CheckUserLogin(string appId, string userName, string passWord)
        {
            if (userName.StrValidatorHelper().StrIsNullOrEmpty())
            {
                throw new Framework.GlobalException.UIValidateException("用户名不能为空");
            }
            if (passWord.StrValidatorHelper().StrIsNullOrEmpty())
            {
                throw new Framework.GlobalException.UIValidateException("密码不能为空");
            }

            using (var qwfContext = DbAccess.DbFrameworkContext.Create())
            {
                var                 ip          = QWF.Framework.Web.QWFRequest.GetIP();
                BLL.UserHelper      users       = new BLL.UserHelper(qwfContext, svrUserIdentifier);
                BLL.UserLoginHelper loginHelper = new BLL.UserLoginHelper(qwfContext, svrUserIdentifier);

                var log = new SvrModels.SvrLoginLog();
                log.AppId    = appId;
                log.Ip       = ip;
                log.UserName = userName;
                try
                {
                    BLL.User user = users.GetUserInfo(userName);

                    if (user.GetPassword() != passWord)
                    {
                        log.Remarks = userName + "的密码错误!";
                        throw new UserValidateException(log.Remarks);
                    }

                    user.UpdateLoginLog(ip);
                    user.SetUserTokenCookie(appId);

                    //保存所有修改
                    log.LoginStatus = SvrModels.SvrLoginLoginStauts.Success;
                    loginHelper.Add(log);

                    qwfContext.SaveChanges();
                }
                catch (UserValidateException uex)
                {
                    //写入登录日志
                    log.LoginStatus = SvrModels.SvrLoginLoginStauts.Error;
                    log.Remarks     = uex.Message;

                    loginHelper.Add(log);
                    qwfContext.SaveChanges();

                    throw uex;
                }
                return(true);
            }
        }
Exemple #3
0
        /// <summary>
        /// 创建用户接口
        /// </summary>
        /// <param name="svrUserInfo"></param>
        /// <returns></returns>
        public int CreateUser(SvrUserInfo svrUserInfo)
        {
            //开始
            using (var db = DbAccess.DbFrameworkContext.Create())
            {
                var      userHelper = new BLL.UserHelper(db, this.svrUser);
                BLL.User user       = userHelper.CreateUserInfo(svrUserInfo);
                //保存修改
                db.SaveChanges();

                return(user.GetNewUserId());
            }
        }