Example #1
0
        public async Task <IActionResult> GetCustomer([FromRoute][Required] GetCustomerDetailsRequest request)
        {
            var input = new GetCustomerDetailsInput(request.CustomerId);
            await _mediator.PublishAsync(input);

            return(_presenter.ViewModel);
        }
Example #2
0
        public async Task Execute(GetCustomerDetailsInput input)
        {
            ICustomer customer = await _customerRepository.Get(input.CustomerId);

            if (customer == null)
            {
                _outputHandler.NotFound($"The customer {input.CustomerId} does not exist or is not processed yet.");
                return;
            }

            List <Boundaries.GetCustomerDetails.Account> accounts = new List <Boundaries.GetCustomerDetails.Account>();

            foreach (Guid accountId in customer.Accounts.GetAccountIds())
            {
                IAccount account = await _accountRepository.Get(accountId);

                if (account != null)
                {
                    Boundaries.GetCustomerDetails.Account accountOutput = new Boundaries.GetCustomerDetails.Account(account);
                    accounts.Add(accountOutput);
                }
            }

            GetCustomerDetailsOutput output = new GetCustomerDetailsOutput(customer, accounts);

            _outputHandler.Default(output);
        }
        public async Task <IActionResult> GetCustomer()
        {
            var input = new GetCustomerDetailsInput();
            await _mediator.PublishAsync(input);

            return(_presenter.ViewModel);
        }
Example #4
0
        public async Task <IActionResult> GetCustomer([FromRoute][Required] GetCustomerDetailsRequest request)
        {
            var getCustomerDetailsInput = new GetCustomerDetailsInput(request.CustomerId);
            await _getCustomerDetailsUseCase.Execute(getCustomerDetailsInput);

            return(_presenter.ViewModel);
        }
Example #5
0
        public void GivenValidData_InputCreated()
        {
            var actual = new GetCustomerDetailsInput(
                Guid.NewGuid()
                );

            Assert.NotNull(actual);
        }
        public async Task <IActionResult> GetCustomer(Guid customerId)
        {
            var request = new GetCustomerDetailsInput(customerId);

            await this.getCustomerInput.Process(request);

            return(this.getCustomerDetailsPresenter.ViewModel);
        }
Example #7
0
        public async Task <IActionResult> GetCustomer(
            [FromServices] IMediator mediator,
            [FromServices] GetCustomerDetailsPresenter presenter)
        {
            var input = new GetCustomerDetailsInput();
            await mediator.PublishAsync(input);

            return(presenter.ViewModel);
        }
Example #8
0
        /// <summary>
        ///     Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(GetCustomerDetailsInput input)
        {
            if (input is null)
            {
                this._outputPort.WriteError(Messages.InputIsNull);
                return;
            }

            ICustomer customer;

            if (this._userService.GetCustomerId() is CustomerId customerId)
            {
                try
                {
                    customer = await this._customerRepository.GetBy(customerId)
                               .ConfigureAwait(false);
                }
                catch (CustomerNotFoundException ex)
                {
                    this._outputPort.NotFound(ex.Message);
                    return;
                }
            }
            else
            {
                this._outputPort.NotFound(Messages.CustomerDoesNotExist);
                return;
            }

            var accounts = new List <Account>();

            foreach (AccountId accountId in customer.Accounts.GetAccountIds())
            {
                IAccount account;

                try
                {
                    account = await this._accountRepository.GetAccount(accountId)
                              .ConfigureAwait(false);
                }
                catch (AccountNotFoundException ex)
                {
                    this._outputPort.NotFound(ex.Message);
                    return;
                }

                var outputAccount = new Account(account);
                accounts.Add(outputAccount);
            }

            this.BuildOutput(
                this._userService.GetExternalUserId(),
                customer,
                accounts);
        }
        /// <summary>
        /// Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(GetCustomerDetailsInput input)
        {
            ICustomer customer;

            if (this.userService.GetCustomerId() is CustomerId customerId)
            {
                try
                {
                    customer = await this.customerRepository.GetBy(customerId)
                               .ConfigureAwait(false);
                }
                catch (CustomerNotFoundException ex)
                {
                    this.outputPort.NotFound(ex.Message);
                    return;
                }
            }
            else
            {
                this.outputPort.NotFound("Customer does not exist.");
                return;
            }

            var accounts = new List <Boundaries.GetCustomerDetails.Account>();

            foreach (AccountId accountId in customer.Accounts.GetAccountIds())
            {
                IAccount account;

                try
                {
                    account = await this.accountRepository.GetAccount(accountId)
                              .ConfigureAwait(false);
                }
                catch (AccountNotFoundException ex)
                {
                    this.outputPort.NotFound(ex.Message);
                    return;
                }

                var outputAccount = new Boundaries.GetCustomerDetails.Account(account);
                accounts.Add(outputAccount);
            }

            this.BuildOutput(
                this.userService.GetExternalUserId(),
                customer,
                accounts);
        }
Example #10
0
        public async Task Execute(GetCustomerDetailsInput input)
        {
            var customer = await _customerRepository.Get(input.CustomerId);

            var accounts = new List <Boundaries.GetCustomerDetails.Account>();

            foreach (Guid accountId in customer.Accounts.GetAccountIds())
            {
                var account = await _accountRepository.Get(accountId);

                var outputAccount = new Boundaries.GetCustomerDetails.Account(account);
                accounts.Add(outputAccount);
            }

            BuildOutput(customer, accounts);
        }
Example #11
0
        public async Task Execute(GetCustomerDetailsInput input)
        {
            ICustomer customer;

            try
            {
                customer = await _customerRepository.Get(input.CustomerId);
            }
            catch (CustomerNotFoundException ex)
            {
                _outputPort.NotFound(ex.Message);
                return;
            }

            var accounts = new List <Boundaries.GetCustomerDetails.Account>();

            foreach (Guid accountId in customer.Accounts.GetAccountIds())
            {
                IAccount account;

                try
                {
                    account = await _accountRepository.Get(accountId);
                }
                catch (AccountNotFoundException ex)
                {
                    _outputPort.NotFound(ex.Message);
                    return;
                }

                var outputAccount = new Boundaries.GetCustomerDetails.Account(account);
                accounts.Add(outputAccount);
            }

            BuildOutput(customer, accounts);
        }