public static void SaveDocument(DomainDocument document) { var connectionString = SettingsManager.LoadDbSettings().ConnectionString; using (var connection = new SqlConnection(connectionString)) { var documentId = connection.Query <int?>(Queries.DocumentSave, document).FirstOrDefault() ?? 0; if (documentId > 0) { document.Nodes.ForEach(n => n.DocumentId = documentId); document.Links.ForEach(l => l.DocumentId = documentId); connection.Execute(Queries.DeleteNodesByDocumentId, new { documentId }); connection.Execute(Queries.DeleteLinksByDocumentId, new { documentId }); connection.Execute(Queries.NodeSave, document.Nodes); connection.Execute(Queries.LinkSave, document.Links); } } }
public void CreateDocument(DomainDocument domainDocument) { Document = new Document { Id = domainDocument.Id, Name = domainDocument.Name, WindowSize = Size }; foreach (var node in domainDocument.Nodes) { var rectangle = new Rectangle(node.X, node.Y, node.Width, node.Height); switch (node.Type) { case NodeType.Concept: var rectangleNode = new RectangleNode(rectangle) { Id = node.Id, Label = new LabelElement { Text = node.Label } }; rectangleNode.Label.PositionBySite(rectangleNode); Document.AddElement(rectangleNode); break; case NodeType.Relation: var ellipseNode = new EllipseNode(rectangle) { Id = node.Id, Label = new LabelElement { Text = node.Label } }; ellipseNode.Label.PositionBySite(ellipseNode); Document.AddElement(ellipseNode); break; case NodeType.Comment: var commentBoxElement = new CommentBoxElement(rectangle) { Id = node.Id, Label = new LabelElement { Text = node.Label } }; commentBoxElement.Label.PositionBySite(commentBoxElement); Document.AddElement(commentBoxElement); break; } } foreach (var link in domainDocument.Links) { ConnectorElement startConnectorElement, endConnectorElement; GetConnectors(link, out startConnectorElement, out endConnectorElement); if (startConnectorElement != null && endConnectorElement != null) { var linkElement = new StraightLinkElement(startConnectorElement, endConnectorElement) { Id = link.Id, Label = new LabelElement { Text = link.Label } }; linkElement.Label.Size = EditLabelAction.GetTextSize(linkElement); linkElement.Label.PositionBySite(linkElement); Document.Elements.Add(linkElement); } } Document.SetCurrentId(); RecreateEventsHandlers(); }