We will make use of ASP.NET MVC 5 web platform and Web API 2 controller for REST API to create a Gantt application.
To organize communication with database we will use the Entity Framework.
We will build our application with the help of the Visual Studio IDE.

Creating Models

Now we define model classes for the gantt chart. A Gantt data model consists of Links and Tasks.
As you can see, dhtmlxGantt uses a certain naming convention for data model that is different from the one traditionally used in C#.
The client-side model can also contain some properties that shouldn't be stored in a database, but will be used either on the client or in the backend logic.

Because of this, we'll go with the Data Transfer Object pattern here: we'll define domain model classes that will be used with EF and inside the app,
and DTO classes that will be used to communicate with Web API. Then we'll implement some kind of mapping between the two models.

Let's start!

Task Model

First, we will create a class for Task. Its content can be similar to this one:

Adding initial records to database

The Entity Framework can automatically create a database when an application runs.
We should specify that a database should be dropped and re-created whenever the model changes.

First, we should create a database initializer. For this purpose, we need to add a new class in the App_Start folder
that will be inherited from the DropCreateDatabaseIfModelChanges class. Let's call it "GanttInitializer".

In this class we are going to redefine the Seed() method to populate it with test data.
Then we will add the entities collection into the context with the AddRange() method.

Open the Global.asax file. It contains the code that runs on the application start.
Add the necessary namespace and the code line that will set Initializer for our context into the Application_Start() method:

General technique of loading data using REST API

Finally it's time to implement the API.

As you can see from the API details we'll need two controllers: one for tasks and one for links.
We will also need one more controller for the 'load data' action, since gantt expects a mixed result there.

Task Controller

Activate the context menu for the Controllers folder and select Add -> Controller.
Choose the Web API 2 Controller -> Empty. The new controller will be called "TaskController".

Now if any Web API controller fires an exception while processing the request,
the client side will receive an error status and an error message that can be either somehow processed or shown to the user.

Note that returning an exception message to the client might not be the best idea for a production environment.

Gantt doesn't provide any means of preventing an application from various threats, such as SQL injections or XSS and CSRF attacks. It is important that responsibility for keeping an application safe is on the developers implementing the backend. Read the details in the corresponding article.