public async Task <(bool IsSuccess, dynamic SearchResults)> SearchAsync(int customerId) { var ordersResult = await _ordersService.GetOrdersAsync(customerId); var productsResult = await _productsService.GetProductsAsync(); var customersResult = await _customersService.GetCustomerAsync(customerId); if (ordersResult.IsSuccess) { foreach (var order in ordersResult.Orders) { foreach (var item in order.Items) { item.ProductName = productsResult.IsSuccess ? productsResult.Products.FirstOrDefault(p => p.Id == item.ProductId)?.Name : "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); }
public async Task <(bool IsSuccess, dynamic SearchResults)> SearchAsync(int CustomerId) { //await Task.Delay(1); //return (true, new {Message = "Hello"}); var ordersResult = await _ordersService.GetOrdersAsync(CustomerId); var productResult = await _productsService.GetProductsAsync(); var customerResult = await _customersService.GetCustomerAsync(CustomerId); if (ordersResult.IsSuccess) { foreach (var order in ordersResult.Orders) { foreach (var item in order.Items) { item.ProductName = productResult.IsSuccess ? productResult.Products.FirstOrDefault(p => p.Id == item.ProductId)?.Name : "Looks like Product Microservice is down"; } } var result = new { Customer = customerResult.IsSuccess? customerResult.Customer : new { Name = "Customer Microservice is down at the moment" }, Orders = ordersResult.Orders }; return(true, result); } return(false, null); }
public async Task <(bool IsSuccess, dynamic SearchResults)> SearchAsync(int customerId) { var ordersResult = await ordersService.GetOrdersAsync(customerId); var productsResult = await productsService.GetproductsAsync(); var customersResult = await customersService.GetCustomerAsync(customerId); if (ordersResult.IsSuccess) { foreach (var orders in ordersResult.Orders) { foreach (var item in orders.Items) { item.ProductName = productsResult.IsSuccess? // search only if we have some results otherwise send: product not available! productsResult.Products.FirstOrDefault(p => p.Id == item.ProductId)?.Name : "Product info is not available!"; // extract only the name of product } } var result = new { Customer = customersResult.IsSuccess ? customersResult.Customer : new { Name = "Customer info not available!" }, Orders = ordersResult.Orders }; return(true, result); } // for testing: // await Task.Delay(1); // return (true, new { Message = "Hello"}); return(false, null); }
public async Task <(bool IsSuccess, dynamic SearchResults)> SearchAsync(int customerId) { // comment for testing var productsResult = await _productsService.GetProductsAsync(); var customersResult = await _customersService.GetCustomerAsync(customerId); var ordersResult = await _orderService.GetOrdersAsync(customerId); if (ordersResult.IsSuccess) { foreach (var order in ordersResult.orders) { foreach (var item in order.Items) { item.ProductName = productsResult.IsSuccess ? productsResult.products.Where(p => p.Id == item.ProductId).FirstOrDefault()?.Name: "Product information is not available"; } } var result = new { Customer = customersResult.IsSuccess ? customersResult.customer : new Models.Customer { Id = -1, Name = "Customer information is not available", Address = "Customer information is not available" }, Orders = ordersResult.orders, }; return(true, result); } return(false, null); }
public async Task <(bool IsSuccess, dynamic SearchResult)> SearchAsync(int CustomerId) { var result = await ordesrService.GetOrdersAsync(CustomerId); var Products = await productsService.GetProductsAsync(); var customers = await customersService.GetCustomerAsync(CustomerId); foreach (var order in result.Orders) { order.CustomerName = customers.Customer.Name; order.CustomerAddress = customers.Customer.Address; foreach (var orderItem in order.Items) { orderItem.ProductName = Products.IsSuccess? Products.Products.FirstOrDefault(a => a.Id == orderItem.ProductId)?.Name:"Product Name os not Available"; } } if (result.IsScuccess) { return(true, result.Orders); } else { return(false, null); } }
SearchAsync(int customerId) { var ordersResult = await ordersService.GetOrdersAsync(customerId); var productResult = await productService.GetProductsAsync(); var customerResult = await customersService.GetCustomerAsync(customerId); if (ordersResult.IsSuccess) { foreach (var order in ordersResult.Orders) { foreach (var item in order.Items) { item.ProductName = productResult.IsSuccess ? productResult.products.FirstOrDefault(p => p.Id == item.ProductId)?.Name : "Product information is not available"; } } var result = new { Orders = ordersResult.Orders, Customer = customerResult.IsSuccess ? customerResult.Customer : new { Name = "Customer Information not available" } //Products = productResult.products }; return(true, result); } return(false, null); }
// GET: Customers/Details/5 public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(NotFound()); } var customer = await _customersService.GetCustomerAsync((Guid)id); if (customer == null) { return(NotFound()); } return(View(customer)); }
public async Task <dynamic> SearchAsync(int customerId) { if (customerId <= 0) { throw new CustomArgumentOutOfRangeException($"The {nameof(customerId)} can not be zero or less than zer") { ExceptionDetails = new ExceptionDetails( SearchErrors.Search.CustomerIdOutOfRange.Message, SearchErrors.Search.CustomerIdOutOfRange.ErrorCode, SearchErrors.Search.CustomerIdOutOfRange.Detail, nameof(customerId)) } } ; var customer = await _customersService.GetCustomerAsync(customerId); if (customer == null) { throw new CustomNotFoundException($"The {nameof(customerId)} cannnot find with this given id : <{customerId}>") { ExceptionDetails = new ExceptionDetails( nameof(customerId)) } } ; var orders = await _ordersService.GetOrdersAsync(customerId); var orderServiceResults = orders as OrderServiceResult[] ?? orders.ToArray(); if (orderServiceResults.Any()) { var products = await _productsService.GetProductsAsync(); var productServiceResults = products?.ToList(); foreach (var order in orderServiceResults) { foreach (var item in order.Items) { item.ProductName = productServiceResults != null && productServiceResults.Any() ? productServiceResults?.FirstOrDefault(p => p.Id.Equals(item.ProductId))?.Name : "Product information is not available"; } } } return(new { customer, orders = orderServiceResults }); } } }
public async Task <ActionResult <Customer> > Get(string id) { var response = await _customersService.GetCustomerAsync(id); if (response == null) { return(NotFound()); } return(response); }
public async Task <IActionResult> GetCustomerAsync(int id) { var result = await customersProvider.GetCustomerAsync(id); if (result.IsSuccess) { return(Ok(result.Customer)); } return(NotFound()); }
public async Task <IActionResult> GetCategoryAsync([FromRoute] string id) { var model = await _productsService.GetCustomerAsync(id); if (model == null) { return(NotFound()); } return(Ok(model)); }
public async Task <(bool IsSuccess, dynamic SearchResults)> SearchCustomerAsync(int customerId) { var customersResult = await customersService.GetCustomerAsync(customerId); if (customersResult.IsSuccess) { var result = new { customer = customersResult.Customer }; return(true, result.customer); } return(false, null); }
public async Task <IActionResult> SearchByIdAsync(string CustomerID) { if (string.IsNullOrWhiteSpace(CustomerID)) { return(BadRequest()); } try { var customer = await customersService.GetCustomerAsync(CustomerID); var sales = await salesService.GetAsync(CustomerID); var result = new { Customer = customer, Sales = sales }; foreach (var sale in sales) { foreach (var item in sale.Items) { var product = await productsService.GetProductAsync(item.ProductId); item.Product = product; } } return(Ok(result)); } catch (Exception) { throw; } }
public async Task <CustomerDto> GetCustomer(int id) { var customer = await _customersService.GetCustomerAsync(id); return(customer); }