We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Working with Razor Pages and MySql

Hi!

I am currently checking out your kit and plan to implement the Gantt component into an existing asp net core solution I`m working on.
I am using the mysql entity framework for mysql and I use all the other things neccessary to make it work, lik migrations and dbcontext and so forth.
I`m also on Razor Pages.
How can I go about creating a Task model, making the neccessary Pages and doing crud operations on the database?

I have managed to do what you`re doing here:
https://ej2.syncfusion.com/aspnetcore/documentation/gantt/getting-started/
in a asp net core web application using Razor Pages template.

Do you have a working sample on this or can you give me some guiding advice?

Tommy

1 Reply 1 reply marked as answer

KR Karthikeyan Raja Syncfusion Team November 19, 2020 07:00 AM

Hi Tommy,

Thanks for contacting Syncfusion support.
For implementing ASP.NET Core web application with Razor pages, Please refer the below documentation link
Documentation - https://ej2.syncfusion.com/aspnetcore/documentation/getting-started/razor-pages/

In Gantt, we can fetch data from mysql and update the changes on CRUD action to the server by using DataManager support. We can define data source for Gantt as instance of DataManager and by using batchUrl property of DataManager we can update the data source on CRUD operation. We have prepared a sample in which we can fetch data from mysql database and updated the server on CRUD actions. Please find the below code example. 

[CS]  
public ActionResult UrlDatasource(DataManagerRequest dm)  
{  
    MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password=yourpassword");//connectionString  
    con.Open();  
    using (con)  
    {  
        using (var command = con.CreateCommand())  
        {  
            command.CommandText = "SELECT * FROM GanttData";  
            using (var reader = command.ExecuteReader())  
            {  
                 var indexOfCol1 = reader.GetOrdinal("TaskId");  
                 var indexOfCol2 = reader.GetOrdinal("TaskName");  
                 //...  
                 while (reader.Read())  
                 {  
                     GanttData obj = new GanttData();  
                     obj.TaskId = reader.GetValue(indexOfCol1).ToString();  
                     //...  
                  }  
                  reader.Close();  
              }  
          }  
            con.Close();  
    }  
    var count = list.Count();  
    return Json(new { result = list, count = count });  
}  
public ActionResult BatchSave([FromBody]ICRUDModel<GanttData> data)  
{  
  
   //...  
   return Json(new { addedRecords = uAdded, changedRecords = uChanged, deletedRecords = uDeleted });  
}  
  
public GanttData Create(GanttData value)  
{  
    string cmdString = "INSERT INTO GanttData (`TaskId`, `TaskName`, `StartDate`, `EndDate`, `Duration`, `Progress`, `ParentId`,`Predecessor`)" +  
       "VALUES(@TaskId,@TaskName,@StartDate,@EndDate,@Duration,@Progress,@ParentId, @Predecessor)";           
    MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password=yourpassword");//connectionString  
    con.Open();  
    //...  
    con.Close();  
}  
public GanttData Edit(GanttData Task)  
{  
     MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password= yourpassword");//connectionString  
     con.Open();  
     string IDNumber = Task.TaskId;  
     string cmdString = "UPDATE ganttdata SET `TaskId`=@TaskId,`TaskName`=@TaskName,`StartDate`=@StartDate,`EndDate`=@EndDate,`Duration`=@Duration,`Progress`=@Progress,`ParentId`=@ParentId,`Predecessor`=@Predecessor WHERE(TaskId = " + IDNumber + ")";  
            //...  
}  
public GanttData Delete(string TaskId)  
{  
    MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password=yourpassword");//connectionString  
    con.Open();  
    MySqlCommand cmd = new MySqlCommand("delete from GanttData where TaskId = '" + TaskId + "'", con);  
    //...  
    con.Close();  
return data;  

For further reference, Please refer the below forum link
Link - https://www.syncfusion.com/forums/155461/connect-gantt-chart-with-database-mysql

Please let us know, If you have any concerns.

Regards,
Karthikeyan Raja



Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon