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

Scheduler Unable to call Update WebAPI (Put)

5 Answers 116 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Ashley
Top achievements
Rank 1
Ashley asked on 04 Dec 2018, 06:48 PM

Hello,

 

I am trying to use the Scheduler control for my application. I have it reading the data from my controller fine. However, I cannot get it call the HttpPut handler correctly.

My breakpoint isnt hit & checking the traffic the responce is:

400 - Bad Request
{"":["The input was not valid."]}

 

The code I am using for the UI is:

01.@(Html.Kendo().Scheduler<MeetingViewModel>()
02.      .Name("SchedulerView")
03.      .Height(500)
04.      .Date(DateTime.Now.ToUniversalTime())
05.      .StartTime(new DateTime(2018, 11, 28, 0, 00, 00).ToUniversalTime())
06.      .MajorTick(30)
07.      .ShowWorkHours(false)
08.      .Footer(false)
09.      .Editable(edit =>
10.      {
11.          //edit.Resize(false);
12.          edit.Create(false);
13.      })
14.      .Views(views =>
15.      {
16.          views.TimelineView(timeline => timeline.EventHeight(50));
17.          //views.TimelineWeekView(timeline => timeline.EventHeight(50));
18.          //views.TimelineWorkWeekView(timeline => timeline.EventHeight(50));
19.          //views.TimelineMonthView(timeline =>
20.          //{
21.          //    timeline.StartTime(DateTime.Now);
22.          //    timeline.EndTime(DateTime.Now.AddMonths(1));
23.          //    timeline.MajorTick(1440);
24.          //    timeline.EventHeight(50);
25.          //});
26. 
27.      })
28.      .Timezone("Etc/UTC")
29.      .Group(group => group.Resources("WorkCenters" /*,"Attendees"*/).Orientation(SchedulerGroupOrientation.Vertical))
30.      .Resources(resource =>
31.      {
32.          resource.Add(m => m.ScheduleRowID)
33.              .Title("Work Center")
34.              .Name("WorkCenters")
35.              .DataTextField("Text")
36.              .DataValueField("Value")
37.              .DataColorField("Color")
38.              .BindTo(@Model.AvailableWorkCenters);
39.      })
40.      .DataSource(d => d
41.          .ServerOperation(true)
42.          .WebApi()
43.          .Model(m =>
44.          {
45.              m.Id(f => f.ActivityID);
46.              m.Field(f => f.Title).DefaultValue("No title");
47.              //m.RecurrenceId(f => f.RecurrenceID);
48.              m.Field(f => f.Description).DefaultValue("No Description");
49.          })
50.          .Events(events => events.Error("error_handler"))
51.          .Read(read => read.Action("GetActivities", "Scheduler").Data("setRequestDateTimes"))
52.          //.Create(create => create.Action("Post", "Scheduler"))
53.          .Update(update => update.Action("PutActivity", "Scheduler", new { id = "{0}" }))
54.          //.Destroy(destroy => destroy.Action("Delete", "Scheduler", new { id = "{0}" }))
55.      )))

 

The code I am using for the Controller is:

01.[Route("Api/[controller]")]
02.[ApiController]
03.public class SchedulerController : DawnController
04.{
05.    public SchedulerController(DatabaseContext context) : base(context)
06.    {
07.    }
08. 
09.    [HttpGet]
10.    public DataSourceResult GetActivities([DataSourceRequest] DataSourceRequest request, DateTime requestStartDateTime, DateTime requestEndDateTime)
11.    {
12.        //Kendo doesnt seem to send the full date range. so + 1 day to end
13.        requestEndDateTime = requestEndDateTime.AddDays(1);
14. 
15.        List<MeetingViewModel> test = new List<MeetingViewModel>();
16. 
17.        //List<JobTask> Tasks =
18.        //    Context.JobTask.Where(j => JobTask.HasActivityInDateRange(j, requestStartDateTime, requestEndDateTime)).ToList();
19. 
20.        //foreach (JobTask jobTask in Tasks)
21.        //{
22.        //    foreach (Activites jobTaskAct in jobTask.Activites)
23.        //    {
24.        //        test.Add(new MeetingViewModel()
25.        //        {
26.        //            JobTaskID = jobTask.JobTaskId,
27.        //            ActivityID = jobTaskAct.ActivityId,
28.        //            Title = jobTaskAct.Name,
29.        //            Description = jobTaskAct.Description,
30.        //            Start = jobTaskAct.StartTime,
31.        //            End = jobTaskAct.EndTime,
32.        //            IsAllDay = false,
33.        //            ScheduleRowID = jobTaskAct.Workcenter.WorkCenterId,
34.        //        });
35.        //    }
36.        //}
37. 
38.        foreach (JobTask jobTask in Context.JobTask)
39.        {
40.            if (JobTask.HasActivityInDateRange(jobTask, requestStartDateTime, requestEndDateTime))
41.            {
42.                foreach (Activites jobTaskAct in jobTask.Activites)
43.                {
44.                    test.Add(new MeetingViewModel()
45.                    {
46.                        JobTaskID = jobTask.JobTaskId,
47.                        ActivityID = jobTaskAct.ActivityId,
48.                        Title = jobTaskAct.Name,
49.                        Description = jobTaskAct.Description,
50.                        Start = jobTaskAct.StartTime.ToUniversalTime(),
51.                        End = jobTaskAct.EndTime.ToUniversalTime(),
52.                        IsAllDay = false,
53.                        ScheduleRowID = jobTaskAct.Workcenter.WorkCenterId,
54.                    });
55.                }
56.            }
57.        }
58.        return test.ToDataSourceResult(request);
59.    }
60. 
61. 
62.    [HttpPut("{id}")]
63.    public IActionResult PutActivity(int id, MeetingViewModel task)
64.    {
65.        if (ModelState.IsValid && id == task.ActivityID)
66.        {
67.            try
68.            {
69.                //breakpoint here
70.                bool a = true;
71.                //update the db here
72.            }
73.            catch (DbUpdateConcurrencyException)
74.            {
75.                return new NotFoundResult();
76.            }
77. 
78.            return new StatusCodeResult(200);
79.        }
80.        else
81.        {
82.            return BadRequest(ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage));
83.        }
84.    }
85.}

 

What could be the issue for me?

5 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 07 Dec 2018, 12:11 PM
Hello,

I have inspected the code provided but could not find out what may not be working correctly. In such case I would recommend you to refer to our online demo and compare your case with it where a similar scenario is working correctly and Put is triggered as expected. All the demo is also available in our offline demo Sample Application that can be downloaded from in your Telerik account.

If you still can't figure our what is not working correctly - I would recommend you to try to isolate the issue into a sample runnable project and send it so we could inspect it and be more helpful.

Regards,
Plamen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ashley
Top achievements
Rank 1
answered on 07 Dec 2018, 12:15 PM

I have resolved this issue.

In ASP Core 2.1 the code above makes the Scheduler send the data as FormData and not Json.

 

I fixed it by changing the function to the following:

1.public IActionResult UpdateActivity(int id, [FromForm]MeetingViewModel task)
2.{
3.     //Code here
4.}
0
Pablo
Top achievements
Rank 1
answered on 05 Feb 2019, 07:11 PM

Hello,

I'm new to Telerik and I'm trying to run your Scheduler demo for Core in my Visual Studio 2017. I installed Telerik.UI.for.AspNet.Core(2019.1.115) in my VS 2016.

But when I copy the code from your demo I get an error in: @(Html.Kendo().Scheduler<Kendo.Mvc.Examples.Models.Scheduler.TaskViewModel>()

 

Under Kendo.Mvc.Examples it cannot find "Models". Did the dll changed? How can I get to Kendo.Mvc.Examples.Models.Scheduler.TaskViewModel ?

 

0
Plamen
Telerik team
answered on 06 Feb 2019, 10:19 AM
Hi Pablo,

You can download the examples solution with all the models in a runnable sample from your Telerik account as described in this documentation article.

Regards,
Plamen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Pablo
Top achievements
Rank 1
answered on 06 Feb 2019, 05:05 PM
Thank you Plamen.
Tags
Scheduler
Asked by
Ashley
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Ashley
Top achievements
Rank 1
Pablo
Top achievements
Rank 1
Share this question
or