public async Task <ActionResult> CheckUsername(string username)
        {
            return(await Task.Run(() =>
            {
                var userNameAvailability = _candidateServiceProvider.IsUsernameAvailable(username.Trim());

                return Json(userNameAvailability, JsonRequestBehavior.AllowGet);
            }));
        }
Пример #2
0
        public MediatorResponse <RegisterViewModel> Register(RegisterViewModel registerViewModel)
        {
            var emailAddress = string.IsNullOrWhiteSpace(registerViewModel.EmailAddress)
                ? string.Empty
                : registerViewModel.EmailAddress.Trim();

            UserNameAvailability userNameAvailable;

            if (string.IsNullOrWhiteSpace(emailAddress))
            {
                userNameAvailable = new UserNameAvailability
                {
                    HasError            = false,
                    IsUserNameAvailable = false
                };
            }
            else
            {
                userNameAvailable = _candidateServiceProvider.IsUsernameAvailable(emailAddress);
            }

            if (!userNameAvailable.HasError)
            {
                registerViewModel.IsUsernameAvailable = userNameAvailable.IsUserNameAvailable;
                var validationResult = _registerViewModelServerValidator.Validate(registerViewModel);

                if (!validationResult.IsValid)
                {
                    return(GetMediatorResponse(RegisterMediatorCodes.Register.ValidationFailed, registerViewModel, validationResult));
                }

                var registered = _candidateServiceProvider.Register(registerViewModel);
                if (registered)
                {
                    return(GetMediatorResponse(RegisterMediatorCodes.Register.SuccessfullyRegistered, registerViewModel));
                }
            }

            return(GetMediatorResponse(RegisterMediatorCodes.Register.RegistrationFailed, registerViewModel, RegisterPageMessages.RegistrationFailed, UserMessageLevel.Warning));
        }