public async Task <AccountRegisterDto?> Handle( AccountRegisterCommand request, CancellationToken token) { if (await _accountQueries .IsExistByEmail( request.CorrelationToken, request.Email, token)) { throw new AppException( $"Account on the mail {request.Email} is already registered"); } var address = await _addressQueries .GetByProvinceId( request.CorrelationToken, request.ProvinceId, token); if (address == null) { throw new AppException( $"Province with id {request.ProvinceId} not exist"); } var accountDomain = await _accountCommand .Register( request.CorrelationToken, new AccountDomain( request.CorrelationToken, request.Agree, request.Email, request.Password, request.ProvinceId), token); if (accountDomain == null) { return(null); } await _accountCommand .UnitOfWork .SaveEntitiesAsync(token); return(new AccountRegisterDto( accountDomain.Id, (AccountStatusEnum)accountDomain.AccountStatus.Id, accountDomain.Email, new AccountRegisterAddressDto( address.CountryId, address.CountryTitle, address.ProvinceId, address.ProvinceTitle))); }
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))); }
public async Task <GetByProvinceIdAddressDto?> Handle( GetByProvinceIdAddressQuery request, CancellationToken token) { var provinceDomain = await _addressQueries .GetByProvinceId( request.CorrelationToken, request.ProvinceId, token); return(provinceDomain == null ? null : new GetByProvinceIdAddressDto( provinceDomain.CountryId, provinceDomain.Country.Title, provinceDomain.Id, provinceDomain.Title)); }