Resources in Syncfusion® ASP.NET CORE Gantt Component
6 Dec 202424 minutes to read
In Gantt, the resources are represented by staff, equipment and materials etc. In Gantt control you can show or allocate the resources (human resources) for each task.
Resource collection
The resource collection contains details about resources that are used in the project. Resources are JSON object that contains id, name, unit and group of the resources and this collection is mapped to the Gantt control using the resources
property. These resource fields are mapped to the Gantt control using the resourceFields
property.
Resource fields | Description |
---|---|
id |
This field is used to assign resources to the tasks. |
name |
This field is used to map the resource names. These names are displayed as one of Gantt columns and also can display as labels using the labelSettings property. |
unit |
It indicates the amount of work that can be done by a resource for the task in a day. |
group |
This field is used to group the resources and the tasks assigned to that particular resource into category. |
The following code snippets shows resource collection and how it assigned to Gantt control.
@{
......
//Gantt Resource Collection
List<GanttResources> GanttResourcesCollection = new List<GanttResources>();
GanttResources Record13 = new GanttResources()
{
ResourceId = 1,
ResourceName = "Martin Tamer"
};
GanttResources Record14 = new GanttResources()
{
ResourceId = 2,
ResourceName = "Rose Fuller"
};
GanttResources Record3 = new GanttResources()
{
ResourceId = 3,
ResourceName = "Margaret Buchanan"
};
GanttResources Record4 = new GanttResources()
{
ResourceId = 4,
ResourceName = "Fuller King"
};
GanttResources Record5 = new GanttResources()
{
ResourceId = 5,
ResourceName = "Davolio Fuller"
};
GanttResources Record6 = new GanttResources()
{
ResourceId = 6,
ResourceName = "Van Jack"
};
GanttResources Record7 = new GanttResources()
{
ResourceId = 7,
ResourceName = "Fuller Buchanan"
};
GanttResources Record8 = new GanttResources()
{
ResourceId = 8,
ResourceName = "Jack Davolio"
};
GanttResources Record9 = new GanttResources()
{
ResourceId = 9,
ResourceName = "Tamer Vinet"
};
GanttResources Record10 = new GanttResources()
{
ResourceId = 10,
ResourceName = "Vinet Fuller"
};
GanttResources Record11 = new GanttResources()
{
ResourceId = 11,
ResourceName = "Bergs Anton"
};
GanttResources Record12 = new GanttResources()
{
ResourceId = 12,
ResourceName = "Construction Supervisor"
};
GanttResourcesCollection.Add(Record13);
GanttResourcesCollection.Add(Record14);
GanttResourcesCollection.Add(Record3);
GanttResourcesCollection.Add(Record4);
GanttResourcesCollection.Add(Record5);
GanttResourcesCollection.Add(Record6);
GanttResourcesCollection.Add(Record7);
GanttResourcesCollection.Add(Record8);
GanttResourcesCollection.Add(Record9);
GanttResourcesCollection.Add(Record10);
GanttResourcesCollection.Add(Record11);
GanttResourcesCollection.Add(Record12);
//Gantt Data Source Collection
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 50,
ResourceId = new int[] { 1 },
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 50,
Predecessor = "2FS",
ResourceId = new int[] { 2, 3, 5 },
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Predecessor="3FS",
Progress = 50,
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 04),
Duration = 3,
Progress = 50,
ResourceId = new int[] { 4 },
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 04),
Duration = 3,
Progress = 50,
Predecessor = "6SS",
ResourceId = new int[] { 4, 8 },
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
}
<ejs-gantt id='Gantt' dataSource="GanttDataSourceCollection" allowSorting="true" allowFiltering="true" height="450px" resources="GanttResourcesCollection">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks" resourceInfo="ResourceId" dependency="Predecessor">
</e-gantt-taskfields>
<e-gantt-labelSettings rightLabel="${if(ResourceId)}${ResourceId}${/if}"></e-gantt-labelSettings>
<e-gantt-resourcefields id="ResourceId" name="ResourceName" unit="Unit">
</e-gantt-resourcefields>
</ejs-gantt>
public IActionResult Index()
{
ViewBag.DataSource = ganttData();
ViewBag.projectResources = projectResources();
return View();
}
public static List<GanttResources> projectResources()
{
List<GanttResources> GanttResourcesCollection = new List<GanttResources>();
GanttResources Record1 = new GanttResources()
{
ResourceId = 1,
ResourceName = "Martin Tamer"
};
GanttResources Record2 = new GanttResources()
{
ResourceId = 2,
ResourceName = "Rose Fuller"
};
GanttResources Record3 = new GanttResources()
{
ResourceId = 3,
ResourceName = "Margaret Buchanan"
};
GanttResources Record4 = new GanttResources()
{
ResourceId = 4,
ResourceName = "Fuller King"
};
GanttResources Record5 = new GanttResources()
{
ResourceId = 5,
ResourceName = "Davolio Fuller"
};
GanttResources Record6 = new GanttResources()
{
ResourceId = 6,
ResourceName = "Van Jack"
};
GanttResources Record7 = new GanttResources()
{
ResourceId = 7,
ResourceName = "Fuller Buchanan"
};
GanttResources Record8 = new GanttResources()
{
ResourceId = 8,
ResourceName = "Jack Davolio"
};
GanttResources Record9 = new GanttResources()
{
ResourceId = 9,
ResourceName = "Tamer Vinet"
};
GanttResources Record10 = new GanttResources()
{
ResourceId = 10,
ResourceName = "Vinet Fuller"
};
GanttResources Record11 = new GanttResources()
{
ResourceId = 11,
ResourceName = "Bergs Anton"
};
GanttResources Record12 = new GanttResources()
{
ResourceId = 12,
ResourceName = "Construction Supervisor"
};
GanttResourcesCollection.Add(Record1);
GanttResourcesCollection.Add(Record2);
GanttResourcesCollection.Add(Record3);
GanttResourcesCollection.Add(Record4);
GanttResourcesCollection.Add(Record5);
GanttResourcesCollection.Add(Record6);
GanttResourcesCollection.Add(Record7);
GanttResourcesCollection.Add(Record8);
GanttResourcesCollection.Add(Record9);
GanttResourcesCollection.Add(Record10);
GanttResourcesCollection.Add(Record11);
GanttResourcesCollection.Add(Record12);
return GanttResourcesCollection;
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 50,
ResourceId = new int[] { 1 },
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 50,
ResourceId = new int[] { 2, 3, 5 },
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 50,
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 04),
Duration = 3,
Progress = 50,
ResourceId = new int[] { 4 },
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 04),
Duration = 3,
Progress = 50,
ResourceId = new int[] { 4, 8 },
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class GanttResources
{
public int ResourceId { get; set; }
public string ResourceName { get; set; }
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
public int[] ResourceId { get; set; }
}
Assign resource
We can assign resources for a task at initial load, using the resource id value of the resources as a collection. This collection is mapped from the dataSource to the Gantt control using the resourceInfo
property.
Resources are assigned to tasks in following ways.
Assign resource alone
If the unit is not specified for specific resource, the amount of work done will be consider as 100% by default. In such cases, the resource unit will not be displayed in Gantt UI.
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 50,
ResourceId = new int[] { 1 },
};
Assign resources with unit
We can assign the quantity of work done by the resources for the specific task as like below code snippet.
GanttDataSource Record1Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify Site location",
StartDate = new DateTime(2019, 03, 29),
Duration = 2,
Progress = 30,
Work = 10,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 1, Unit = 50 }
}
};
When resource unit is defined in resource collection, the amount of work done by that particular resource will be same for all the tasks.
The following code snippet shows how to assign the resource for each task and map to Gantt control.
<ejs-gantt id='Resources' dataSource="ViewBag.dataSource"
treeColumnIndex="1" height="450px" allowSelection="true" highlightWeekends="true"
resources="ViewBag.projectResources"
projectStartDate="03/25/2019" projectEndDate="07/28/2019"
toolbar="@(new List<string>() { "Add", "Edit", "Update", "Delete", "Cancel", "ExpandAll", "CollapseAll" })">
<e-gantt-resourcefields id="ResourceId" name="ResourceName" unit="Unit">
</e-gantt-resourcefields>
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress"
resourceInfo="Resources" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-labelSettings rightLabel="Resources"></e-gantt-labelSettings>
<e-gantt-columns>
<e-gantt-column field="TaskId" width="100" visible="false"></e-gantt-column>
<e-gantt-column field="TaskName" headerText="Task Name"></e-gantt-column>
<e-gantt-column field="Resources" headerText="Resources"></e-gantt-column>
<e-gantt-column field="Duration" width="100"></e-gantt-column>
</e-gantt-columns>
</ejs-gantt>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication8Core.Models;
using Syncfusion.EJ2.Gantt;
namespace WebApplication8Core.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.DataSource = ganttData();
ViewBag.projectResources = projectResources();
return View();
}
public static List<GanttResources> projectResources()
{
List<GanttResources> GanttResourcesCollection = new List<GanttResources>();
GanttResources Record1 = new GanttResources()
{
ResourceId = 1,
ResourceName = "Martin Tamer"
};
GanttResources Record2 = new GanttResources()
{
ResourceId = 2,
ResourceName = "Rose Fuller"
};
GanttResources Record3 = new GanttResources()
{
ResourceId = 3,
ResourceName = "Margaret Buchanan"
};
GanttResources Record4 = new GanttResources()
{
ResourceId = 4,
ResourceName = "Fuller King"
};
GanttResources Record5 = new GanttResources()
{
ResourceId = 5,
ResourceName = "Davolio Fuller"
};
GanttResources Record6 = new GanttResources()
{
ResourceId = 6,
ResourceName = "Van Jack"
};
GanttResources Record7 = new GanttResources()
{
ResourceId = 7,
ResourceName = "Fuller Buchanan"
};
GanttResources Record8 = new GanttResources()
{
ResourceId = 8,
ResourceName = "Jack Davolio"
};
GanttResources Record9 = new GanttResources()
{
ResourceId = 9,
ResourceName = "Tamer Vinet"
};
GanttResources Record10 = new GanttResources()
{
ResourceId = 10,
ResourceName = "Vinet Fuller"
};
GanttResources Record11 = new GanttResources()
{
ResourceId = 11,
ResourceName = "Bergs Anton"
};
GanttResources Record12 = new GanttResources()
{
ResourceId = 12,
ResourceName = "Construction Supervisor"
};
GanttResourcesCollection.Add(Record1);
GanttResourcesCollection.Add(Record2);
GanttResourcesCollection.Add(Record3);
GanttResourcesCollection.Add(Record4);
GanttResourcesCollection.Add(Record5);
GanttResourcesCollection.Add(Record6);
GanttResourcesCollection.Add(Record7);
GanttResourcesCollection.Add(Record8);
GanttResourcesCollection.Add(Record9);
GanttResourcesCollection.Add(Record10);
GanttResourcesCollection.Add(Record11);
GanttResourcesCollection.Add(Record12);
return GanttResourcesCollection;
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 03, 29),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Record1Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify Site location",
StartDate = new DateTime(2019, 03, 29),
Duration = 2,
Progress = 30,
Work = 10,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 1, Unit = 50 }
}
};
GanttDataSource Record1Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 03, 29),
Duration = 4,
Progress = 30,
Work = 20,
Resources = new List<ResourceModel>
{
new ResourceModel { ResourceId = 2, Unit = 70 }
}
};
GanttDataSource Record1Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 03, 29),
Duration = 1,
Progress = 30,
Work = 10,
Resources = new List<ResourceModel> {
new ResourceModel { ResourceId = 3, Unit = 25 },
new ResourceModel { ResourceId = 1, Unit = 75 },
}
};
Record1.SubTasks.Add(Record1Child1);
Record1.SubTasks.Add(Record1Child2);
Record1.SubTasks.Add(Record1Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 03, 29),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Record2Child1 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 03, 29),
Duration = 3,
Progress = 30,
Work = 30,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 4, Unit = 50 },
new ResourceModel{ ResourceId = 2, Unit = 70 }
}
};
GanttDataSource Record2Child2 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 01),
Duration = 3,
Progress = 30,
Work = 40,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 6, Unit = 40 }
}
};
GanttDataSource Record2Child3 = new GanttDataSource()
{
TaskId = 8,
TaskName = "Estimation approval",
StartDate = new DateTime(2019, 04, 01),
Duration = 2,
Progress = 30,
Work = 60,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 5, Unit = 75 }
}
};
Record2.SubTasks.Add(Record2Child1);
Record2.SubTasks.Add(Record2Child2);
Record2.SubTasks.Add(Record2Child3);
GanttDataSource Record3 = new GanttDataSource()
{
TaskId = 9,
TaskName = "Sign contract",
StartDate = new DateTime(2019, 04, 01),
Duration = 1,
Progress = 30,
};
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
GanttDataSourceCollection.Add(Record3);
return GanttDataSourceCollection;
}
public class GanttResources
{
public int ResourceId { get; set; }
public string ResourceName { get; set; }
public Nullable<int> Unit { get; set; }
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
public int[] ResourceId { get; set; }
public List<ResourceModel> Resources { get; set; }
public int Work { get; set; }
}
public class ResourceModel
{
public int ResourceId { get; set; }
public Nullable<int> Unit { get; set; }
}
}
}
Add/Edit resource collection
By using cell/ dialog edit option, we can add/remove the multiple resources for a particular task. Resource Unit can be change for a each task on resource tab in edit dialog by double click on the unit cell.
Custom background colors for resource column and taskbar
In the Gantt Component, you can customize the background colors of the resource column and taskbars based on the resources assigned to each task. This customization enhances the readability and usability of the Gantt chart.
To achieve this, utilize the template property for the resource column and the queryTaskbarInfo event. The template
property allows you to define a custom template for the resource column, while the queryTaskbarInfo
event to modify the taskbar properties, including background colors.
The following code snippet demonstrates how to customize the background colors of the taskbar and resource column according to the assigned resources:
<ejs-gantt id='resAllocation' dataSource="ViewBag.dataSource" resources="ViewBag.projectResources" highlightWeekends="true"
height="450px" queryTaskbarInfo="queryTaskbarInfo">
<e-gantt-columns>
<e-gantt-column field="TaskName" headerText="Task Name" width="270"></e-gantt-column>
<e-gantt-column field="Resources" width="175" template="#resColumnTemplate"></e-gantt-column>
<e-gantt-column field="StartDate"></e-gantt-column>
<e-gantt-column field="Duration"></e-gantt-column>
</e-gantt-columns>
<e-gantt-labelSettings rightLabel="Resources"></e-gantt-labelSettings>
<e-gantt-splitterSettings columnIndex="2"></e-gantt-splitterSettings>
<e-gantt-resourcefields id="ResourceId" name="ResourceName">
</e-gantt-resourcefields>
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress"
child="SubTasks" resourceInfo="Resources">
</e-gantt-taskfields>
</ejs-gantt>
<script>
function queryTaskbarInfo(args) {
if(args.data.Resources === 'Martin Tamer'){
args.taskbarBgColor = '#DFECFF';
args.progressBarBgColor = '#006AA6'
}else if(args.data.Resources === 'Rose Fuller'){
args.taskbarBgColor = '#E4E4E7';
args.progressBarBgColor = '#766B7C'
}
else if(args.data.Resources === 'Margaret Buchanan'){
args.taskbarBgColor = '#DFFFE2';
args.progressBarBgColor = '#00A653'
}
else if(args.data.Resources === 'Tamer Vinet'){
args.taskbarBgColor = '#FFEBE9';
args.progressBarBgColor = '#FF3740'
}
}
</script>
<script type="text/x-template" id="resColumnTemplate">
${if(ganttProperties.resourceNames)}
${if(ganttProperties.resourceNames === 'Martin Tamer')}
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; width: 110px; height: 24px; border-radius: 24px; background: #DFECFF">
<span style="color: #006AA6; font-weight: 500;">${ganttProperties.resourceNames}</span>
</div>
${/if}
${if(ganttProperties.resourceNames === 'Rose Fuller')}
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; width: 110px; height: 24px; border-radius: 24px; background: #E4E4E7">
<span style="color: #766B7C; font-weight: 500;">${ganttProperties.resourceNames}</span>
</div>
${/if}
${if(ganttProperties.resourceNames === 'Margaret Buchanan')}
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; width: 160px; height: 24px; border-radius: 24px; background: #DFFFE2">
<span style="color: #00A653; font-weight: 500;">${ganttProperties.resourceNames}</span>
</div>
${/if}
${if(ganttProperties.resourceNames === 'Tamer Vinet')}
<div style="display: flex; align-items: center; justify-content: center; gap: 10px; width: 110px; height: 24px; border-radius: 24px; background: #FFEBE9">
<span style="color: #FF3740; font-weight: 500;">${ganttProperties.resourceNames}</span>
</div>
${/if}
${/if}
</script>
public IActionResult Index()
{
ViewBag.DataSource = ganttData();
ViewBag.projectResources = projectResources();
return View();
}
public static List<GanttResources> projectResources()
{
List<GanttResources> GanttResourcesCollection = new List<GanttResources>();
GanttResources Record1 = new GanttResources()
{
ResourceId = 1,
ResourceName = "Martin Tamer"
};
GanttResources Record2 = new GanttResources()
{
ResourceId = 2,
ResourceName = "Rose Fuller"
};
GanttResources Record3 = new GanttResources()
{
ResourceId = 3,
ResourceName = "Margaret Buchanan"
};
GanttResources Record4 = new GanttResources()
{
ResourceId = 4,
ResourceName = "Tamer Vinet"
};
GanttResourcesCollection.Add(Record1);
GanttResourcesCollection.Add(Record2);
GanttResourcesCollection.Add(Record3);
GanttResourcesCollection.Add(Record4);
return GanttResourcesCollection;
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 30,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 1 }
}
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 2 }
}
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 30,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 3 }
}
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 04),
Duration = 4,
Progress = 30,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 4 }
}
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 04),
Duration = 3,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 1 }
}
};
GanttDataSource Child6 = new GanttDataSource()
{
TaskId = 8,
TaskName = "Estimation approval",
StartDate = new DateTime(2019, 04, 01),
Duration = 4,
Progress = 30,
Resources = new List<ResourceModel>
{
new ResourceModel{ ResourceId = 2}
}
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
Record2.SubTasks.Add(Child6);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class ResourceModel
{
public int ResourceId { get; set; }
public Nullable<int> ResourceUnit { get; set; }
}
public class GanttResources
{
public int ResourceId { get; set; }
public string ResourceName { get; set; }
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
public List<ResourceModel> Resources { get; set; }
}