Esempio n. 1
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);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
        }