public void ChangeEmail(string codeValue)
        {
            if (_emailConfirmationService.TryAcceptConfirmation(codeValue))
            {
                var user          = _confirmationCodeService.GetRelatedUser(codeValue);
                var newEmailValue = _confirmationCodeService.GetCodeByValue(codeValue).Email.Value;

                user.ChangeEmailTo(newEmailValue);

                _confirmationCodeService.DeactivateCode(codeValue);
            }

            else
            {
                throw new CodeIsNotValidException(codeValue);
            }
        }
        public bool TryAcceptConfirmation(string codeValue)
        {
            try
            {
                _confirmationCodeService.ValidateCode(codeValue);
            }
            catch (Exception ex)
                when(ex is CodeIsNotActiveException || ex is CodeIsNotExistException || ex is CodeIsNotValidException)
                {
                    return(false);
                }
            var user       = _confirmationCodeService.GetRelatedUser(codeValue);
            var emailValue = _confirmationCodeService.GetCodeByValue(codeValue).Email.Value;

            user.Emails.Find(e => e.Value == emailValue).IsConfirmed = true;

            _confirmationCodeService.DeactivateCode(codeValue);

            return(true);
        }
        public string ChangeEmail(string codeValue)
        {
            string newEmailValue;

            if (_emailConfirmationService.TryAcceptConfirmation(codeValue, ConfirmationCodeType.EmailChangeConfirmation))
            {
                var user = _confirmationCodeService.GetRelatedUser(codeValue);
                newEmailValue = _confirmationCodeService.GetCodeByValue(codeValue).Email.Value;

                user.ChangeEmailTo(newEmailValue);

                _confirmationCodeService.DeactivateCode(codeValue);
            }

            else
            {
                throw new CodeIsNotValidException(codeValue);
            }

            return(newEmailValue);
        }