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

I am using Telerik UI Scheduler for asp.net core Project.I am using WebApi to bind data and insert new meeting to the room but I have 2 problems are:

1 Answer 148 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Abdalla
Top achievements
Rank 1
Abdalla asked on 12 May 2017, 02:48 AM
I am using Telerik UI Scheduler for asp.net core Project.I am using WebApi to bind data and insert new meeting to the room but I have 2 problems are:

 1. insert is called twice when I insert new Item. 
 2. update and delete methods are bound to Post and they are not calling corresponded  do delete of add operation.
 
 
html view
 
    @(Html.Kendo().Scheduler<Meeting>().Name("scheduler").Date(new DateTime(2017, 5, 13))
          .StartTime(new DateTime(2017, 5,13, 7, 00, 00))
          .Editable(true)
          .Views(views=>{
              views.DayView();
              views.AgendaView();
          })
          .Height(600)
          .Timezone("Etc/UTC")
          .Group(group => { group.Resources("Rooms"); group.Date(true); })
          .Resources(resource =>
          {
              resource.Add(m => m.RoomId).Title("Room").Name("Rooms").DataTextField("Text").DataValueField("Value").DataColorField("Color").BindTo(new[] {
                  new { Text = "Meeting Room 101", Value = 1, Color = "#6eb3fa" },
                  new { Text = "Meeting Room 201", Value = 2, Color = "#f58a8a" }
              });
              resource.Add(m => m.Attendees)
                  .Title("Attendees")
                  .Multiple(true)
                  .DataTextField("Text")
                  .DataValueField("Value")
                  .DataColorField("Color")
                  .BindTo(new[] {
                      new { Text = "Alex", Value = 1, Color = "#f8a398" } ,
                      new { Text = "Bob", Value = 2, Color = "#51a0ed" } ,
                      new { Text = "Charlie", Value = 3, Color = "#56ca85" }
                  });
          }).DataSource(d => d
              .WebApi()
              .Model(m =>
              {
                  m.Id(f => f.RecordId);
                  m.Field(f => f.Title).DefaultValue("No title");
                  m.Field(f => f.Title).DefaultValue("No title");
              })
              .Events(events => events.Error("error_handler"))
              .Read(read => read.Action("Get", "Meeting"))
              .Create(create => create.Action("Post", "Meeting"))
             .Update(update => update.Action("Put", "Meeting", new { id = "{0}" }))
             .Destroy(destroy => destroy.Action("Delete", "Meeting", new { id = "{0}" }))
              ).Deferred())
     
        @* All initialization scripts are rendered to the bottom of the page, see _Layout.cshtml *@
        @section scripts {
            @Html.Kendo().DeferredScripts()
        }
        <script>
    function error_handler(e) {
        var errors = $.parseJSON(e.xhr.responseText);
     
        if (errors) {
            alert("Errors:\n" + errors.join("\n"));
        }
    }
        </script>
 
meeting Web api controller
  
 
     [Route("api/[controller]")]
        public class MeetingController : Controller
        {
            private IMeetingData meetingData;
     
            public MeetingController(IMeetingData meetingData)
            {
                this.meetingData = meetingData;
            }
     
            // GET api/task
            [HttpGet]
            public DataSourceResult Get([DataSourceRequest]DataSourceRequest request)
            {
                return meetingData.GetAll().ToDataSourceResult(request);
            }
     
            // POST api/Meeting
            [HttpPost]
            public IActionResult Post(Meeting m)
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage));
                }
     
                meetingData.Insert(m, null);
     
                return new ObjectResult(new DataSourceResult { Data = new[] { m }, Total = 1 });
            }
     
            // PUT api/Meeting/5
            [HttpPut("{id}")]
            public IActionResult Put(int id, Meeting m)
            {
                if (ModelState.IsValid && id ==  m.RecordId)
                {
                    try
                    {
                        meetingData.Update(m, null);
                    }
                    catch (Exception)
                    {
                        return new NotFoundResult();
                    }
     
                    return new StatusCodeResult(200);
                }
                else
                {
                    return BadRequest(ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage));
                }
            }
     
            // DELETE api/Meeting/5
            [HttpDelete("{id}")]
            public IActionResult Delete(int id)
            {
                try
                {
                    meetingData.Delete(new Meeting { RecordId = id }, null);
                }
                catch (Exception)
                {
                    return new NotFoundResult();
                }
     
                return new StatusCodeResult(200);
            }
        }
    }

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 15 May 2017, 11:55 AM

Hello Abdalla,

I tested with this demo here: https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/scheduler/scheduler-web-api-crud/SchedulerWebApiCrud. The insert call is called only once for this example and I am unable to think of a situation where or why it might be called twice. 

As for the update and delete methods, you can configure them to use the Get HttpVerb for the API call: https://github.com/telerik/ui-for-aspnet-mvc-examples/blob/master/scheduler/scheduler-web-api-crud/SchedulerWebApiCrud/Views/Home/Index.cshtml#L34-L35. You can also use the HttpVerbs.Get type if needed.

Regards,
Ianko
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler
Asked by
Abdalla
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or