Example #1
0
 //constructor
 public UnitOfWork()
 {
     Context             = new InventoryContext();
     Items               = new ItemRepository(Context);
     ItemTransactions    = new ItemTransactionsRepo(Context);
     AdminAccounts       = new AdminAccountsRepo(Context);
     CurrentDeliveries   = new CurrentDeliveriesRepo(Context);
     CurrentReservations = new CurrentReservationsRepo(Context);
     ItemDeliveries      = new ItemDeliveriesRepo(Context);
     ItemReservations    = new ItemReservationsRepo(Context);
     PastDeliveries      = new PastDeliveriesRepo(Context);
     PastReservations    = new PastReservationsRepo(Context);
     StaffAccounts       = new StaffAccountsRepo(Context);
 }
Example #2
0
        /// <summary>
        /// Assumes items in itemToQuantity exist.
        /// </summary>
        /// <param name="itemsToQuantity"></param>
        /// <param name="expectedArrivalDate"></param>
        /// <param name="supplier"></param>
        public void AddNewCurrentDelivery(Dictionary <Item, int> itemsToQuantity, DateTime expectedArrivalDate, Supplier supplier)
        {
            //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();
            }

            //retrieving it
            using (var cdRepo = new CurrentDeliveriesRepo(new InventoryContext()))
            {
                NewCurrentDelivery = cdRepo.Find(cd => cd.ExpectedArrivalDate == expectedArrivalDate).First();
                cdRepo.Complete();
            }

            //adding ItemDeliveries
            //creating current deliveries from itemsToQuantity
            List <ItemDelivery> itemDeliveriesRange = new List <ItemDelivery>();

            foreach (KeyValuePair <Item, int> i_q in itemsToQuantity)
            {
                itemDeliveriesRange.Add(
                    new ItemDelivery()
                {
                    Item     = i_q.Key,
                    Delivery = NewCurrentDelivery,
                    Quantity = i_q.Value
                });
            }
            //adding range
            using (var idRepo = new ItemDeliveriesRepo(new InventoryContext()))
            {
                idRepo.AddRange(itemDeliveriesRange);
                idRepo.Complete();
            }
        }