public void SubmitChanges(CommodityStorageNote document)
        {
            int sequence = 0;
            var envelope = new CommandEnvelope();
            envelope.Initialize(document);
            List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute();

            CreateCommand createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault();
            if (createCommand != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand));
            List<AfterCreateCommand> lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>().ToList();
            foreach (var item in lineItemCommands)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item));
                //_commandRouter.RouteDocumentCommand(item);

            }

            ConfirmCommodityStorageCommand confirmCommand = commandsToExecute.OfType<ConfirmCommodityStorageCommand>().FirstOrDefault();
            if (confirmCommand != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, confirmCommand));
            _commandEnvelopeRouter.RouteCommandEnvelope(envelope);

            _auditLogWFManager.AuditLogEntry("Commodity Storage", "Created and confirmed commodity storage note " + document.DocumentReference+ "; id "+document.Id + " with " +document.LineItems.Count+" line items");
        }
        private SourcingDocument Map(tblSourcingDocument tbldoc)
        {
            SourcingDocument doc = null;
            doc = new CommodityStorageNote(tbldoc.Id);
            _Map(tbldoc, doc);
            CommodityStorageNote storageNote = doc as CommodityStorageNote;
            storageNote._SetLineItems(tbldoc.tblSourcingLineItem.Select(MapCommodityStorageLineItem).ToList());
            doc = storageNote;
            return doc;

        }
        private CompletedAndStoredCommodityListItem Map(CommodityStorageNote doc)
       {

           var item = new CompletedAndStoredCommodityListItem
           {
               DocumentId = doc.Id,
               DocumentReference = doc.DocumentReference,
               DateIssued = doc.DocumentDateIssued,
               ClerkName = doc.DocumentIssuerUser.Username,
               Description = doc.Description,
               NetWeight = doc.TotalNetWeight,
               NoOfContainers = doc.LineItems.Count,
               Status = doc.Status
           };
           return item;
       }
 public void SubmitChanges(CommodityStorageNote document)
 {
     
 }
 public CommodityStorageLineItem PendingSourcingDocumentLineItemsFactory(CommodityStorageNote document,
                                                                         ISourcingDocumentLineItemFactoryParameters parameters)
 {
     throw new NotImplementedException();
 }
 public void SaveNew(CommodityStorageNote document)
 {
     throw new NotImplementedException();
 }