Ejemplo n.º 1
0
        public UserSmsVerification ResendVerificationRequest(int userId, UserVerificationReason reason)
        {
            if (userId == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(userId), "must not be null");
            }

            if (reason == null)
            {
                throw new ArgumentOutOfRangeException(nameof(reason), "must not be null");
            }

            IQueryConstraints <UserSmsVerification> constraints = new QueryConstraints <UserSmsVerification>()
                                                                  .Where(v => v.UserId == userId)
                                                                  .AndAlso(v => v.UserVerificationReasonId == reason.UserVerificationReasonId);

            UserSmsVerification verificationRequest = queryRepository.Find(constraints).Items.OrderBy(v => v.CreatedAt).LastOrDefault();

            if (verificationRequest == null)
            {
                throw new BusinessRuleException(nameof(UserSmsVerification), "");
            }

            verificationRequest.RenewIfNecessary();
            verificationRequest.IncrementResendCount();

            //Send the verification code to the user by SMS
            IQueryConstraints <User> userConstraints = new QueryConstraints <User>()
                                                       .Where(u => u.Id == userId);
            User user = queryRepository.Single(userConstraints);

            SendSms(verificationRequest.Code, user.Mobile);

            return(repository.Update(verificationRequest));
        }
Ejemplo n.º 2
0
        public UserSmsVerification ResendVerificationRequest(string mobile, Guid smsRefId)
        {
            IQueryConstraints <UserSmsVerification> constraints = new QueryConstraints <UserSmsVerification>()
                                                                  .Where(v => v.SMSRefId == smsRefId);

            UserSmsVerification verificationRequest = queryRepository.Find(constraints).Items.OrderBy(v => v.CreatedAt).LastOrDefault();

            if (verificationRequest == null)
            {
                throw new BusinessRuleException(nameof(UserSmsVerification), "");
            }

            verificationRequest.RenewIfNecessary();
            verificationRequest.IncrementResendCount();

            SendSms(verificationRequest.Code, mobile);

            return(repository.Update(verificationRequest));
        }