Mobile scheduler with .NET MVC backend

Hi,

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:

[code] dhx.ready(function () {
dhx.ui.fullScreen();
dhx.ui({
view: “scheduler”,
id: “scheduler”,
save: “@Url.Content(string.Format(”~/Mobile/Save"))",

	        });                

	        $$("scheduler").load("@Url.Content(string.Format("~/Mobile/Data"))", "scheduler");
	    });[/code]

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:

public ActionResult Save(int? id, FormCollection actionValues) { System.Collections.Specialized.NameValueCollection nvc = Request.Form; ... }

I am finding that the form field ids have a long integer prefixed to each, which is different each time the app is launched:

{1346707054054_text=my event text&1346707054054_start_date=2012-02-09+23%3a00&1346707054054_end_date=2012-02-10+00%3a00&1346707054054_allDay=0&1346707054054_details=&1346707054054_id=1346707054054&1346707054054_!nativeeditor_status=insert&ids=1346707054054}

Of course I can look through the fields for ones which end with the values I expect, but I must be missing something - can someone advise please?

Thanks in advance.

Prefix is item id. If you are adding a new item, the item id is random. And after the record is inserted into database, the ids will be replaced.

You may use our .Net connector in the server-side script in this case all parameters will be processed automatically:

www.dhtmlx.com/x/download/regular/dhtml … or_net.zip

This package contains samples for desktop Scheduler. However, you may use the same connector for Mobile Scheduler.

Thanks

Hi,

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 :cry: . Please advice me to save the event mannually

–pavan

Hi,

please advise me, how to save the event mannually from formcollection(actionvalues).

–pavan

Hi,
can you specify what exactly goes wrong?

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?

Hi,

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.

–Pavan

Hi,

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

1345200007331_start_date
1345200007331_end_date
1345200007331_text
1345200007331_id
1345200007331_!nativeeditor_status

In case of existing dummy event, the action key values are coming as below
10_start_date
10_end_date
10_text
10_id
10_!nativeeditor_status

I guess, the convertion is not happening because of this extra value coming before key value.

Please advice.

–pavan

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"); }

Hi,

Great Help! Working Fine. I am able to save the event after so many days :laughing:

But i am noticing two issues:

  1. 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.

  1. 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.

Please advice.
–pavan

Hi,
1)please make sure that you send correct type, sid and tid values from the action response. type and sid should be the same as in actionValues

  1. You can send color in attributes of item, and apply it inside the onAfterUpdate event:
return Content(string.Format("<data><action type=\"{0}\" sid=\"{1}\" tid=\"{2}\" textColor=\"{3}\"></action></data>", mode, sId, tId, textColor), "text/xml");

dhx.dp($$("scheduler")).attachEvent("onAfterUpdate",function(obj){ $$("scheduler").item(obj.tid).textColor = obj.textColor; $$("scheduler").data.silent(function(){ $$("scheduler").refresh(obj.tid); $$("scheduler").$$("eventTemplate").refresh(); }); return true; });

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.

Do I need to do any other settings to solve this.

Please advice.

–pavan :frowning:

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”):wink: is coming like this.

Hi,

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.

Please advice.

–pavan :confused:

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.

–pavan :sunglasses:

We will check the possible issue with ID updating in case of recurring events and will post fix here, when it will be available.

Hi,

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.

Pavan :unamused: