Esempio n. 1
0
        public async Task <GetByEmailAccountDto?> Handle(
            GetByEmailAccountQuery request,
            CancellationToken token)
        {
            var accountDomain = await _accountQueries
                                .GetByEmail(
                request.CorrelationToken,
                request.Email,
                token);

            if (accountDomain == null)
            {
                return(null);
            }

            if (Equals(
                    accountDomain
                    .AccountStatus,
                    AccountStatusType.AddressVerificationRequired))
            {
                return(new GetByEmailAccountDto(
                           accountDomain.Id,
                           (AccountStatusEnum)accountDomain.Id,
                           accountDomain.Email,
                           null));
            }

            var address = await _addressQueries
                          .GetByProvinceId(
                request.CorrelationToken,
                accountDomain.ProvinceId,
                token);

            if (address == null)
            {
                throw new AppException(
                          "An error has occurred. " +
                          "We are working on a solution to it. " +
                          "You can find out the status by ticket: " +
                          $"{request.CorrelationToken}");
            }

            return(new GetByEmailAccountDto(
                       accountDomain.Id,
                       (AccountStatusEnum)accountDomain.Id,
                       accountDomain.Email,
                       new GetByEmailAccountAddressDto(
                           address.CountryId,
                           address.CountryTitle,
                           address.ProvinceId,
                           address.ProvinceTitle)));
        }