public void Submit(InventoryAdjustmentNote note)
 {
     int sequence = 0;
     var envelope = new CommandEnvelope();
     envelope.Initialize(note);
     List<DocumentCommand> commandsToExecute = note.GetDocumentCommandsToExecute();
     var createCommand = commandsToExecute.OfType<CreateCommand>().First();
    
     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);
 }
        public void SubmitChanges(InventoryAdjustmentNote document, BasicConfig config)
        {
            int sequence = 0;
            var envelope = new CommandEnvelope();
            envelope.Initialize(document);
            envelope.OtherRecipientCostCentreList.Add(Guid.NewGuid());
            List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute();
            
            var createCommand = commandsToExecute.OfType<CreateCommand>().First();
           // _commandRouter.RouteDocumentCommand(createCommand);
            envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence,createCommand));
            _auditLogWFManager.AuditLogEntry("Inventory Adjustment", string.Format("Created IAN document: {0};", document.Id));

            var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
            foreach (var _item in lineItemCommands)
            {
                var item = _item as AddInventoryAdjustmentNoteLineItemCommand;
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item));
             
                _auditLogWFManager.AuditLogEntry("Inventory Adjustment", string.Format("Adjusted Product: {1}; quantity from: {2}; to: {3}; for IAN document: {0};", document.Id, item.ProductId, item.Actual, item.Actual));
            }
            
            var co = commandsToExecute.OfType<ConfirmCommand>().First();
            envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co));
            _commandEnvelopeRouter.RouteCommandEnvelope(envelope);
            _auditLogWFManager.AuditLogEntry("Inventory Adjustment", string.Format("Confirmed IAN document: {0};", document.Id));
        }