void DeductBatchQuantityFromInventory()
        {
            string        query      = "SELECT * FROM ReceivedBatches WHERE SystemId = ?";
            List <object> parameters = new List <object> {
                targetId
            };

            store.ExecuteReader(typeof(ReceivedBatch), query, parameters);

            if (store.Results.Count > 0)
            {
                Entity <ReceivedBatch> targetInventoryEntity = store.Results[0] as Entity <ReceivedBatch>;
                ITransaction           finder = new ListCurrentInventoryTransaction(store);
                finder.Execute();

                foreach (IEntity entity in finder.Results)
                {
                    Entity <InventoryBatch> inventoryEntity = entity as Entity <InventoryBatch>;

                    if (inventoryEntity.NativeModel.BatchNumber == targetInventoryEntity.NativeModel.BatchNumber)
                    {
                        inventoryEntity.NativeModel.DeductQuantity(targetInventoryEntity.NativeModel.Quantity);
                        ITransaction updater = new EditBatchInCurrentInventoryTransaction(inventoryEntity, store);
                        updater.Execute();
                        break;
                    }
                }
            }
        }
Example #2
0
        public override void Execute()
        {
            if (BatchExistsInInventory())
            {
                Entity <InventoryBatch> entity = store.Results[0] as Entity <InventoryBatch>;
                entity.NativeModel.Quantity += this.entity.NativeModel.Quantity;

                ITransaction updater = new EditBatchInCurrentInventoryTransaction(entity, store);
                updater.Execute();
                return;
            }

            string query = "INSERT INTO InventoryBatches (ColorName, BatchNumber, ActivityDate, QtyOnHand) VALUES (?, ?, ?, ?)";

            List <object> parameters = new List <object>
            {
                entity.NativeModel.ColorName,
                entity.NativeModel.BatchNumber,
                entity.NativeModel.ActivityDate.FormatForDatabase(),
                entity.NativeModel.Quantity
            };

            store.ExecuteNonQuery(query, parameters);
        }