Пример #1
0
        public async Task <IActionResult> Get([FromRoute] Guid customerId)
        {
            var customer = await customersService.GetCustomerByIdAsync(customerId);

            if (customer == null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <CustomerResponse>(customer)));
        }
Пример #2
0
        /// <summary>
        /// Search Async
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        /// "https://www.c-sharpcorner.com/article/microservice-using-asp-net-core/"
        public async Task <(bool IsSuccess, dynamic SearchResults)> SearchAsync(int customerId)
        {
            // Customer Service
            var customersResult = await _customersService.GetCustomerByIdAsync(customerId);

            // Order Service
            var ordersResult = await _ordersService.GetOrdersByCustomerIdAsync(customerId);

            // Product Service
            var productsResult = await _productsService.GetProductsAsync();

            // Validate Order result
            if (ordersResult.IsSuccess)
            {
                //Product ID and Product Name will be included in Order List
                foreach (var orders in ordersResult.Orders)
                {
                    //Items is a an Order Item List
                    foreach (var item in orders.Items)
                    {
                        item.ProductName = productsResult.IsSuccess
                            ? productsResult.Products.FirstOrDefault(p => p.Id == item.ProductId)?.ProductName
                            : "Product information is not available";
                    }
                }

                var result = new
                {
                    Customer = customersResult.IsSuccess
                               ? customersResult.Customer
                               : new { Name = "Customer information is not available" }
                    , Orders = ordersResult.Orders
                };

                return(true, result);
            }
            return(false, null);
        }
Пример #3
0
        public async Task <CustomerModel> GetAsync(int customerId)
        {
            var customer = await _customersService.GetCustomerByIdAsync(customerId);

            return(customer);
        }