public async Task <ServiceUserResponse> GetServiceUserInformation(int hackneyId)
        {
            var serviceUserCount = await _serviceUserGateway.GetServiceUserCountAsync(hackneyId);

            if (serviceUserCount is 0)
            {
                var serviceUserResponse = await _residentsService.GetServiceUserInformationAsync(hackneyId);

                if (serviceUserResponse is null)
                {
                    throw new ApiException($"service user with hackney Id : {hackneyId} not found");
                }

                foreach (var item in serviceUserResponse.Residents)
                {
                    var newServiceUserDomain = new ServiceUserDomain()
                    {
                        HackneyId    = hackneyId,
                        FirstName    = item.FirstName,
                        LastName     = item.LastName,
                        DateOfBirth  = item.DateOfBirth,
                        AddressLine1 = item.Address?.Address,
                        PostCode     = item.Address?.Postcode
                    };

                    await _serviceUserGateway.CreateAsync(newServiceUserDomain.ToEntity());
                }
            }

            var serviceUserDomain = await _serviceUserGateway.GetAsync(hackneyId)
                                    .EnsureExistsAsync($"service user with hackney Id : {hackneyId} not found");

            return(serviceUserDomain.ToResponse());
        }
Ejemplo n.º 2
0
        public async Task <ServiceUserDomain> ExecuteAsync(ServiceUserDomain serviceUser)
        {
            var clientEntity = serviceUser.ToEntity();

            clientEntity = await _gateway.UpsertAsync(clientEntity).ConfigureAwait(false);

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

            serviceUser = clientEntity.ToDomain();

            return(serviceUser);
        }