public void CreateDiagram(DiagramModel diagram) { if (CurrentProject == null) { throw new NullReferenceException("ProjectModel does not exist"); } if (diagram == null) { return; } var diagramName = string.IsNullOrEmpty(diagram.Name) ? "diagram" : diagram.Name; var diagramNumber = 1; while (CurrentProject.Diagrams.Any(x => x.Name.Equals(diagramName + diagramNumber))) { diagramNumber++; } diagram.Name = diagramName + diagramNumber; CreateDiagramViewModel(diagram); CurrentProject.AddDiagram(diagram); }