Exemplo n.º 1
0
        public List <int> ReplenishInventory(string nameOfStore, List <int> productQuantity)
        {
            int i = 0;
            List <Inventory> inventories      = _repo.GetAllInventories();
            List <Product>   products         = _repo.GetAllProducts();
            List <int>       updatedInventory = new List <int>();

            Log.Information("BL attempt to retrive specific location from DL");
            Location location         = _locationBL.GetLocation(nameOfStore);
            bool     inventoryUpdated = false;

            foreach (Product item in products)
            {
                inventoryUpdated = false;
                // If no inventory entries exist
                if (!inventories.Any())
                {
                    Inventory newInventory = new Inventory(location.Id, item.Id, productQuantity[i]);
                    updatedInventory.Add(productQuantity[i]);
                    i++;
                    Log.Information("BL sent new inventory to DL");
                    _repo.AddInventory(newInventory, location, item);
                    inventoryUpdated = true;
                }
                foreach (Inventory inventory in inventories)
                {
                    // If match is found update inventory
                    if (inventory.LocationID.Equals(location.Id) && inventory.ProductID.Equals(item.Id) && !inventoryUpdated)
                    {
                        inventory.Quantity += productQuantity[i];
                        updatedInventory.Add(inventory.Quantity);
                        i++;
                        Log.Information("BL sent updated inventory to DL");
                        _repo.UpdateInventory(inventory, location, item);
                        inventoryUpdated = true;
                    }
                }
                // If inventory exists but specific item does not
                if (!inventoryUpdated)
                {
                    Inventory newInventory = new Inventory(location.Id, item.Id, productQuantity[i]);
                    updatedInventory.Add(productQuantity[i]);
                    i++;
                    Log.Information("BL sent new inventory to DL");
                    _repo.AddInventory(newInventory, location, item);
                }
            }
            Log.Information("BL sent updated inventory to UI");
            return(updatedInventory);
        }
        public void DecrementInventory(int pcode, string lcode)
        {
            int lctn = _locationBL.GetLocation(lcode);

            Inventory newInventory = _inventoryBL.GetInventory(pcode, lctn);

            _inventoryBL.DecrementInventory(newInventory);
        }
Exemplo n.º 3
0
        private Location SearchBranch()
        {
            DisplayBranchLocations();
            string name = _validate.ValidateEmptyInput("Select a location from above table by [Branch Location Name]");

            try
            {
                Location branch = _locationBL.GetLocation(name);
                return(branch);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("No matched branch is found. Go back to Branch Menu and create one");
                return(null);
            }
        }
        /// <summary>
        /// UI to view location order history
        /// </summary>
        private void ViewLocationOrderHistory()
        {
            bool   repeat       = true;
            string locationName = _validate.ValidateString("\nEnter the location you want to view");

            Log.Information("Location name input");
            try
            {
                // Search for specific location and retrieve orders
                Location     location       = _locationBL.GetLocation(locationName);
                List <Order> locationOrders = _orderBL.GetLocationOrders(location.Id);
                List <Order> sortedOrders   = new List <Order>();
                do
                {
                    Console.WriteLine("How should the orders be sorted?");
                    Console.WriteLine("[1] Sort by Date (Newest to Oldest)");
                    Console.WriteLine("[2] Sort by Date (Oldest to Newest)");
                    Console.WriteLine("[3] Sort by Cost (Lowest to Highest)");
                    string input = Console.ReadLine();

                    switch (input)
                    {
                    case "1":
                        Log.Information("Sort by Date Ascending Selected");
                        repeat       = false;
                        sortedOrders = locationOrders.OrderByDescending(ord => ord.OrderDate).ToList();
                        break;

                    case "2":
                        Log.Information("Sort by Date Descending Selected");
                        repeat       = false;
                        sortedOrders = locationOrders.OrderBy(ord => ord.OrderDate).ToList();
                        break;

                    case "3":
                        Log.Information("Sort by Cost Ascending Seleceted");
                        repeat       = false;
                        sortedOrders = locationOrders.OrderBy(ord => ord.Total).ToList();
                        break;

                    default:
                        // Invalid Input
                        Console.WriteLine("Please input a valid option");
                        break;
                    }
                } while (repeat);
                // Iterate through, orders, line items, and products to display order information
                foreach (Order order in sortedOrders)
                {
                    Customer        customer  = _customerBL.SearchCustomer(order.CustomerID);
                    List <LineItem> lineItems = _lineItemBL.GetLineItems(order.OrderID);
                    Console.WriteLine($"\nCustomer Name: {customer.FirstName} {customer.LastName} \nLocation Name: {location.StoreName} \nOrder Date: {order.OrderDate}");
                    foreach (LineItem lineItem in lineItems)
                    {
                        List <Product> products = _productBL.GetAllProducts();
                        foreach (Product product in products)
                        {
                            if (product.Id.Equals(lineItem.ProductID))
                            {
                                Console.WriteLine($"{lineItem.Quantity} {product.ItemName}");
                            }
                        }
                    }
                    Console.WriteLine($"Order Total ${order.Total}\n");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }