public void SubmitChanges(InventoryTransferNote document, BasicConfig config)
        {

            int sequence = 0;
            var envelope = new CommandEnvelope();
            envelope.Initialize(document);
            List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute();
            var createCommand = commandsToExecute.OfType<CreateCommand>().First();
            envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand));
            //_commandRouter.RouteDocumentCommand(createCommand);
            _auditLogWFManager.AuditLogEntry("Inventory Transfer", string.Format("Created Inventory Transfer: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name));

            var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
            foreach (var _item in lineItemCommands)
            {
                var item = _item as AddInventoryTransferNoteLineItemCommand;
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item));
               // _commandRouter.RouteDocumentCommand(_item);
                _auditLogWFManager.AuditLogEntry("Inventory Transfer", string.Format("Transferred Product: {0}; Quantity: {1}; for Inventory Transfer: {2};", item.ProductId, item.Qty, document.Id));
            }
            var co = commandsToExecute.OfType<ConfirmCommand>().First();
            envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co));
            //_commandRouter.RouteDocumentCommand(co);
            _commandEnvelopeRouter.RouteCommandEnvelope(envelope);
            _auditLogWFManager.AuditLogEntry("Inventory Transfer", string.Format("Confirmed Inventory Transfer: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name));
        }
 public void Submit(InventoryTransferNote note)
 {
     int sequence = 0;
     var envelope = new CommandEnvelope();
     envelope.Initialize(note);
     List<DocumentCommand> commandsToExecute = note.GetDocumentCommandsToExecute();
     var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault();
     if (createCommand != null)
     {
         envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand));
     }
     var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
     foreach (var _item in lineItemCommands)
     {
         envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item));
     }
     var co = commandsToExecute.OfType<ConfirmCommand>().First();
     if(co !=null)
     {
         envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co));
     }
     AddToMongoDB(envelope);
 }