Updating newly created event calls Create, not Update

4 posts, 1 answers
  1. Dirk
    Dirk avatar
    3 posts
    Member since:
    Jul 2012

    Posted 04 Sep 2013 Link to this post

    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.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 06 Sep 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Dirk
    Dirk avatar
    3 posts
    Member since:
    Jul 2012

    Posted 06 Sep 2013 Link to this post

    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.
  5. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 06 Sep 2013 Link to this post

    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!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready