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.
Unfortunately, activation email could not send to your email. Please try again.

Save Resource from Gantt to Entityframework

Thread ID:

Created:

Updated:

Platform:

Replies:

121446 Dec 15,2015 03:14 PM Dec 18,2015 12:01 AM ASP.NET MVC 7
loading
Tags: Gantt
Edmund Herbert
Asked On December 15, 2015 03:14 PM


Hi Guys is it possible to save Resource Name and Resource ID (you select resource from dropdown) I wand to save the resource and gantt data to my server controller in MVC using entityframework

Thanks

Edmund Herbert

Edmund Herbert
Replied On December 16, 2015 02:26 PM

Hi I notice if I add a new record to Gantt and select a resource , resource is not added if I edit record and select resource and add then it is displayed,

I urgently need information on how to get resource selection back to controller I have looked at you java-script actioncomplete function
I need to get complete Gantt record back to controller so that I can save it to sql database, the saving is not the problem but getting it back to controller I am using
MVC 5 and

        <add assembly="Syncfusion.Compression.Base, Version=13.3450.0.7, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.EJ, Version=13.3450.0.7, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.EJ.Mvc, Version=13.3500.0.7, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.Linq.Base, Version=13.3450.0.7, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.XlsIO.Base, Version=13.3450.0.7, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.EJ.Olap,Version=13.3450.0.7, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />
        <add assembly="Syncfusion.Olap.Base, Version=13.3450.0.7, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" />

Regards


Edmund Herbert

Dinesh Kumar Nagarathinam [Syncfusion]
Replied On December 16, 2015 08:53 PM

Hi Herbert,

Yes, we can save the Resource Name and Resource Id to the server using entityframework by passing the resource values to server using Ajax post. Also we can get back the Resource collection using following four properties of Gantt Control.

·         ResourceInfoMapping

·         ResourceIdMapping

·         ResourceNameMapping

·         Resources

Code Snippet:

[CSHTML]
<script type="text/javascript">

@(Html.EJ().Gantt("Gantt").

                     //...

                //To Set the resources

 ResourceInfoMapping("Resource").// "Resource" which is defined in Gantt data object,

                   i.e Resource column in data table

 ResourceIdMapping("ResourceID").//"ResourceID" which is defined in Resource datasource
 ResourceNameMapping("ddtext"). //"ddtext" which is defined in Resource datasource.
Resources(ViewBag.resources). //set the Resource datasource.
                     //...

)
function ActionComplete(args) {  
                     //...

          var editedRecord = args.data.item;               

                var data = JSON.stringify({

                    'Task': editedRecord,

                    'Resource': args.data.resourceInfo

                });

                $.ajax({

                    type: "POST",

                    url: "/TreeGrid/Update"//Update is Server side method

                    data: data,

                    traditional:true,

                    contentType: 'application/json'
                });

                  //...

  }
</script>

[CS]

                //Resource Definition

public class myDropDown

    {

        public string ResourceID { get; set; }      

        public string ddtext { get; set; }
    }

[HttpPost()]

        public void Update(TaskData Task, List<myDropDown> Resource)

        {                      

             string IDNumber = Task.TaskId;

             GanttDataTable data = db.GanttDataTables.First(i => i.TaskId == IDNumber);

                data.TaskId = Task.TaskId;
                data.TaskName = Task.TaskName;
                  //...
             db.SaveChanges();

}




We have prepared a sample based on your requirement, find the sample from below location.

Sample: http://www.syncfusion.com/downloads/support/forum/121446/ze/Mvc5TreeGridSample-174505972

Please let us know, if you need further assistance on this.

Regards,

Dinesh kumar.N


Edmund Herbert
Replied On December 17, 2015 01:49 AM

Hi thanks for reply I just want to confirm that when I add Gantt record I select a resource and add to task I then want to return to server via Ajax complete Gantt record including select resource and all fields in record

Thanks Edmund



Edmund Herbert
Replied On December 17, 2015 03:45 AM

Hi Dinesh

I have tested the sample you sent me I need to be able to do the following which seems to not work:

  • Add a new Gantt record and be able to add resource to new record (when I do add new record, resource does not show up)
  • On ActionComplete function I need to send all the data for that gantt record including resource information that was selected so that I can persist to database
  • I need to be able to edit gantt record and send all the data for that gantt record including resource so that I can persist on database
  • I will not be using parent records I just want to add one task after the other and save to database ( all data fields plus selected resource for that record)

The main thing that I am trying to achieve is add a gantt record with a resource and save it to a table

retrieve that record and also to be able to edit record, I use the gantt table in another part of my program so I need all data.

Thanks for your speedy response

Regards

Edmund Herbert


Dinesh Kumar Nagarathinam [Syncfusion]
Replied On December 17, 2015 07:25 AM

Hi Herbert,

Query 1 :  Add a new Gantt record and be able to add resource to new record (when I do add new record, resource does not show up).

Solution : We request you to set the name of resource id field same for both TaskData and Resources Datasources. Also make sure with the column name of SQL table and Entity Framework Table.

Query 2 : On ActionComplete function I need to send all the data for that gantt record including resource information that was selected so that I can persist to database.

Solution : We can get the complete Gantt Data from parameters (args.data.item) of ActionComplete client side event, in this item collection for resource reference we have passed the Resource ID alone, if we want complete resource details of a particular gantt record then we can get it by args.data.resourceInfo.

Query 3 : I need to be able to edit gantt record and send all the data for that gantt record including resource so that I can persist on database.

Solution : We can update the edited gantt record to database using ActionComplete client side event, when the request type of the event is “recordUpdate”.

Code Snippet :

<script type="text/javascript">              

        function ActionComplete(args) {

if (args.requestType === 'recordUpdate') {

   var editedRecord = args.data.item; //get all datas of the edited gantt record               

   var data = JSON.stringify({

   'Task': editedRecord,

   'Resource': args.data.resourceInfo//get the resource info of the edited gantt record

    });

        $.ajax({

               type: "POST",

               url: "/TreeGrid/Update"//Update is Server side method

               data: data,

               traditional:true,

               contentType: 'application/json'

           });

        }

     }

</script>


Query 4 : I will not be using parent records I just want to add one task after the other and save to database ( all data fields plus selected resource for that record).

Solution : We can avoid the parent Records by ignoring the “ParentTaskIdMapping” property, and we can add new gantt task with saving all datas of the task to the database using “ActionComplete” client side event, when the request type of the event is “save” also the event parameter should be contain “addedRecord” which is newly added to the control. Also we can get the resource details of the newly added task from “args.addedRecord.resourceInfo”, for more details find the below code snippet,

Code Snippet :

<script type="text/javascript">              

        function ActionComplete(args) {

//args.addedRecord contains all datas of newly added task.

if (args.requestType === 'save' && args.addedRecord) {               

                addedItem = args.addedRecord.item;

                var addedRecord = JSON.stringify({

                    'Task': addedItem,

                    //Resource Details of the newly added task.

                    'Resource': args.addedRecord.resourceInfo

                });

                $.ajax({

                    type: "POST",

                    url: "/TreeGrid/Add",//Add is Server side method

                    data: addedRecord,

                    traditional: true,

                    contentType: 'application/json'

                });

            }

</script>


We have prepared a sample base on your above requirements, find the sample from below location.

Sample : http://www.syncfusion.com/downloads/support/forum/121446/ze/Mvc5GanttSample198965217

Please let us know, if you need further assistance on this.

Regards,      

Dinesh kumar.N


Edmund Herbert
Replied On December 17, 2015 08:40 AM

Thank you very much your support is outstanding

Regards

Edmund Herbert

Dinesh Kumar Nagarathinam [Syncfusion]
Replied On December 18, 2015 12:01 AM

Hi Herbert,

Thanks for your update.

Please let us know, if you need further assistance on this.
Reagrds,
Dinesh kumar.N


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;