This is a migrated thread and some comments may be shown as answers.

Updating newly created event calls Create, not Update

3 Answers 174 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Dirk
Top achievements
Rank 1
Dirk asked on 04 Sep 2013, 07:47 AM
Hi,
I'm using the ASP.NET MVC wrapper for the scheduler. The problem is that when I want to edit an event I just created (for example lengthen the event in the week view) the scheduler calls the Create-Method and not the Update-Method. I could imagine it has something to do with the ID of the newly created event.
How can I correct this?

The Create-Method:
public JsonResult Scheduler_Create([DataSourceRequest] DataSourceRequest request, SchedulerModel model)
        {
            Calendar_Entry entry = new Calendar_Entry
            {
                ID=Guid.NewGuid(),
                Description=model.Description,
                End=model.End,
                Begin=model.Start,
                CreationTime=DateTime.UtcNow,
                UpdateTime=DateTime.UtcNow,
                Name=model.Title,
                Calendar_ID=model.CalendarID
            };
            dbContext.Add(entry);
            dbContext.SaveChanges();
            model.ID = entry.ID;
            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
The Scheduler:
@(Html.Kendo().Scheduler<ViCRM.Models.SchedulerModel>()
                    .Name("scheduler")
                    .Date(DateTime.UtcNow)
                    .StartTime(new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 6, 0, 0))
                    .Height(750)
                    .Views(views =>
                    {
                        views.DayView();
                        views.WeekView(weekView => weekView.Selected(true));
                        views.MonthView();
                        views.AgendaView();
                    })
                    .Timezone("Etc/UTC")
                    .DataSource(d => d
                        .Model(m =>
                        {
                            m.Id(f => f.ID);
                        })
                        .Read("Scheduler_Read", "Calendar")
                        .Create("Scheduler_Create", "Calendar")
                        .Destroy("Scheduler_Delete", "Calendar")
                        .Update("Scheduler_Update", "Calendar")
                    )
                    .EventTemplateId("EventTemplate")
                    .Resources(res =>
                    {
                        res.Add(m => m.CalendarID).Title("Kalender").DataSource(ds => ds.Read("getCalendars", "Calendar")).DataValueField("Value").DataTextField("Text").DataColorField("Color");
                )
Kendo UI Version is 2013.2.716

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 06 Sep 2013, 06:28 AM
Hello Dirk,

 Indeed this will happen if the ID of the created event remains the same as the default ID (which is 0 by default). Could you please check if model.ID is properly set to a non-zero value before returned as Json()?

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dirk
Top achievements
Rank 1
answered on 06 Sep 2013, 06:50 AM
Hi,
I checked the POST and Response-Data again. The ID is set to the new value. I did not see that an error was silently given back saying that the field ID is required. Is it possible to set a default value for the ID of a new event? Because now a null value is posted which translates to a Guid.Empty in the controller action.

Thanks in advance.
0
Accepted
Atanas Korchev
Telerik team
answered on 06 Sep 2013, 11:12 AM
Hello Dirk,

 You can change the default value like this:

.Model(m => {
            m.Id(f => f.ID);
            m.Field(f => f.ID).DefaultValue(new Guid());
        })

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Scheduler
Asked by
Dirk
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Dirk
Top achievements
Rank 1
Share this question
or