public static Entities.Inventory MapInv(Business.Library.Inventory inventory)
 {
     return(new Entities.Inventory
     {
         Id = inventory.ID,
         LocationId = inventory.location_id,
         ProductId = inventory.product_id,
         Quantity = inventory.quantity
     });
 }
Beispiel #2
0
        public static void UpdateOrder(Repository data, Order order, Business.Library.Inventory inv)
        {
            //List<Business.Library.Order> entityOrder = data.GetOrders(order.OCustomer, order.OLocation);


            Business.Library.OrderDetails od = new Business.Library.OrderDetails();
            //od.order_id = entityOrder[0].ID;
            //od.Order = entityOrder[0];
            od.product_id = inv.Product.ID;
            od.Quantity   = inv.quantity;
            od.Product    = inv.Product;
            Console.WriteLine($"Updating od: order_id = {od.order_id}, product_id = {od.product_id}, quantity = {od.Quantity}");
            data.AddNewOrderDetail(od);
            data.Save();
        }
Beispiel #3
0
        public static List <Product> AddToCart(Business.Library.Inventory invItem, int quantity, Location location, Repository data, List <Product> cart)
        {
            Business.Library.OrderDetails od = new Business.Library.OrderDetails();
            try
            {
                invItem.Product = new Product(invItem.Product.Name, invItem.Product.Description, invItem.Product.Price);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Product does not exist try again.");
                return(cart);
            }
            int index;

            //Console.WriteLine($"Location: {_location.LocationName}");
            //Console.WriteLine($"Index => {index}");
            //Console.WriteLine($"Item {item.Name}, quantity: {_location.Inventory[index].Amount} ");
            //Console.WriteLine(_location.Quantity(product));
            //Console.WriteLine("Removing item from inventory");
            //_location.RemoveItem(product, quantity);
            //Console.WriteLine($"Quantity now {_location.Quantity(product)}");
            if (location.Quantity(invItem) >= quantity)
            {
                cart.Add(invItem.Product);
                Console.WriteLine($"Added {invItem.Product.Name} to cart.");
                index             = cart.IndexOf(invItem.Product);
                invItem.quantity -= quantity;


                data.UpdateLocationInventory(invItem);
                data.Save();
                cart[index].Amount += quantity;
                return(cart);
            }
            else if (location.Quantity(invItem) == 0)
            {
                Console.WriteLine($"{invItem.Product.Name} is sold out!");
                return(cart);
            }
            else
            {
                Console.WriteLine($"There is only {location.Quantity(invItem)} left. " +
                                  $"Please decrease quantity.");
                return(cart);
            }
        }
 public void UpdateLocationInventory(Business.Library.Inventory inventory)
 {
     Entities.Inventory myEntity  = _context.Inventory.Find(inventory.ID);
     Entities.Inventory newEntity = Mapper.MapInv(inventory);
     _context.Entry(myEntity).CurrentValues.SetValues(newEntity);
 }
Beispiel #5
0
        public static void SelectProducts(Location location, Customer customer, Repository data, List <Location> locations)
        {
            decimal        total    = 0;
            int            quantity = 0;
            List <Product> cart     = new List <Product>();
            List <Business.Library.Inventory> inventory = null;
            Order order = new Order(location, customer);

            Business.Library.Inventory item = null;
            string option = null;

            //order_history = null;

            while (option != "c" && option != "r")
            {
                Console.Write($"Hello ");
                Console.WriteLine($"{customer.Customername}");
                Console.WriteLine($"Welcome to {location.LocationName}!  ");
                Console.WriteLine($"| Product || Description || Price || Quantity         ");
                ChangeColor(ConsoleColor.Blue);
                Console.WriteLine("====================================================");
                ChangeColor(ConsoleColor.White);

                inventory = PrintLocationInventory(data, location);
                ChangeColor(ConsoleColor.Blue);
                Console.WriteLine("====================================================");
                ChangeColor(ConsoleColor.White);
                Console.WriteLine($"| [R] Return to previous menu    ");
                Console.WriteLine($"| [M] Return to main menu    ");
                ChangeColor(ConsoleColor.Blue);
                Console.WriteLine($"+-----------------------------------------------+  \n");
                ChangeColor(ConsoleColor.White);
                Console.Write("Select product names or R/M: ");
                option = Console.ReadLine();

                if (option.ToLower() == "r")
                {
                    Console.WriteLine("Returning to previous menu...");
                    Thread.Sleep(2000);
                    Console.Clear();
                    SelectStore(option, customer, locations, data);
                    //return null;
                }
                else if (option.ToLower() == "m")
                {
                    Console.WriteLine("Returning to main menu...");
                    Thread.Sleep(2000);
                    Console.Clear();
                    //submitted_order = order_history;
                    return;
                }

                else
                {
                    item = inventory.Find(x => x.Product.Name.Contains(option));
                    Console.Write("How many: ");
                    option = Console.ReadLine();
                    int.TryParse(option, out quantity);
                    cart = AddToCart(item, quantity, location, data, cart);
                    if (cart.Count != 0)
                    {
                        Console.WriteLine("\n");
                        //List<Business.Library.OrderDetails> orderCart = data.GetCurrentCart(order);
                        order.Total = PrintCart(customer, cart);
                        Console.WriteLine("Press C to checkout or any other key to add more. ");
                        option = Console.ReadLine().ToLower();
                        Console.Clear();
                    }
                    else
                    {
                        Console.Clear();
                        SelectProducts(location, customer, data, locations);
                    }
                }
            }
            //data.AddNewOrder(order);
            //data.Save();
            //UpdateOrder(data, order, item);

            return;
        }