# diagram-bpmn-editor

> BPMN process editor with a diagram canvas and a symbol palette of BPMN shapes, events, and tasks.

**Framework:** aspnet-mvc  **Component:** Diagram  **Variant:** bpmn-editor

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/diagram-bpmn-editor.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.Diagram
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/diagram-bpmn-editor/Diagram.cshtml

```cshtml
@using Syncfusion.EJ2.Diagrams;
@using Syncfusion.EJ2.Navigations;
@using EJ2MVCSampleBrowser.Models;
@section ControlsSection{

    <div class="control-section">
        <div class="sb-mobile-palette-bar">
            <div id="palette-icon" style="float: right;" role="button" class="bpmn-editor-icons e-toggle-palette"></div>
        </div>
        <div id="palette-space" class="sb-mobile-palette">
            @(Html.EJS().SymbolPalette("symbolpalette").ExpandMode(ExpandMode.Multiple).Width("100%").Height("445px")
                    .SymbolHeight(60).SymbolWidth(60).Palettes((List<SymbolPalettePalette>)ViewData["Palettes"]).SymbolMargin(new SymbolPaletteMargin() { Left = 15, Right = 15, Top = 15, Bottom = 15 }).GetNodeDefaults("getSymbolNodes").Render())
        </div>
        <div id="diagram-space" class="sb-mobile-diagram sb-bpmn-editor">
            @(Html.EJS().Diagram("diagram").Width("100%").Height("443px").ContextMenuSettings(c => c.Show(true).ShowCustomMenuOnly(true).Items(ViewData["ContextMenuItems"]))
                    .ContextMenuClick("contextMenuClick").ContextMenuOpen("contextMenuOpen").SnapSettings(s => s.Constraints(SnapConstraints.None)).DragEnter("dragEnter")
                    .Created("fitToPage").Nodes((List<DiagramNode>)ViewData["Nodes"]).Connectors((List<DiagramConnector>)ViewData["Connectors"]).Render())
        </div>
    </div>

    <style>
        #diagram {
            display: block;
        }
        #symbolpalette, #diagram {
            border: 1px solid #ccc;
        }
        #symbolPalette {
            display: block;
        }
        /* Bpmn context-menu items icon CSS */
        @@font-face {
            font-family: 'e-bpmn-icons';
            font-weight: normal;
            font-style: normal;
        }

        .e-bpmn-icons {
            font-family: 'e-bpmn-icons' !important;
            speak: none;
            font-size: 55px;
            font-style: normal;
            font-weight: normal;
            font-variant: normal;
            text-transform: none;
            line-height: 1;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        .e-bpmn-icons.e-Order:before {
            content: "\e700";
        }

        .e-bpmn-icons.e-InBOCatchMessage:before {
            content: "\e701";
        }

        .e-bpmn-icons.e-NoneEnd:before {
            content: "\e723";
        }

        .e-bpmn-icons.e-DataObjectCollection:before {
            content: "\e703";
        }

        .e-bpmn-icons.e-DataOutput:before {
            content: "\e704";
        }

        .e-bpmn-icons.e-EscalationEnd:before {
            content: "\e705";
        }

        .e-bpmn-icons.e-Activity:before {
            content: "\e706";
        }

        .e-bpmn-icons.e-EventBasedGateway:before {
            content: "\e721";
        }

        .e-bpmn-icons.e-CatchParallelMultiple:before {
            content: "\e708";
        }

        .e-bpmn-icons.e-CatchMultipleIn:before {
            content: "\e709";
        }

        .e-bpmn-icons.e-BoCatchCompensation:before {
            content: "\e70a";
        }

        .e-bpmn-icons.e-TimerIntermediate:before {
            content: "\e70b";
        }

        .e-bpmn-icons.e-NonInBoCatchParallelMultiple:before {
            content: "\e70d";
        }

        .e-bpmn-icons.e-NonInBoTimerIntermediate:before {
            content: "\e70e";
        }

        .e-bpmn-icons.e-ParallelEventBasedGatewaytostart:before {
            content: "\e718";
        }

        .e-bpmn-icons.e-NonInMultiple:before {
            content: "\e710";
        }

        .e-bpmn-icons.e-CompensationEnd:before {
            content: "\e711";
        }

        .e-bpmn-icons.e-InError:before {
            content: "\e70f";
        }

        .e-bpmn-icons.e-NonCatchMultipleIn:before {
            content: "\e713";
        }

        .e-bpmn-icons.e-InCompensation:before {
            content: "\e722";
        }

        .e-bpmn-icons.e-NonInEscalation:before {
            content: "\e716";
        }

        .e-bpmn-icons.e-ThrowMultipleIn:before {
            content: "\e717";
        }

        .e-bpmn-icons.e-InMessage:before {
            content: "\e715";
        }

        .e-bpmn-icons.e-OutMessage:before {
            content: "\e702";
        }

        .e-bpmn-icons.e-ScriptCall:before {
            content: "\e703";
        }

        .e-bpmn-icons.e-UserCall:before {
            content: "\e713";
        }

        .e-bpmn-icons.e-NonInThrowMessage:before {
            content: "\e719";
        }

        .e-bpmn-icons.e-EvBaseGateTostartProcess:before {
            content: "\e71a";
        }

        .e-bpmn-icons.e-InterruptingNone:before {
            content: "\e71e";
        }

        .e-bpmn-icons.e-ThrowingIntermediate:before {
            content: "\e711";
        }

        .e-bpmn-icons.e-DataOutputCollection:before {
            content: "\e71c";
        }

        .e-bpmn-icons.e-ThrowEscalationIn:before {
            content: "\e71d";
        }

        .e-bpmn-icons.e-ExclusiveGatewayWithMarker:before {
            content: "\e70d";
        }

        .e-bpmn-icons.e-ErrorEnd:before {
            content: "\e71f";
        }

        .e-bpmn-icons.e-ComplexGateway:before {
            content: "\e707";
        }

        .e-bpmn-icons.e-NonInParallelMultiple:before {
            content: "\e721";
        }

        .e-bpmn-icons.e-InSignal:before {
            content: "\e705";
        }

        .e-bpmn-icons.e-NonInBoCatchEscalation:before {
            content: "\e723";
        }

        .e-bpmn-icons.e-InclusiveGateway:before {
            content: "\e71e";
        }

        .e-bpmn-icons.e-MultipleEnd:before {
            content: "\e725";
        }

        .e-bpmn-icons.e-ThrowLinkin:before {
            content: "\e70c";
        }

        .e-bpmn-icons.e-ParallelGateway:before {
            content: "\e729";
        }

        .e-bpmn-icons.e-SignalEnd:before {
            content: "\e728";
        }

        .e-bpmn-icons.e-TerminateEnd:before {
            content: "\e714";
        }

        .e-bpmn-icons.e-BoCatchCompensationIn:before {
            content: "\e72a";
        }

        .e-bpmn-icons.e-InTimer:before {
            content: "\e720";
        }

        .e-bpmn-icons.e-ThrowCompensationIn:before {
            content: "\e72c";
        }

        .e-bpmn-icons.e-InConditional:before {
            content: "\e728";
        }

        .e-bpmn-icons.e-BoCatchCancelIn:before {
            content: "\e72f";
        }

        .e-bpmn-icons.e-ThrowMessage:before {
            content: "\e730";
        }

        .e-bpmn-icons.e-CatchLinkIn:before {
            content: "\e731";
        }

        .e-bpmn-icons.e-Gateway:before {
            content: "\e732";
        }

        .e-bpmn-icons.e-DataInputCollection:before {
            content: "\e733";
        }

        .e-bpmn-icons.e-NonInSignal:before {
            content: "\e734";
        }

        .e-bpmn-icons.e-DataInput:before {
            content: "\e70c";
        }

        .e-bpmn-icons.e-InMultiple:before {
            content: "\e710";
        }

        .e-bpmn-icons.e-InEscalation:before {
            content: "\e71a";
        }

        .e-bpmn-icons.e-CancelEnd:before {
            content: "\e717";
        }

        .e-bpmn-icons.e-DataObject:before {
            content: "\e739";
        }

        .e-bpmn-icons.e-NonInBOCatchMessage:before {
            content: "\e73a";
        }

        .e-bpmn-icons.e-ManualCall:before {
            content: "\e725";
        }

        .e-bpmn-icons.e-InParallelMultiple:before {
            content: "\e727";
        }

        .e-bpmn-icons.e-Flow:before {
            content: "\e73d";
        }

        .e-bpmn-icons.e-DataStore:before {
            content: "\e73e";
        }

        .e-bpmn-icons.e-NoneStart:before {
            content: "\e71f";
        }

        .e-bpmn-icons.e-ServiceTask:before {
            content: "\e719";
        }

        .e-bpmn-icons.e-InBoCatchEscalation:before {
            content: "\e741";
        }

        .e-bpmn-icons.e-NonInConditional:before {
            content: "\e742";
        }

        .e-bpmn-icons.e-BusinessRule:before {
            content: "\e712";
        }

        .e-bpmn-icons.e-NonInTimer:before {
            content: "\e744";
        }

        .e-bpmn-icons.e-MessageEnd:before {
            content: "\e745";
        }

        .e-bpmn-icons.e-None:before {
            content: "\e726";
        }

        .e-bpmn-icons.e-SequentialMI:before {
            content: "\e71d";
        }

        .e-bpmn-icons.e-ParallelMI:before {
            content: "\e70a";
        }

        .e-bpmn-icons.e-Loop:before {
            content: "\e70e";
        }

        .e-bpmn-icons.e-Compensation:before {
            content: "\e722";
        }

        .e-bpmn-icons.e-SubProcess:before {
            content: "\e700";
        }

        .e-bpmn-icons.e-Task:before {
            content: "\e71b";
        }

        .e-bpmn-icons.e-Call:before {
            content: "\e70b";
        }

        .e-bpmn-icons.e-adhoc:before {
            content: "\e709";
        }

        .e-bpmn-icons.e-Default:before {
            content: "\e71b";
        }

        .e-bpmn-icons.e-Event:before {
            content: "\e708";
        }

        .e-bpmn-icons.e-CallActivity:before {
            content: "\e701";
        }

        .e-bpmn-icons.e-ExclusiveEventBased:before {
            content: "\e71c";
        }

        .e-bpmn-icons.e-Noninterruptingstart:before {
            content: "\e72b";
        }

        .e-bpmn-icons.e-NoninterruptingIntermediate:before {
            content: "\e72a";
        }

        .e-bpmn-icons.e-InstantiatingReceive:before {
            content: "\e72c";
        }

    </style>

    <style>
        @@font-face {
            font-family: 'bpmn-editor-icons';
            font-weight: normal;
            font-style: normal;
        }

        .bpmn-editor-icons {
            font-family: 'bpmn-editor-icons';
            speak: none;
            font-size: 16px;
            font-style: normal;
            font-weight: normal;
            font-variant: normal;
            text-transform: none;
            line-height: 1;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
        /* Style to align palette*/
        .sb-mobile-palette {
            width: 240px;
            height: 100%;
            float: left;
        }

        .sb-mobile-palette-bar {
            display: none;
        }
        /* Style to align diagram*/
        .sb-mobile-diagram {
            width: calc(100% - 242px);
            height: 100%;
            float: left;
        }

        @@media (max-width: 550px) {

            .sb-mobile-palette {
                z-index: 19;
                position: absolute;
                display: none;
                transition: transform 300ms linear, visibility 0s linear 300ms;
                width: 39%;
                height: 100%;
            }

            .sb-mobile-palette-bar {
                display: block;
                width: 100%;
                background: #fafafa;
                padding: 10px 10px;
                border: 0.5px solid #e0e0e0;
                min-height: 40px;
            }

            .sb-mobile-diagram {
                width: 100%;
                height: 100%;
                float: left;
                left: 0px;
            }

            #palette-icon {
                font-size: 20px;
            }
        }

        .sb-mobile-palette-open {
            position: absolute;
            display: block;
            right: 15px;
        }

        .bpmn-editor-icons.e-toggle-palette::before {
            content: "\e700"
        }

        .sb-bpmn-editor {
            border-color: rgba(0, 0, 0, 0.12);
            border-width: 1px 1px 1px 0px;
            border-style: solid;
        }

        @@media (max-width: 550px) {
            .sb-bpmn-editor {
                border-width: 0px 1px 1px;
            }
        }
    </style>

    <script type="text/javascript">
        function contextMenuClick(args) {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            if (diagram.selectedItems.nodes.length > 0) {
                var node = diagram.selectedItems.nodes[0];
                var bpmnShape = diagram.selectedItems.nodes[0].shape;
                if (args.item.iconCss.indexOf('e-adhocs') > -1) {
                    bpmnShape.activity.subProcess.adhoc = args.item.id === 'AdhocNone' ? false : true;
                }
                if (args.item.iconCss.indexOf("e-event") > -1) {
                    bpmnShape.event.event = args.item.id;
                }
                if (args.item.iconCss.indexOf("e-trigger") > -1) {
                    var trigger = args.item.id;
                    trigger = (args.item.id === 'TriggerNone') ? 'None' :
                        (args.item.id === 'triggerCompensation') ? 'Compensation' : args.item.id;
                    bpmnShape.event.trigger = args.item.text;
                }
                if (args.item.iconCss.indexOf("e-loop") > -1) {
                    var loop = (args.item.id === 'LoopNone') ? 'None' : args.item.id;
                    if (bpmnShape.activity.activity === 'Task') {
                        bpmnShape.activity.task.loop = loop;
                    }
                    if (bpmnShape.activity.activity === 'SubProcess') {
                        bpmnShape.activity.subProcess.loop = loop;
                    }
                }
                if (args.item.iconCss.indexOf("e-compensation") > -1) {
                    var compensation = (args.item.id === 'CompensationNone') ? false : true;
                    if (bpmnShape.activity.activity === 'Task') {
                        bpmnShape.activity.task.compensation = compensation;
                    }
                    if (bpmnShape.activity.activity === 'SubProcess') {
                        bpmnShape.activity.subProcess.compensation = compensation;
                    }
                }
                if (args.item.iconCss.indexOf('e-call') > -1) {
                    var compensation = (args.item.id === 'CallNone') ? false : true;
                    if (bpmnShape.activity.activity === 'Task') {
                        bpmnShape.activity.task.call = compensation;
                    }
                }
                if (args.item.id === 'CollapsedSubProcess' || args.item.id === 'ExpandedSubProcess') {
                    if (args.item.id === 'ExpandedSubProcess') {
                        bpmnShape.activity.activity = 'SubProcess';
                        bpmnShape.activity.subProcess.collapsed = false;
                    }
                    else {
                        bpmnShape.activity.activity = 'SubProcess';
                        bpmnShape.activity.subProcess.collapsed = true;
                    }
                }
                if (args.item.iconCss.indexOf('e-boundry') > -1) {
                    var call = args.item.id;
                    if (args.item.id !== 'Default') {
                        call = (args.item.id === 'BoundryEvent') ? 'Event' : 'Call';
                    }
                    bpmnShape.activity.subProcess.boundary = call;
                }
                if (args.item.iconCss.indexOf('e-data') > -1) {
                    var call = args.item.id;
                    if (args.item.id === 'DataObjectNone') {
                        call = 'None';
                    }
                    bpmnShape.dataObject.type = call;
                }
                if (args.item.iconCss.indexOf('e-collection') > -1) {
                    var call = (args.item.id === 'Collectioncollection') ? true : false;
                    bpmnShape.dataObject.collection = call;
                }
                if (args.item.iconCss.indexOf("e-task") > -1) {
                    var task = args.item.id;
                    if (task === 'TaskNone') {
                        task = 'None';
                    }
                    if (bpmnShape.activity.activity === 'Task') {
                        bpmnShape.activity.task.type = task;
                    }
                }
                if (args.item.iconCss.indexOf("e-gate") > -1) {
                    var task = args.item.id;
                    if (task === 'GateWayNone') {
                        task = 'None';
                    }
                    if (task === 'GatewayParallel') {
                        task = 'Parallel';
                    }
                    if (bpmnShape.shape === 'Gateway') {
                        bpmnShape.gateway.type = task;
                    }
                }
                diagram.dataBind();
            }
        }
        function contextMenuOpen(args) {
            var hiddenId = [];
            var diagram = document.getElementById("diagram").ej2_instances[0];

            if (args.element.className !== 'e-menu-parent e-ul ') {
                hiddenId = ['Adhoc', 'Loop', 'taskCompensation', 'Activity-Type', 'Boundry', 'DataObject',
                    'collection', 'DeftCall', 'TriggerResult', 'EventType', 'TaskType', 'GateWay'];
            }
            if (diagram.selectedItems.nodes.length) {
                for (var i = 0; i < args.items.length; i++) {
                    var item = args.items[i];
                    var bpmnShape = diagram.selectedItems.nodes[0].shape;
                    if (bpmnShape.shape !== 'DataObject' && bpmnShape.shape !== 'Gateway') {
                        if (item.text === 'Ad-Hoc') {
                            if (bpmnShape.activity.activity === 'SubProcess') {
                                hiddenId.splice(hiddenId.indexOf(item.id), 1);
                            }
                        }
                        if (item.text === 'Loop' || item.text === 'Compensation' || item.text === 'Activity-Type') {
                            if (bpmnShape.shape === 'Activity') {
                                hiddenId.splice(hiddenId.indexOf(item.id), 1);
                            }
                        }
                        if (item.text === 'Boundry') {
                            if (bpmnShape.activity.activity === 'SubProcess') {
                                hiddenId.splice(hiddenId.indexOf(item.id), 1);
                            }
                        }
                    }
                    if (item.text === 'Data Object') {
                        if (bpmnShape.shape === 'DataObject') {
                            hiddenId.splice(hiddenId.indexOf(item.id), 1);
                        }
                    }
                    if (item.text === 'Collection') {
                        if (bpmnShape.shape === 'DataObject') {
                            hiddenId.splice(hiddenId.indexOf(item.id), 1);
                        }
                    }
                    if (item.text === 'Call') {
                        if (bpmnShape.shape === 'Activity' && bpmnShape.activity.activity === 'Task') {
                            hiddenId.splice(hiddenId.indexOf(item.id), 1);
                        }
                    }
                    if (item.text === 'Trigger Result') {
                        if (bpmnShape.shape === 'Event') {
                            hiddenId.splice(hiddenId.indexOf(item.id), 1);
                        }
                    }
                    if (item.text === 'Event Type') {
                        if (bpmnShape.shape === 'Event') {
                            hiddenId.splice(hiddenId.indexOf(item.id), 1);
                        }
                    }
                    if (item.text === 'Task Type') {
                        if (bpmnShape.shape === 'Activity' && bpmnShape.activity.activity === 'Task') {
                            hiddenId.splice(hiddenId.indexOf(item.id), 1);
                        }
                    }
                    if (item.text === 'GateWay') {
                        if (bpmnShape.shape === 'Gateway') {
                            hiddenId.splice(hiddenId.indexOf(item.id), 1);
                        }
                    }
                    if (args.parentItem && args.parentItem.id === 'TriggerResult' && bpmnShape.shape === 'Event') {
                        var shape = bpmnShape;
                        if (item.text !== 'None' && (item.text === shape.event.event || item.text === shape.event.trigger)) {
                            hiddenId.push(item.id);
                        }
                        if (shape.event.event === 'Start') {
                            if (item.text === 'Cancel' || item.text === 'Terminate' || item.text === 'Link') {
                                hiddenId.push(item.id);
                            }
                        }
                        if (shape.event.event === 'NonInterruptingStart' || item.text === 'Link') {
                            if (item.text === 'Cancel' || item.text === 'Terminate' || item.text === 'Compensation' || item.text === 'Error' || item.text === 'None') {
                                hiddenId.push(item.id);
                            }
                        }
                        if (shape.event.event === 'Intermediate') {
                            if (item.text === 'Terminate') {
                                hiddenId.push(item.id);
                            }
                        }
                        if (shape.event.event === 'NonInterruptingIntermediate') {
                            if (item.text === 'Cancel' || item.text === 'Terminate' || item.text === 'Compensation' ||
                                item.text === 'Error' || item.text === 'None' || item.text === 'Link') {
                                hiddenId.push(item.id);
                            }
                        }
                        if (shape.event.event === 'ThrowingIntermediate') {
                            if (item.text === 'Cancel' || item.text === 'Terminate' || item.text === 'Timer' || item.text === 'Error' ||
                                item.text === 'None' || item.text === 'Pareller' || item.text === 'Conditional') {
                                hiddenId.push(item.id);
                            }
                        }
                        if (shape.event.event === 'End') {
                            if (item.text === 'Parallel' || item.text === 'Timer' || item.text === 'Conditional' || item.text === 'Link') {
                                hiddenId.push(item.id);
                            }
                        }
                    }
                    if (diagram.selectedItems.nodes.length > 0 && args.parentItem && args.parentItem.id === 'EventType' && bpmnShape.shape === 'Event') {
                        if ((item.text === bpmnShape.event.event)) {
                            hiddenId.push(item.id);
                        }
                    }
                }
            }
            args.hiddenItems = hiddenId;
        }
        function dragEnter(args) {
            var obj = args.element;
            if (obj instanceof Node) {
                if (!obj.shape.activity.subProcess.collapsed) {
                    obj.shape.activity.subProcess.transaction.cancel.visible = true;
                    obj.shape.activity.subProcess.transaction.failure.visible = true;
                    obj.shape.activity.subProcess.transaction.success.visible = true;
                }
                else {
                    var oWidth = obj.width;
                    var oHeight = obj.height;
                    var ratio = 100 / obj.width;
                    obj.width = 100;
                    obj.height *= ratio;
                    obj.offsetX += (obj.width - oWidth) / 2;
                    obj.offsetY += (obj.height - oHeight) / 2;
                }
            }
        }

        function getSymbolNodes(symbol, diagram) {
            symbol.style.strokeColor = '#757575';
        }

        function fitToPage() {
            var diagram = document.getElementById("diagram").ej2_instances[0];
            addEvents();
            // Ensure diagram is fully rendered
            setTimeout(function () {
                diagram.fitToPage();
            }, 100);
        }

        function addEvents() {
            var isMobile = window.matchMedia('(max-width:550px)').matches;
            if (isMobile) {
                var paletteIcon = document.getElementById('palette-icon');
                if (paletteIcon) {
                    paletteIcon.addEventListener('click', openPalette, false);
                }
            }
        }
        @*custom code start*@
        function openPalette() {
            var paletteSpace = document.getElementById('palette-space');
            var isMobile = window.matchMedia('(max-width:550px)').matches;
            if (isMobile) {
                if (!paletteSpace.classList.contains('sb-mobile-palette-open')) {
                    paletteSpace.classList.add('sb-mobile-palette-open');
                }
                else {
                    paletteSpace.classList.remove('sb-mobile-palette-open');
                }
            }
        }
        @*custom code end*@
    </script>

}

```

### src/components/diagram-bpmn-editor/DiagramController.cs

```cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
using System.ComponentModel;
using Syncfusion.EJ2;
using Newtonsoft.Json;

namespace EJ2MVCSampleBrowser.Controllers.Diagram
{
    public partial class DiagramController : Controller
    {
        public ActionResult BPMNEditor()
        {
            // Sets the Annotation for the Node         
            
            List<SymbolPalettePalette> palettes = new List<SymbolPalettePalette>();
            palettes.Add(new SymbolPalettePalette() { Id = "BPMN", Expanded = true, Symbols = GetBPMNShapes(), IconCss = "e-ddb-icons e-basic", Title = "BPMN Shapes" });
            palettes.Add(new SymbolPalettePalette() { Id = "Connector", Expanded = true, Symbols = GetBPMNConnectors(), IconCss = "e-ddb-icons e-basic", Title = "Connectors" });

            ViewData["Nodes"] = GetBPMNDiagramNodes();
            ViewData["Connectors"] = GetBPMNDiagramConnectors();
            ViewData["Palettes"] = palettes;
            ViewData["getSymbolNode"] = "getSymbolNodes";
            ViewData["ContextMenuItems"] = GetContextMenuItems();

            return View("~/Views/Home/diagram/bpmn-editor/Diagram.cshtml");

        }
        public ContextMenuItem AddItems(string text, string id, string iconCss, string target, List<ContextMenuItem> content)
        {
            ContextMenuItem item = new ContextMenuItem()
            {
                Id = id,
                Text = text,
                Target = target,
                IconCss = iconCss,
                Items = content
            };
            return item;
        }

        public DiagramNode AddBpmnEvent(string Id, double width, double height, double offSetX, double offsetY, BpmnEvents events, DiagramMargin margin, List<DiagramNodeAnnotation> annotation, BpmnTriggers trigger = BpmnTriggers.None)
        {
            DiagramNode node = new DiagramNode();
            node.Id = Id;
            node.Width = width;
            node.Height = height;
            node.OffsetX = offSetX;
            node.OffsetY = offsetY;
            node.Margin = margin;
            node.Annotations = annotation;
            node.Shape = new BpmnShapes()
            {
                Type = "Bpmn",
                Shape = "Event",
                Event = new DiagramBpmnEvent() { Event = events, Trigger = trigger },
            };
            return node;
        }

        public DiagramConnector AddConnector(string Id, string SourceID, string SourcePortID, string TargetID, Segments type, List<DiagramConnectorAnnotation> annotation, DiagramMargin margin, DiagramStrokeStyle style)
        {
            DiagramConnector connector = new DiagramConnector();
            connector.Id = Id;
            connector.SourceID = SourceID;
            if (SourcePortID != "")
            {
                connector.SourcePortID = SourcePortID;
            }
            connector.TargetID = TargetID;
            connector.Type = type;
            connector.Annotations = annotation;
            connector.Style = style;
            connector.Margin = margin;
            return connector;
        }

        public List<DiagramNode> GetBPMNDiagramNodes()
        {
            List<DiagramNode> nodes = new List<DiagramNode>();
            List<DiagramNodeAnnotation> annotation = new List<DiagramNodeAnnotation>();

            nodes.Add(AddBpmnEvent("start", 40, 40, 35, 180, BpmnEvents.Start, new DiagramMargin() { }, annotation));
            nodes.Add(new DiagramNode()
            {
                Id = "subProcess",
                Width = 520,
                Height = 250,
                OffsetX = 355,
                OffsetY = 180,
                Constraints = NodeConstraints.Default | NodeConstraints.AllowDrop,
                Shape = new BpmnShapes()
                {
                    Shape = "Activity",
                    Type = "Bpmn",
                    Activity = new DiagramBpmnActivity()
                    {
                        Activity = BpmnActivities.SubProcess,
                        SubProcess = new DiagramBpmnSubProcess()
                        {
                            Type = BpmnSubProcessTypes.Transaction,
                            Collapsed = false,
                            Processes = new string[] {"processesStart", "service", "compensation", "processesTask",
                           "error", "processesEnd", "user", "subProcessesEnd"}
                        }
                    }
                }
            });

            nodes.Add(AddBpmnEvent("cancelledEnd", 40, 40, 545, 370, BpmnEvents.End, new DiagramMargin() { }, annotation));
            nodes.Add(AddBpmnEvent("end", 40, 40, 665, 180, BpmnEvents.End, new DiagramMargin() { }, annotation));

            nodes.Add(AddBpmnEvent("processesStart", 30, 30, 0, 0, BpmnEvents.Start, new DiagramMargin() { Left = 40, Top = 80 }, annotation));

            nodes.Add(AddBpmnEvent("error", 30, 30, 0, 0, BpmnEvents.Intermediate, new DiagramMargin() { Top = 100, Left = 350 }, annotation, BpmnTriggers.Error));
            nodes.Add(AddBpmnEvent("processesEnd", 30, 30, 0, 0, BpmnEvents.End, new DiagramMargin() { Top = 80, Left = 440 }, annotation));

            List<DiagramNodeAnnotation> nodeAnnotation4 = new List<DiagramNodeAnnotation>();
            nodeAnnotation4.Add(new DiagramNodeAnnotation()
            {
                Id = "serviceLabel2",
                Content = "Cancel hotel reservation",
                Style = new DiagramTextStyle() { Color = "white" },
                Offset = new DiagramPoint() { X = 0.5, Y = 0.6 },
                Margin = new DiagramMargin() { Top = 240, Left = 160 }
            });
            nodes.Add(new DiagramNode()
            {
                Id = "user",
                Width = 90,
                Height = 80,

                Shape = new BpmnShapes()
                {
                    Shape = "Activity",
                    Type = "Bpmn",
                    Activity = new DiagramBpmnActivity()
                    {
                        Activity = BpmnActivities.Task,
                        Task = new DiagramBpmnTask()
                        {
                            Type = BpmnTasks.User,
                            Compensation = true
                        }
                    }
                },
                Margin = new DiagramMargin() { Left = 240, Top = 160 },
                Style = new DiagramTextStyle { Fill = "#E94649" },
                Annotations = nodeAnnotation4
            });
            nodes.Add(AddBpmnEvent("subProcessesEnd", 30, 30, 0, 0, BpmnEvents.End, new DiagramMargin() { Top = 210, Left = 440 }, annotation));
            return nodes;
        }

        public List<DiagramConnector> GetBPMNDiagramConnectors()
        {
            List<DiagramConnector> connectors = new List<DiagramConnector>();
            List<DiagramConnectorAnnotation> cAnnotation = new List<DiagramConnectorAnnotation>();
            connectors.Add(AddConnector("connector1", "start", "", "subProcess", Segments.Orthogonal, cAnnotation, new DiagramMargin() { }, new DiagramStrokeStyle() { }));
            connectors.Add(AddConnector("connector2", "subProcess", "success", "end", Segments.Orthogonal, cAnnotation, new DiagramMargin() { }, new DiagramStrokeStyle() { }));
            List<DiagramConnectorAnnotation> annotation1 = new List<DiagramConnectorAnnotation>();
            return connectors;
        }

        public List<DiagramNode> GetBPMNShapes()
        {
            List<DiagramNodeAnnotation> annotation = new List<DiagramNodeAnnotation>();
            List<DiagramNode> bpmnNodes = new List<DiagramNode>();
            bpmnNodes.Add(AddBpmnEvent("start", 35, 35, 0, 0, BpmnEvents.Start, new DiagramMargin() { }, annotation));
            bpmnNodes.Add(AddBpmnEvent("nonInterruptingIntermediate", 35, 35, 0, 0, BpmnEvents.NonInterruptingIntermediate, new DiagramMargin() { }, annotation));
            bpmnNodes.Add(AddBpmnEvent("end", 35, 35, 0, 0, BpmnEvents.End, new DiagramMargin() { }, annotation));
            bpmnNodes.Add(new DiagramNode()
            {
                Id = "Task",
                Width = 35,
                Height = 35,
                OffsetX = 700,
                OffsetY = 700,
                Shape = new BpmnShapes() { Type = "Bpmn", Shape = "Activity", Activity = new DiagramBpmnActivity() { Activity = BpmnActivities.Task } }
            });
           
            return bpmnNodes;
        }

        public List<DiagramConnector> GetBPMNConnectors()
        {
            List<DiagramConnector> connectors = new List<DiagramConnector>();
            connectors.Add(new DiagramConnector()
            {
                Id = "Link1",
                Type = Segments.Orthogonal,
                SourcePoint = new DiagramPoint() { X = 0, Y = 0 },
                TargetPoint = new DiagramPoint() { X = 40, Y = 40 },
                TargetDecorator = new DiagramDecorator() { Shape = DecoratorShapes.Arrow, Style = new DiagramShapeStyle() { StrokeColor = "#757575", Fill = "#757575" } },
                Style = new DiagramStrokeStyle() { StrokeWidth = 2, StrokeColor = "#757575" }
            });
            connectors.Add(new DiagramConnector()
            {
                Id = "Link2",
                Type = Segments.Orthogonal,
                SourcePoint = new DiagramPoint() { X = 0, Y = 0 },
                TargetPoint = new DiagramPoint() { X = 40, Y = 40 },
                TargetDecorator = new DiagramDecorator() { Shape = DecoratorShapes.Arrow, Style = new DiagramShapeStyle() { StrokeColor = "#757575", Fill = "#757575" } },
                Style = new DiagramStrokeStyle() { StrokeWidth = 2, StrokeDashArray = "4 4", StrokeColor = "#757575" }
            });
            return connectors;
        }

        public List<ContextMenuItem> GetContextMenuItems()
        {
            List<ContextMenuItem> item = new List<ContextMenuItem>();
            List<ContextMenuItem> adHocItem = new List<ContextMenuItem>();
            adHocItem.Add(AddItems("None", "AdhocNone", "e-adhocs e-bpmn-icons e-None", "", new List<ContextMenuItem>() { }));
            adHocItem.Add(AddItems("Ad-Hoc", "AdhocAdhoc", "e-adhocs e-bpmn-icons e-adhoc", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Ad-Hoc", "Adhoc", "", "", adHocItem));
            List<ContextMenuItem> loopItem = new List<ContextMenuItem>();
            loopItem.Add(AddItems("None", "LoopNone", "e-loop e-bpmn-icons e-None", "", new List<ContextMenuItem>() { }));
            loopItem.Add(AddItems("Standard", "Standard", "e-loop e-bpmn-icons e-Loop", "", new List<ContextMenuItem>() { }));
            loopItem.Add(AddItems("Parallel Multi-Instance", "ParallelMultiInstance", "e-loop e-bpmn-icons e-ParallelMI", "", new List<ContextMenuItem>() { }));
            loopItem.Add(AddItems("Sequence Multi-Instance", "SequenceMultiInstance", "e-loop e-bpmn-icons e-SequentialMI", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Loop", "Loop", "", ".e-diagramcontent", loopItem));
            List<ContextMenuItem> compensationItem = new List<ContextMenuItem>();
            compensationItem.Add(AddItems("None", "CompensationNone", "e-compensation e-bpmn-icons e-None", "", new List<ContextMenuItem>() { }));
            compensationItem.Add(AddItems("Compensation", "CompensationCompensation", "e-compensation e-bpmn-icons e-Compensation", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Compensation", "taskCompensation", "", "", compensationItem));
            List<ContextMenuItem> activityItem = new List<ContextMenuItem>();
            activityItem.Add(AddItems("Expanded sub - process", "ExpandedSubProcess", "e-bpmn-icons e-SubProcess", "", new List<ContextMenuItem>() { }));
            activityItem.Add(AddItems("Collapsed sub-process", "CollapsedSubProcess", "e-bpmn-icons e-Task", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Activity-Type", "Activity-Type", "", "", activityItem));
            List<ContextMenuItem> DataItem = new List<ContextMenuItem>();
            DataItem.Add(AddItems("None", "DataObjectNone", "e-data e-icons e-dataobject", "", new List<ContextMenuItem>() { }));
            DataItem.Add(AddItems("Input", "Input", "e-data e-icons e-datainput", "", new List<ContextMenuItem>() { }));
            DataItem.Add(AddItems("Output", "Output", "e-data e-icons e-dataoutput", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Data Object", "DataObject", "", "", DataItem));
            List<ContextMenuItem> boundryItem = new List<ContextMenuItem>();
            boundryItem.Add(AddItems("Default", "Default", "e-boundry e-bpmn-icons e-Default", "", new List<ContextMenuItem>() { }));
            boundryItem.Add(AddItems("Call", "BoundryCall", "e-boundry e-bpmn-icons e-Call", "", new List<ContextMenuItem>() { }));
            boundryItem.Add(AddItems("Event", "BoundryEvent", "e-boundry e-bpmn-icons e-Event", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Boundry", "Boundry", "", "", boundryItem));
            List<ContextMenuItem> collectionItem = new List<ContextMenuItem>();
            collectionItem.Add(AddItems("None", "collectionNone", "e-collection e-bpmn-icons e-None", "", new List<ContextMenuItem>() { }));
            collectionItem.Add(AddItems("Collection", "Collectioncollection", "e-collection e-bpmn-icons e-ParallelMI", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Collection", "collection", "", "", collectionItem));
            List<ContextMenuItem> callItem = new List<ContextMenuItem>();
            callItem.Add(AddItems("None", "CallNone", "e-call e-bpmn-icons e-None", "", new List<ContextMenuItem>() { }));
            callItem.Add(AddItems("Call", "CallCall", "e-call e-bpmn-icons e-CallActivity", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Call", "DeftCall", "", "", callItem));
            List<ContextMenuItem> TriggerItem = new List<ContextMenuItem>();
            TriggerItem.Add(AddItems("None", "TriggerNone", "e-trigger e-bpmn-icons e-None", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Message", "Message", "e-trigger e-bpmn-icons e-InMessage", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Parallel", "Parallel", "e-trigger e-bpmn-icons e-InParallelMultiple", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Multiple", "Multiple", "e-trigger e-bpmn-icons e-InMultiple", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Signal", "Signal", "e-trigger e-bpmn-icons e-InSignal", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Timer", "Timer", "e-trigger e-bpmn-icons e-InTimer", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Escalation", "Escalation", "e-trigger e-bpmn-icons e-InEscalation", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Error", "Error", "e-trigger e-bpmn-icons e-InError", "", new List<ContextMenuItem>() { }));
            TriggerItem.Add(AddItems("Link", "Link", "e-trigger e-bpmn-icons e-ThrowLinkin", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Trigger Result", "TriggerResult", "", "", TriggerItem));
            List<ContextMenuItem> EventItem = new List<ContextMenuItem>();
            EventItem.Add(AddItems("Start", "Start", "e-event e-bpmn-icons e-NoneStart", "", new List<ContextMenuItem>() { }));
            EventItem.Add(AddItems("Intermediate", "NonInterruptingStart", "e-event e-bpmn-icons e-InterruptingNone", "", new List<ContextMenuItem>() { }));
            EventItem.Add(AddItems("NonInterruptingStart", "NonInterruptingStart", "e-event e-bpmn-icons e-Noninterruptingstart", "", new List<ContextMenuItem>() { }));
            EventItem.Add(AddItems("ThrowingIntermediate", "ThrowingIntermediate", "e-event e-bpmn-icons e-ThrowingIntermediate", "", new List<ContextMenuItem>() { }));
            EventItem.Add(AddItems("NonInterruptingIntermediate", "NonInterruptingIntermediate", "e-event e-bpmn-icons e-NoninterruptingIntermediate", "", new List<ContextMenuItem>() { }));
            EventItem.Add(AddItems("End", "End", "e-event e-bpmn-icons e-NoneEnd", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Event Type", "EventType", "", "", EventItem));
            List<ContextMenuItem> taskItem = new List<ContextMenuItem>();
            taskItem.Add(AddItems("None", "TaskNone", "e-task e-bpmn-icons e-None", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("Service", "Service", "e-task e-bpmn-icons e-ServiceTask", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("BusinessRule", "BusinessRule", "e-task e-bpmn-icons e-BusinessRule", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("InstantiatingReceive", "InstantiatingReceive", "e-task e-bpmn-icons e-InstantiatingReceive", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("Manual", "Manual", "e-task e-bpmn-icons e-ManualCall", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("Receive", "Receive", "e-task e-bpmn-icons e-InMessage", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("Script", "Script", "e-bpmn-icons e-ScriptCall", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("Send", "Send", "e-task e-bpmn-icons e-OutMessage", "", new List<ContextMenuItem>() { }));
            taskItem.Add(AddItems("User", "User", "e-task e-bpmn-icons e-UserCall", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("Task Type", "TaskType", "", "", taskItem));
            List<ContextMenuItem> gateWayItem = new List<ContextMenuItem>();
            gateWayItem.Add(AddItems("None", "GateWayNone", "e-gate e-bpmn-icons e-Gateway", "", new List<ContextMenuItem>() { }));
            gateWayItem.Add(AddItems("Inclusive", "Inclusive", "e-gate e-bpmn-icons e-InclusiveGateway", "", new List<ContextMenuItem>() { }));
            gateWayItem.Add(AddItems("Complex", "Complex", "e-gate e-bpmn-icons e-ComplexGateway", "", new List<ContextMenuItem>() { }));
            gateWayItem.Add(AddItems("ExclusiveEventBased", "e-gate e-bpmn-icons e-ExclusiveEventBased", "", "", new List<ContextMenuItem>() { }));
            gateWayItem.Add(AddItems("Exclusive", "Exclusive", "e-gate e-bpmn-icons e-ExclusiveGatewayWithMarker", "", new List<ContextMenuItem>() { }));
            gateWayItem.Add(AddItems("Parallel", "GatewayParallel", "e-gate e-bpmn-icons e-ParallelGateway", "", new List<ContextMenuItem>() { }));
            gateWayItem.Add(AddItems("EventBased", "EventBased", "e-gate e-bpmn-icons e-EventBasedGateway", "", new List<ContextMenuItem>() { }));
            gateWayItem.Add(AddItems("ParallelEventBased", "ParallelEventBased", "e-gate e-bpmn-icons e-ParallelEventBasedGatewayToStart", "", new List<ContextMenuItem>() { }));
            item.Add(AddItems("GateWay", "GateWay", "", "", gateWayItem));
            return item;
        }

    }
    public class ContextMenuItem
    {
        [DefaultValue(null)]
        
        [JsonProperty("text")]
        public string Text
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("id")]
        public string Id
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("target")]
        public string Target
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("iconCss")]
        public string IconCss
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("items")]
        public List<ContextMenuItem> Items
        {
            get;
            set;
        }
    }

    public class BpmnShapes
    {
        [DefaultValue(null)]
        
        [JsonProperty("type")]
        public string Type
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("shape")]
        public string Shape
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("activity")]
        public DiagramBpmnActivity Activity
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("event")]
        public DiagramBpmnEvent Event
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("gateway")]
        public DiagramBpmnGateway Gateway
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("dataObject")]
        public DiagramBpmnDataObject dataObject
        {
            get;
            set;
        }
    }
    public class BpmnConnectors
    {
        [DefaultValue(null)]
        
        [JsonProperty("type")]
        public string Type
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("flow")]
        public string Flow
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("association")]
        public string Association
        {
            get;
            set;
        }
    }
    public class Segment
    {
        [DefaultValue(null)]
        
        [JsonProperty("type")]
        public Segments Type
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("length")]
        public double Length
        {
            get;
            set;
        }
        [DefaultValue(null)]
        
        [JsonProperty("direction")]
        public string Direction
        {
            get;
            set;
        }
    }
}

```
