I am implementing an app which will have both desktop and mobile views. I am evaluating Scheduler .NET MVC, and am experimenting with using mobile Scheduler for the mobile view.
I am pointing the mobile scheduler to MVC actions to retrieve data and send it back, as follows:
I have implemented a very basic version of the data retrieval fine. However, when I am having trouble getting the event data passed in successfully to the Save action. When I examine the form fields as follows:
I am using the following MVC code to saving the event in my mobile sample project instead of processing the field by field from formcollection(actionValues) or using DHTMLX .Net connector.
var action = new DataAction(actionValues);
var changedEvent = (Event)DHXEventsHelper.Bind(typeof(Event), actionValues);
But both are not working . Please advice me to save the event mannually
var changedEvent = (Event)DHXEventsHelper.Bind(typeof(Event), actionValues);
does Bind method returns event object or it fails somehow? Or you have difficulties with further processing of the event?
In my save Event method, I am following these steps.
First Step:
I am trying to get the action status by using the following step.
var action = new DataAction(actionValues);
But when I check action values like type, sourceId, targetId, i am getting as “Error”,0,0 respectively. it means the above steps is not taking actual action.type i.e. insert or update.
Second Step:
After this, I am trying to convert the actionvalues (formcollection) into the event entity by using the below step.
var changedEvent = (Event)DHXEventsHelper.Bind(typeof(Event), actionValues);
After execution of this step, I verified the changedEvent and it is having blank values. All properties of this changedEvent is having default/blank values not the actionValues (formcollection values).
Please advise me, How i can get action type from actionValues and also convert actionvalues into entity for further process. If I am able to do this, then i can follow the other steps mentioned in your MVC samples to save the event.
To understand more on the process, I executed your MVC sample and verified the convertion of action values to event i.e.var changedEvent = (Event)DHXEventsHelper.Bind(typeof(Event), actionValues);
and noticed that the action key values are coming as below
start_date
end_date
text
id
!nativeeditor_status
Where as in my application, the action key values are coming as below
Hi,
try adding this line after scheduler initialization
dhx.dp($$("scheduler")).define("single",true);
then scheduler won’t add prefix to the post parameters
Great!.. i am getting the action key values without prefix now and able convert action vlaues to entity.
But still i am not getting action type when I execute this statement i.e. var action = new DataAction(actionValues); it is taking as Error not the insert or update. One thing i noticed is, when i execute the above statement, the source Id and target Id of action is having proper ids but not the type. I am not sure why this is happening.
Please advice.
Looks like dataprocessor which goes with mobile scheduler uses slightly different format for action types then one in scheduler for .net, and DataAction cant parse it. However you can do update without DataAction and AjaxSaveResponse classes. You’ll need to render output manually, but format is simple.
Code may look like followingpublic ContentResult Save(int? id, FormCollection actionValues){
var sId = long.Parse(actionValues["id"]);
var tId = sId;
var mode = actionValues["!nativeeditor_status"];
var data = new DHXSchedulerDataContext();
try
{
var changedEvent = (Event)DHXEventsHelper.Bind(typeof(Event), actionValues);
switch (mode){
case "insert":
//do insert
break;
case "update":
//do update
break;
case "delete":
//do delete
break;
default:
break;
}
data.SubmitChanges();
tId = changedEvent.id;
}catch{
mode = "error";
}
return Content(string.Format("<data><action type=\"{0}\" sid=\"{1}\" tid=\"{2}\"></action></data>", mode, sId, tId), "text/xml");
}
Great Help! Working Fine. I am able to save the event after so many days
But i am noticing two issues:
while saving the new event, i got the value like this
var sid = 1345200007389
var tid = 21
return Content(string.Format("<action type="{0}" sid="{1}" tid="{2}">", mode, sId, tId), “text/xml”);
I am again editing the above event to add some more information then i am getting the actionvalues[“id”] as 1345200007389 not the 21. So application is inserting the new record instead of updating the event.
I want to add the color(textcolor) to the event based on the some conditions. I am doing this while saving the event. After saving , i want to update same color to the event on scheduler but not it is not happening.
As you suggested, I followed the same steps as shown below.
public ContentResult Save(int? id, FormCollection actionValues){
var sId = long.Parse(actionValues[“id”]);
var tId = sId;
var mode = actionValues["!nativeeditor_status"];
try
{
var changedEvent = (Event)DHXEventsHelper.Bind(typeof(Event), actionValues);
switch (mode){
case “insert”:
changedEvent.id = SaveScheduler()
break;
case “update”:
UpdateScheduler()
break;
case “delete”:
DeleteScheduler()
break;
default:
break;
}
tId = changedEvent.id;
}catch{
mode = “error”;
}
return Content(string.Format("<action type="{0}" sid="{1}" tid="{2}">", mode, sId, tId), “text/xml”);
}
But still I am facing same issue i.e. not getting the id for newly created event.
Can you post here example of actionValues of the ‘insert’ request and its xml response?
And also, is it possible that SaveScheduler() returns incorrect id?
Sure, find the key and action values are below
Key : text - Value : New Event
Key : event_location - Value :
Key : start_date - Value : 2012-09-14 14:02
Key : end_date - Value : 2012-09-14 15:02
Key : allDay - Value : 0
Key : rec_type - Value :
Key : event_length - Value :
Key : endRepeat - Value :
Key : id - Value : 1347631366324
Key : !nativeeditor_status - Value : insert
I have verified the SaveSchedluer method and it is returning the proper id.
After saving the event, the return content xml (return Content(string.Format("<action type="{0}" sid="{1}" tid="{2}">", mode, sId, tId), “text/xml”) is coming like this.
I found the root cause why the id is not updating for newly created event. As you know, i am using the recurring files such as “dhxscheduler_mobile_rec.js”, “dhxscheduler_mobile_rec.css” to enable recurring functionality along with normal event functionality. if i use “dhtmlxscheduler_mobile.js”, “dhtmlxscheduler_mobile.css” files instead of recurring files then the id is updating properly for newly created event. I guess that there might be an issue with dhxscheduler recurring files.
Another thing is, the “OnAfterUpdate” method i.e. “dhx.dp($$(“scheduler”)).attachEvent(“onAfterUpdate”,function(obj)” is triggering for an updating event. i want to update the color for both newly inserted event (insert) and existing event (update). I tried “OnAfterAdd” method as seen your mobile samples but it is not working.
Initially, when i go through documentation, i intend that the implementation is quite easy but it seems the existing documentation is not enough for a developer. I request you to upgrade the documentation with detailed examples in near future.
I anticipate your reply on latest status of fixes. This is high time for me as i have to submit this assignment to my college by this week. Appreicate, if you share the fixes at the earliest.