Esempio n. 1
0
 public HttpResponseMessage Post([FromBody] UserModel model)
 {
     try
     {
         var user = _iUserServices.GetUserByInfo(model.email);
         if (user != null)
         {
             return(ResponseHelper.ErrorResult(Request, HttpStatusCode.BadRequest,
                                               ErrorMessages.ERROR_MSG_EMAIL_IS_ALREADY_EXISTED, ErrorCodeStrings.EMAIL_IS_ALREADY_EXISTED,
                                               null));
         }
         user = _iUserServices.GetUserByInfo(model.phone);
         if (user != null)
         {
             return(ResponseHelper.ErrorResult(Request, HttpStatusCode.BadRequest,
                                               ErrorMessages.ERROR_MSG_PHONE_IS_ALREADY_EXISTED, ErrorCodeStrings.PHONE_IS_ALREADY_EXISTED,
                                               null));
         }
         var userEntity = Mapper.Map <UserModel, UserEntity>(model);
         userEntity = _iUserServices.CreateUser(userEntity);
         var userAuthInfoEntity = new UserAuthInfoEntity()
         {
             userId       = userEntity.id,
             passwordHash = model.passwordHash
         };
         userAuthInfoEntity = _iUserAuthInfoServices.CreateUserAuthInfo(userAuthInfoEntity);
         return(Request.CreateResponse(HttpStatusCode.OK, new { userEntity, userAuthInfoEntity }));
     }
     catch (Exception e)
     {
         return(ResponseHelper.ErrorResult(Request, HttpStatusCode.InternalServerError, ErrorMessages.ERROR_MSG_SERVER_ERROR, ErrorCodeStrings.SERVER_ERROR, e.ToString()));
     }
 }
 public UserAuthInfoEntity CreateUserAuthInfo(UserAuthInfoEntity userAuthInfoEntity)
 {
     if (userAuthInfoEntity == null)
     {
         return(null);
     }
     using (var scope = new TransactionScope())
     {
         var userAuthInfo = Mapper.Map <UserAuthInfoEntity, UserAuthInfo>(userAuthInfoEntity);
         _unitOfWork.UserAuthInfoRepository.Insert(userAuthInfo);
         _unitOfWork.Save();
         scope.Complete();
         userAuthInfoEntity.id = userAuthInfo.Id;
         return(userAuthInfoEntity);
     }
 }
        public UserAuthInfoEntity UpdateUserAuthInfoEntity(int id, UserAuthInfoEntity userAuthInfoEntity)
        {
            var userAuthInfo = _unitOfWork.UserAuthInfoRepository.GetById(id);

            if (userAuthInfo == null)
            {
                return(null);
            }
            userAuthInfo.PasswordHash = userAuthInfoEntity.passwordHash;
            userAuthInfo.UserId       = userAuthInfoEntity.userId;
            using (var scope = new TransactionScope())
            {
                _unitOfWork.UserAuthInfoRepository.Update(userAuthInfo);
                _unitOfWork.Save();
                scope.Complete();
                return(userAuthInfoEntity);
            }
        }