private static void Setup()
        {
            StoreCatalogue.Instance.RegisterItem("Item1", 1);
            StoreCatalogue.Instance.RegisterItem("Item2", 2);
            StoreCatalogue.Instance.RegisterItem("Item3", 3);
            StoreCatalogue.Instance.RegisterItem("Item4", 4);
            StoreCatalogue.Instance.RegisterItem("Item5", 5);


            Locations.Instance.RegisterLocation("Store1");
            Locations.Instance.GetLocation("Store1").AddInventory("Item1", 50);
            Locations.Instance.GetLocation("Store1").AddInventory("Item2", 1);
            Locations.Instance.GetLocation("Store1").AddInventory("Item3", 10);

            Locations.Instance.RegisterLocation("Store2");
            Locations.Instance.GetLocation("Store2").AddInventory("Item4", 50);
            Locations.Instance.GetLocation("Store2").AddInventory("Item5", 60);
            Locations.Instance.GetLocation("Store2").AddInventory("Item2", 25);

            Store.Customer c = Customers.Instance.RegisterCustomer("Daniel", "last", 'm');
            Customers.Instance.RegisterCustomer("Randel", "last", 'n');
            Customers.Instance.RegisterCustomer("Daniel", "last");

            Console.WriteLine("Creating first order");
            Store.Order o = Locations.Instance.GetLocation("Store1").CreateNewOrder("Item1", 10, c);
            o.FinallizeOrder();


            o = Locations.Instance.GetLocation("Store2").CreateNewOrder("Item5", 1, c);
            o.EditOrderAmounts("Item2", 5);
            o.FinallizeOrder();
        }
示例#2
0
        /// <summary>
        /// Take a finalized order from the model, and convert it into a db order, adjust store invintories,
        /// and insert it.
        /// </summary>
        /// <exception cref="NullReferenceException">
        /// This might throw a null reference if the store has no invintory for an item in the order in the database.
        /// </exception>
        /// <param name="o">A model order. This order should have had Finalize() called on it, as this method doesn't</param>
        public void PlaceOrder(Store.Order o)
        {
            Order newOrder = new Order();
            //default is null.
            int nextid = (_context.Orders.OrderByDescending(cust => cust.Id).FirstOrDefault()?.Id ?? 0) + 1;

            newOrder.Id            = nextid;
            newOrder.StoreLocation = o.OrderLoc.LocationName;
            newOrder.Customer      = GetDBCustomerByName(o.Customer.CustomerName);
            newOrder.OrderTime     = o.Time;

            decimal total = 0;

            foreach (ItemCount item in o.Items)
            {
                total += item.Count * (Decimal)item.ThisItem.cost;

                OrderItem orderItem = new OrderItem();
                orderItem.Order    = newOrder;
                orderItem.Quantity = item.Count;
                orderItem.ItemId   = item.ThisItem.name;
                newOrder.OrderItems.Add(orderItem);

                //change store stocks, Assumes there's already an invintory entry, otherwise throws exception.
                Invintory iv = _context.Invintories.Find(o.OrderLoc.LocationName, item.ThisItem.name);
                iv.Quantity -= item.Count;
            }
            newOrder.OrderTotal = total;

            _context.Orders.Add(newOrder);
            _context.SaveChanges();
            //o.ID = newOrder.Id;
        }
 public EditOrderMenu(IDbRepository repo, Store.Customer currentCustomer, Store.Location selectedStore, Store.Order currentOrder)
 {
     Repo = repo;
     this.currentCustomer = currentCustomer;
     this.selectedStore   = selectedStore;
     this.currentOrder    = currentOrder;
 }