Beispiel #1
0
        public void Handle(MergeFieldValueIntoDocument message)
        {
            const string InsertSql = @"
INSERT INTO [Document](DataCaptureId, Text) 
SELECT @DataCaptureId, [Text] FROM Template 
WHERE NOT EXISTS(SELECT * FROM [Document] WHERE DataCaptureId = @DataCaptureId)";

            var mapping = projectionStore
                          .GetProjection <RiskCaptureItemToDocumentFieldMapping>(RiskCaptureItemToDocumentFieldMappingId.Parse(message.ProductLine))
                          .Single(i => i.ItemId == message.DataCaptureId);

            runner.ExecuteConnectionAction(connection =>
            {
                connection.Execute(InsertSql, new { message.DataCaptureId });

                var documents = connection
                                .Query <Document>("SELECT * from Document WHERE DataCaptureId = @DataCaptureId", new { message.DataCaptureId });

                documents.ForEach(document =>
                {
                    document.Merge(mapping.FieldName, message.FieldValue);
                    connection.Execute("UPDATE [Document] SET Text = @Text WHERE DataCaptureId = @DataCaptureId", document);
                });
            });
        }