public IEnumerable <Models.Order> GetDeliveryOrders([FromRoute] string routeCode) { // Build new route helper Helpers.Route routeHelper = new Helpers.Route(_context); // Get orders list to be delivered today List <Models.Order> orders = routeHelper.GetRouteOrders(routeCode); // Verify whether orders list is not empty if (orders.Any()) { // Iterate through all orders found foreach (var order in orders) { // Find container return by order number var containerReturn = _context .ContainerReturns .Include(x => x.Items) .Where(x => x.ReturnNumber == order.OrderNumber) .FirstOrDefault(); // Verify whether container return is not null if (containerReturn != null) { // Assign container return found order.Container = containerReturn; } } } // Return result return(orders); }
public List <Models.AS400.Customer> GetCustomersByRoute( [FromRoute] string routeCode, [FromRoute] Decimal?customerCode = null ) { // Create a new route helper instance Helpers.Route routeHelper = new Helpers.Route(_distributionContext); // Save route type var isDeliveryRoute = IsDeliveryRoute(routeCode); // Build query standard parameters List <QueryParameter> parameters = new List <QueryParameter>(); parameters.Add(new QueryParameter { key = "{schema}", value = AS400Schema.GetSchema(Constants.DATA_WAREHOUSE_PREFIX) }); parameters.Add(new QueryParameter { key = "{routeCodes}", value = $"'{routeCode}'" }); // Query all customers List <Models.AS400.Customer> customers = _BPCSContext .Customers .FromSql(QueryBuilder.Build("GetCustomersByRoute.txt", parameters)) .ToListAsync() .Result; // Verify whether customer code is not empty if (customerCode != null) { // Filter customer list by customer code customers = customers.FindAll(x => x.CustomerCode == customerCode); } // Verify whether route is for delivery or not if (isDeliveryRoute) { // Query orders and extract customer codes List <Models.Order> orders = routeHelper.GetRouteOrders(routeCode); // Verify whether any order was found if (orders.Count > 0) { // Create an empty list to store the customer codes List <int> customerCodes = new List <int>(); // Iterate through all orders found foreach (var order in orders) { // Verify whether the customer codes list do not contain the same customer code if (!customerCodes.Contains(Int32.Parse(order.CustomerCode))) { customerCodes.Add(Int32.Parse(order.CustomerCode)); } } // Verify whether the customer codes list is not empty if (customerCodes.Count > 0) { // Filter customers list by customer codes return(customers .FindAll(x => customerCodes.Contains(x.CustomerCode) || x.CreditLimit > 0)); } } else { return(new List <Models.AS400.Customer>()); } } // Return result return(customers); }
public List <PriceList> GetPriceListByRoute([FromRoute] string routeCode, [FromQuery] int numberOfRecords = 10) { // Create a new route helper instance Helpers.Route routeHelper = new Helpers.Route(_distributionContext); // Save route type var isDeliveryRoute = IsDeliveryRoute(routeCode); // Build query standard parameters List <QueryParameter> parameters = new List <QueryParameter>(); parameters.Add(new QueryParameter { key = "{numberOfRecords}", value = numberOfRecords.ToString() }); parameters.Add(new QueryParameter { key = "{schema}", value = AS400Schema.GetSchema(Constants.AS400_PREFIX) }); parameters.Add(new QueryParameter { key = "{routeCode}", value = routeCode }); // Query all price lists var priceLists = _BPCSContext .PriceLists .FromSql(QueryBuilder.Build("GetPriceListByRoute.txt", parameters)) .ToListAsync() .Result; // Verify whether route is for delivery or not if (isDeliveryRoute) { // Query orders and extract customer codes List <Models.Order> orders = routeHelper.GetRouteOrders(routeCode); // Verify whether any order was found if (orders.Count > 0) { // Create an empty list to store the item codes List <string> itemCodes = new List <string>(); // Iterate through all orders found foreach (var order in orders) { // Get order items List <OrderItem> items = order.Items; // Verify whether any item was found in the order if (items.Count > 0) { // Iterate through all items found foreach (var item in items) { // Verify whether the item codes list do not contain the same item code if (!itemCodes.Contains(item.ItemCode)) { itemCodes.Add(item.ItemCode); } } } } // Verify whether the item codes list is not empty if (itemCodes.Count > 0) { // Filter price lists by item codes return(priceLists.FindAll(x => itemCodes.Contains(x.ItemCode))); } } else { return(new List <PriceList>()); } } return(priceLists); }