Exemplo n.º 1
0
        public async Task <IActionResult> CheckIfTwoCustomersHasSameAddress(CustomerCheckSameAddressRequest request)
        {
            var response = new BaseResponse <CustomerCheckSameAddressResponse>();
            var data     = new CustomerCheckSameAddressResponse();

            try
            {
                if (request == null)
                {
                    throw new ArgumentNullException("missing body");
                }

                request.Validate();

                var custRepo  = new CustomerRepository();
                var customerA = custRepo.GetCustomerById(request.customerAId);
                var customerB = custRepo.GetCustomerById(request.customerBId);

                if (customerA == null)
                {
                    throw new CustomerNotFoundException($"{request.customerAId}");
                }

                if (customerB == null)
                {
                    throw new CustomerNotFoundException($"{request.customerBId}");
                }

                //consider using mapper such as automapper lib
                data.isSame            = customerA.IsLiveTogether(customerB);
                data.customerACity     = customerA.Address?.City;
                data.customerAStreet   = customerA.Address?.Street;
                data.customerABuilding = customerA.Address?.Building;
                data.customerBBuilding = customerB.Address?.City;
                data.customerBBuilding = customerB.Address?.Street;
                data.customerBBuilding = customerB.Address?.Building;

                response.SetData(data);
            }
            catch (Exception e)
            {
                response.SetError(e);
            }

            return(Ok(response));
        }
        public BaseResponse <CustomerCheckSameAddressResponse> CheckIfCustomerHasSameAddress(CustomerCheckSameAddressRequest request)
        {
            var response = new BaseResponse <CustomerCheckSameAddressResponse>();
            var data     = new CustomerCheckSameAddressResponse();

            var customerA = _customerDomainService.GetCustomerById(request.customerAId);
            var customerB = _customerDomainService.GetCustomerById(request.customerBId);

            data.isSame            = customerA.IsLiveTogether(customerB);
            data.customerACity     = customerA.Address.City;
            data.customerABuilding = customerA.Address.Building;
            data.customerAStreet   = customerA.Address.Street;
            data.customerBCity     = customerB.Address.City;
            data.customerBBuilding = customerB.Address.Building;
            data.customerBStreet   = customerB.Address.Street;

            response.SetData(data);

            return(response);
        }