public UserInfoViewModel AddUserInfo(UserInfoModel userInfoModel)
 {
     lock (userObject)
     {
         var userInfoEntity = _mapper.Map <UserInfoEntity>(userInfoModel);
         var userInfo       = _con.GetEntities <UserInfoEntity>().Where(p => p.Valid == 1 && p.TelPhone == userInfoModel.TelPhone).QueryFirst <UserInfoEntity>();
         //判断电话号码是否被注册
         if (userInfo != null)
         {
             throw new CNException("电话号码已被注册");
         }
         UserInfoEntity entity = null;
         //将用户数据存到数据库中
         using (var transa = _con.BeginTransaction())
         {
             try
             {
                 int    codeName = (int)CodeName.用户编码;
                 string userCode = _generateCode.GetCode(codeName, transa);
                 userInfoEntity.UserCode = userCode;
                 entity = _con.AddRecord(userInfoEntity, transa);
                 UserPsdEntity userPsdEntity = new UserPsdEntity
                 {
                     PassWord = userInfoModel.PassWord,
                     UserId   = entity.Id
                 };
                 _con.AddRecord(userPsdEntity, transa);
                 transa.Commit();
             }
             catch (Exception e)
             {
                 transa.Rollback();
                 throw e;
             }
         }
         //将用户的信息、产生的Token存到Redis中
         using (var redisManager = _redisManagerPool.GetClient())
         {
             redisManager.Db = (int)RedisDB.DB0;
             var currentUser = _mapper.Map <CurrentUser>(entity);
             currentUser.Token = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(Guid.NewGuid().ToString()));
             //存取用户编码(key:token value:用户编码)
             redisManager.Set <string>(currentUser.Token, currentUser.UserCode, DateTime.Now.AddMinutes(15));
             //存取用户信息(key:用户编码 value:用户信息)
             redisManager.Set <CurrentUser>(currentUser.UserCode, currentUser, DateTime.Now.AddMinutes(15));
             return(_mapper.Map <UserInfoViewModel>(currentUser));
         }
     }
 }
Пример #2
0
        public bool AddSystemCommment(CommentModel commentModel)
        {
            var entity = _mapper.Map <SystemCommentEntity>(commentModel);

            entity.UserId = _currentUser.Id;
            _con.AddRecord(entity);
            return(true);
        }
        /// <summary>
        /// 判断回答该问题是否已存在
        /// </summary>
        /// <param name="answerModel"></param>
        private void JudgeFundAnswer(FundAnswerModel answerModel)
        {
            var fundAnswerEntity = _con.GetEntities <FundAnswerEntity>().Where(p => p.AnswerContent == answerModel.AnswerContent).QueryFirst <FundAnswerEntity>();

            if (fundAnswerEntity != null)
            {
                fundAnswerEntity.AnswerNumber += 1;
                _con.UpdateReord(fundAnswerEntity);
            }
            else
            {
                var answerEntity = _mapper.Map <FundAnswerEntity>(answerModel);
                _con.AddRecord(answerEntity);
            }
        }