Example #1
0
        /// <summary>
        /// Dangerous!!
        /// Don't use
        /// </summary>
        public static void CreateNewTransaction()
        {
            using (var dbContext = new InventoryContext())
            {
                var allItems = from item in dbContext.Items
                               where item.ItemID == 1 || item.ItemID == 2
                               select item;

                Dictionary <Item, int> itemToQuantity = new Dictionary <Item, int>();

                //buy quantity of 12 of all items
                foreach (Item item in allItems)
                {
                    itemToQuantity.Add(item, 12);
                }

                UIObjectCreator.CreateNewTransaction(itemToQuantity);
                Console.WriteLine((from transaction in dbContext.Transactions select transaction).First().TransactionID);

                var allI_Ts = from i_t in dbContext.ItemTransactions select i_t;
                foreach (ItemTransaction i_t in allI_Ts)
                {
                    Console.WriteLine(string.Format("TransactionID: {0}\nItemID: {1}\nQuantity{2}\n", i_t.TransactionID, i_t.ItemID, i_t.Quantity));
                }
            }
        }
Example #2
0
        //This and ReduceItemQuantityStockLevel() works!
        public static void TestIfCreateNewReservationWorks()
        {
            using (var dbContext = new InventoryContext())
            {
                var allItems            = dbContext.Items;
                var _ItemToQuantity     = new Dictionary <Item, int>();
                var _ExpectedPickUpDate = new DateTime(2017, 12, 12, 23, 0, 0);

                foreach (Item item in allItems)
                {
                    _ItemToQuantity.Add(item, 1);
                }

                UIObjectCreator.CreateNewCurrentReservation(_ItemToQuantity, _ExpectedPickUpDate, dbContext);

                //check if it worked
                var currRes = (from r in dbContext.Reservations.OfType <CurrentReservation>()
                               where r.ExpectedPickUpDate == _ExpectedPickUpDate
                               select r).First();

                Console.WriteLine(
                    string.Format("ReservationID:{0}, IsPickedUp{1}, ExpectedPickUpDate:{2}"
                                  , currRes.ReservationID, currRes.IsPickedUp, currRes.ExpectedPickUpDate)
                    );
            }
        }
Example #3
0
        //Yes it does work
        public static void TestIfCreateCurrDelWorks(DateTime _expectedArrivalDate)
        {
            using (var dbContext = new InventoryContext())
            {
                Dictionary <Item, int> _itemToItemQuantity = new Dictionary <Item, int>();
                var _supplier = dbContext.Suppliers.First();

                var allItems = dbContext.Items;

                foreach (Item item in allItems)
                {
                    _itemToItemQuantity.Add(item, 12);
                }

                UIObjectCreator.CreateNewCurrentDelivery(_itemToItemQuantity, _expectedArrivalDate, _supplier, dbContext);

                //checking if worked
                var currDel = (from del in dbContext.Deliveries.OfType <CurrentDelivery>()
                               where del.ExpectedArrivalDate == _expectedArrivalDate
                               select del).First();
                Console.WriteLine(
                    string.Format("DeliveryID:{0}, ExpectedArrivalDate:{1}, SupplierName:{2}, IsArrived:{3}"
                                  , currDel.DeliveryID, currDel.ExpectedArrivalDate, currDel.Supplier.SupplierName, currDel.IsArrived)
                    );
            }
        }
Example #4
0
        //Testing if turning CurrentDelivery to PastDelivery works
        public static void TestIfCreatePastDeliveryWorks()
        {
            using (var dbContext = new InventoryContext())
            {
                //Creating a new PastDelivery object
                CurrentDelivery CurrDel = dbContext.Deliveries.OfType <CurrentDelivery>()
                                          .First();


                var ActualArrivalDate = DateTime.Now.AddDays(1);

                var PastDel = UIObjectCreator.CreatePastDelivery(CurrDel, ActualArrivalDate, dbContext);

                //Testing if it worked
                if (PastDel == null)
                {
                    Console.WriteLine("It's null again. :(");
                }
                else
                {
                    var PastDelFromDB = dbContext.Deliveries.OfType <PastDelivery>()
                                        .Where(pd => pd.ActualArrivalDate == ActualArrivalDate)
                                        .First();
                    Console.WriteLine(
                        string.Format("DeliveryID:{0}, ActualArrivalDate:{1}, IsArrived:{2}"
                                      , PastDelFromDB.DeliveryID
                                      , PastDelFromDB.ActualArrivalDate
                                      , PastDelFromDB.IsArrived)
                        );
                }
            }
        }
Example #5
0
        void AddItemToDB(string barcode, string description, decimal rrp, int stockLevel, ItemCatagory itemCatagory)
        {
            var item = UIObjectCreator.CreateNewItem(barcode, description, rrp, stockLevel, itemCatagory);

            if (item == null)
            {
                //Item wasn't added, set all input fields to default
                MessageBox.Show("Something went wrong.\nThat item was not added.\nTry again.");
                SetToDefault();
            }
            else
            {
                MessageBox.Show("Item was succesfully added to the database.");
                SetToDefault();
            }
        }