Пример #1
0
        /// <summary>
        ///   Start registration by phone number.
        /// </summary>
        /// <param name="registrationModel">Model of registration user.</param>
        /// <returns>
        ///    Not validated user registration profile.
        /// </returns>
        /// <exception cref="System.ArgumentException">When one of params invalid.</exception>
        /// <exception cref="System.InvalidOperationException">When the user is registered.</exception>

        public async Task <User> StartRegistration(RegistrationModel registrationModel)
        {
            registrationModel.CheckArgumentException();

            var containsUser = GetUserByTelephoneNumber(registrationModel.TelephoneNumber);

            if (containsUser == null)
            {
                return(await _userRepository.AddAsync(new User
                {
                    TelephoneNumber = registrationModel.TelephoneNumber
                }));
            }

            var passwordOfUser = GetUserPasswordByUserId(containsUser.Id) == null
                ? new UserPassword()
                : throw new InvalidOperationException();

            var userEntity = await _userRepository.EditAsync(new User()
            {
                Id = containsUser.Id,
                TelephoneNumber = containsUser.TelephoneNumber
            });

            SmsService.Send(userEntity.TelephoneNumber);

            return(userEntity);
        }
Пример #2
0
        /// <summary>
        ///   Get validation code to phone number.
        /// </summary>
        /// <param name="registrationModel">Registration model.</param>
        /// <returns>
        ///    True or exception.
        /// </returns>
        /// <exception cref="System.ArgumentException">When one of params invalid.</exception>
        /// <exception cref="System.ArgumentNullException">When user not found.</exception>

        public bool GetValidationCode(RegistrationModel registrationModel)
        {
            registrationModel.CheckArgumentException();

            SmsService.Send(registrationModel.TelephoneNumber);

            return(true);
        }