Exemple #1
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)
                        );
                }
            }
        }
Exemple #2
0
        public static CurrentDelivery CreateNewCurrentDelivery(Dictionary <Item, int> ItemToItemQuantity, DateTime expectedArrivalDate, Supplier supplier, InventoryContext dbContext)
        {
            //Create new currentDelivery
            var currDel = new CurrentDelivery()
            {
                IsArrived           = false,
                ExpectedArrivalDate = expectedArrivalDate,
                SupplierID          = supplier.SupplierID,
            };

            try
            {
                //save to db
                dbContext.Deliveries.Add(currDel);
                dbContext.SaveChanges();
            }
            catch (Exception)
            {
                //Failure to commit new Delivery to database
                return(null);
            }

            //if creating itemdeliveries didnt work
            if (!CreateItemDeliveries(ItemToItemQuantity, dbContext, currDel))
            {
                return(null);
            }
            else
            {
                return(currDel);
            }
        }
Exemple #3
0
        public static void CreateNewDelivery(DateTime expectedArrivalDate)
        {
            //vars needed
            Supplier supplier;

            //getting supplier
            using (var sRepo = new SupplierRepo(new InventoryContext()))
            {
                supplier = sRepo.GetByID(1);
            }

            //creating new delivery
            var NewCurrentDelivery = new CurrentDelivery()
            {
                Supplier            = supplier,
                IsArrived           = false,
                ExpectedArrivalDate = expectedArrivalDate
            };

            using (var cdRepo = new CurrentDeliveriesRepo(new InventoryContext()))
            {
                cdRepo.Add(NewCurrentDelivery);
                cdRepo.Complete();
            }
        }
Exemple #4
0
        public static List <object> ViewTblGetComboBoxObjects(dynamic user)
        {
            var Transaction     = new Transaction();
            var PastReservation = new PastReservation();
            var CurrentDelivery = new CurrentDelivery();
            var PastDelivery    = new PastDelivery();
            var Item            = new Item();
            var Supplier        = new Supplier();

            var datasource = new List <object>
            {
                Transaction,
                PastReservation,
                CurrentDelivery,
                PastDelivery,
                Item,
                Supplier
            };

            //if user isn't an admin and isnt allowed to see analytics
            //then remove first item from datasouce (transactions)
            if (!(user.IsAnalyticsAllowed))
            {
                //if the user isnt an admi
                datasource.RemoveAt(0);
            }

            return(datasource);
        }
        private void CurrentDeliveriesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CurrentDelivery selectedDelivery = (CurrentDeliveriesList.SelectedItem as CurrentDelivery);

            dataContext.SelectionChanged(selectedDelivery);
            RefreshControls();
        }
Exemple #6
0
        public void EndImport()
        {
            if (State != DeliveryManagerState.Importing)
            {
                throw new InvalidOperationException("EndImport can only be called after BeginImport.");
            }
            OnEndImport();

            CurrentDelivery.Save();
            CurrentDelivery = null;

            State = DeliveryManagerState.Idle;

            OnDisposeImport();
            OnDispose();
        }
Exemple #7
0
        public void CompleteDelivery()
        {
            CurrentDelivery.DeliveryComplete(true);
            CompletedNumDeliveries++;

            if (!IsLevelComplete())
            {
                SFXInstance = DeliverySound.CreateInstance();
                SFXInstance.Play();
                TheLastSliceGame.Instance.Player.OnDeliveryComplete();
                TheLastSliceGame.Instance.HUD.OnDeliveryComplete();
                NextDelivery();
            }
            else
            {
                SFXInstance = LevelCompleteSound.CreateInstance();
                SFXInstance.Play();
                TheLastSliceGame.Instance.Player.OnLevelComplete();
            }
        }
Exemple #8
0
        public static bool AttachItemDeliveriesToPastDelivery(CurrentDelivery CurrDel, PastDelivery PastDel, InventoryContext dbContext)
        {
            bool isSuccessful;

            try
            {
                var relatedI_Ds = UIUtility.GetItemDeliveries(CurrDel, dbContext);

                Item _testItem;
                foreach (ItemDelivery i_d in relatedI_Ds)
                {
                    _testItem = i_d.Item;
                    //Change each ItemDelivery to have a relation with the PastDel object
                    dbContext.ItemDeliveries.Add(new ItemDelivery()
                    {
                        Item     = i_d.Item,
                        Delivery = PastDel,
                        Quantity = i_d.Quantity
                    });

                    if (!IncreaseItemQuantityStockLevel(i_d.Item, i_d.Quantity, dbContext))
                    {
                        isSuccessful = false;
                        return(isSuccessful);
                    }

                    //Since everything worked, remove old ItemDelivery referencing CurrDel obj
                    dbContext.ItemDeliveries.Remove(i_d);
                }
                dbContext.SaveChanges();

                //It worked
                isSuccessful = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.ToString());
                isSuccessful = false;
            }
            return(isSuccessful);
        }
Exemple #9
0
        public void NextDelivery()
        {
            if (CompletedNumDeliveries == 0)
            {
                LevelLoading = true;
                SFXInstance  = LevelLoadingSounds[TheLastSliceGame.LevelManager.CurrentLevelNum - 1].CreateInstance();
                SFXInstance.Play();
            }

            if (!IsLevelComplete())
            {
                CurrentDelivery = Deliveries[CompletedNumDeliveries];
                CurrentDelivery.SetAsCurrentDelivery();
                TheLastSliceGame.Instance.HUD.OnNewDelivery();

                //Fill the map with the delivery ingredients - H.E.
                foreach (Ingredient ingredient in CurrentDelivery.Pizza)
                {
                    ingredient.Map.AddEntity(ingredient);
                }
            }
        }
Exemple #10
0
        /*public PastReservation CreatePastReservation()
         * {
         *
         * }*/
        public static PastDelivery CreatePastDelivery(CurrentDelivery CurrDel, DateTime ActualArrivalDate, InventoryContext dbContext)
        {
            try
            {
                Supplier Supplier = dbContext.Suppliers
                                    .Where(s => s.SupplierID == CurrDel.SupplierID)
                                    .First();
                var PastDel = new PastDelivery()
                {
                    IsArrived         = true,
                    Supplier          = Supplier,
                    ActualArrivalDate = ActualArrivalDate
                };

                dbContext.Deliveries.Add(PastDel);
                dbContext.SaveChanges();

                if (!AttachItemDeliveriesToPastDelivery(CurrDel, PastDel, dbContext))
                {
                    //It didn't work
                    return(null);
                }
                else
                {
                    //It did work
                    //So remove CurrDelivery, which is no longer needed
                    dbContext.Deliveries.Remove(CurrDel);
                    return(PastDel);
                }
            }
            catch (Exception ex)
            {
                //Add PastDel to database didn't work
                Console.WriteLine(ex.ToString());
                return(null);
            }
        }
Exemple #11
0
        public static bool CreateItemDeliveries(Dictionary <Item, int> ItemToItemQuantity, InventoryContext dbContext, CurrentDelivery currDel)
        {
            //Whether this transaction worked
            bool isSuccessful;

            try
            {
                foreach (KeyValuePair <Item, int> itemQuantity in ItemToItemQuantity)
                {
                    dbContext.ItemDeliveries.Add(new ItemDelivery()
                    {
                        Item     = itemQuantity.Key,
                        Delivery = currDel,
                        Quantity = itemQuantity.Value
                    });
                }
                dbContext.SaveChanges();

                isSuccessful = true;
            }
            catch (Exception)
            {
                //If adding ItemDelivries fails, remove currDel
                dbContext.Deliveries.Remove(currDel);
                dbContext.SaveChanges();
                isSuccessful = false;
            }
            return(isSuccessful);
        }
Exemple #12
0
 public void SelectionChanged(CurrentDelivery newCurrentDelivery)
 {
     CurrentDelivery             = newCurrentDelivery;
     CurrentItemDeliveryDisplays = GetCurrentItemDeliveryDisplays();
 }