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

Why always trigger POST event when DELETE one event?

3 Answers 67 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
IT
Top achievements
Rank 1
IT asked on 08 May 2014, 05:00 AM
Dear,

I am doing a booking system with Kendo UI Scheduler, once I delete one event, it always call the POST action instead of the DELETE action declared in my Odata API.
My Odata Controller is like that:
// POST: odata/BookingSchedulers
        [ValidateHttpAntiForgeryToken]
        public async Task<IHttpActionResult> Post(BookingScheduler bookingScheduler)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            bookingScheduler.Start = bookingScheduler.Start.ToLocalTime();
            bookingScheduler.End = bookingScheduler.End.ToLocalTime();

            _bookingSchedulerRepository.Create(bookingScheduler);
            await _bookingSchedulerRepository.SaveAsync();

            return Created(bookingScheduler);
        }

// DELETE: odata/BookingSchedulers(5)
        [ValidateHttpAntiForgeryToken]
        public async Task<IHttpActionResult> Delete([FromODataUri] int key)
        {
            BookingScheduler bookingScheduler = await _bookingSchedulerRepository.FindAsync(key);
            if (bookingScheduler == null)
            {
                return NotFound();
            }

            _bookingSchedulerRepository.Delete(bookingScheduler);
            await _bookingSchedulerRepository.SaveAsync();

            return StatusCode(HttpStatusCode.NoContent);
        }

My POCO is 
public class BookingScheduler
    {
        public int BookingSchedulerID { get; set; }
        public int BookingItemID { get; set; }
        public int ItemBreakdownID { get; set; }
        public string BookingUser { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public int StaffID { get; set; }
        public int RoomID { get; set; }
        public string Description { get; set; }
        public string StartTimezone { get; set; }
        public string EndTimezone { get; set; }
        public string RecurrenceID { get; set; }
        public string RecurrenceRule { get; set; }
        public string RecurrenceException { get; set; }
        public bool IsAllDay { get; set; }

        public virtual BookingItem BookingItem { get; set; }
        public virtual Room Room { get; set; }
        public virtual Staff Staff { get; set; }
        public virtual ItemBreakdown ItemBreakdown { get; set; }
    }

and My scheduler datasource is:
bookingDataSource: new kendo.data.SchedulerDataSource({
                //batch: true,
                type: "odata",
                transport: {
                    read: {
                        url: config.bookingSchedulersUrl + '?$expand=ItemBreakdown',
                        dataType: "json"
                    },
                    update: {
                        url: function (data) {
                            return config.bookingSchedulersUrl + "(" + data.BookingSchedulerID + ")";
                        },
                        dataType: "json",
                        type: "PUT",
                        beforeSend: function (req) {
                            req.setRequestHeader('RequestVerificationToken', token);
                        }
                    },
                    create: {
                        url: config.bookingSchedulersUrl,
                        dataType: "json",
                        type: "POST",
                        beforeSend: function (req) {
                            req.setRequestHeader('RequestVerificationToken', token);
                        }
                    },
                    destroy: {
                        url: function (data) {
                            alert(data.BookingSchedulerID);
                            return config.bookingSchedulersUrl + "(" + data.BookingSchedulerID + ")";
                        },
                        dataType: "json",
                        type: "DELETE",
                        beforeSend: function (req) {
                            req.setRequestHeader('RequestVerificationToken', token);
                        }
                    }
                },
                error: function (e) {
                    alert(e.xhr.responseText);
                },
                requestEnd: function(e){
                    //if (e.type == "update") {
                    //    openMessageWindow("#popup-message-template", messageViewModel("Edited Successfully.", "MESSAGE", false));

                    //    var scheduler = $("#scheduler").data("kendoScheduler");
                    //    scheduler.view(scheduler.view().name);
                    //}

                    //if (e.type == "create") {
                    //    openMessageWindow("#popup-message-template", messageViewModel("Created Successfully.", "MESSAGE", false));

                    //    var scheduler = $("#scheduler").data("kendoScheduler");
                    //    scheduler.view(scheduler.view().name);
                    //}

                    if (e.type == "destory") {
                        openMessageWindow("#popup-message-template", messageViewModel("Deleted Successfully.", "MESSAGE", false));

                        var scheduler = $("#scheduler").data("kendoScheduler");
                        scheduler.view(scheduler.view().name);
                    }
                },
                schema: {
                    data: function (data) {
                        return data.value;
                    },
                    total: function (data) {
                        return parseInt(data["odata.count"]);
                    },
                    model: {
                        id: "bookingSchedulerID",
                        fields: {
                            bookingSchedulerID: { from: "BookingSchedulerID", type: "number" },
                            bookingItemID: { from: "BookingItemID", type: "number", defaultValue: data.BookingItemID },
                            itemBreakdownID: { from: "ItemBreakdownID", type: "number", nullable: true },
                            title: { from: "BookingUser", defaultValue: userName },
                            start: { type: "date", from: "Start" },
                            end: { type: "date", from: "End" },
                            roomId: { from: "RoomID", type: "number", nullable: true },
                            staffId: { from: "StaffID", type: "number", nullable: true },
                            startTimezone: { from: "StartTimezone" },
                            endTimezone: { from: "EndTimezone" },
                            description: { from: "Description" },
                            recurrenceId: { from: "RecurrenceID" },
                            recurrenceRule: { from: "RecurrenceRule" },
                            recurrenceException: { from: "RecurrenceException" },
                            isAllDay: { type: "boolean", from: "IsAllDay" },
                            image: { from: "ItemBreakdown.ItemBreakdownImageURL" },
                            itemBreakdownName: { from: "ItemBreakdown.ItemBreakdownName" },
                            color: { from: "ItemBreakdown.Color" }
                        }
                    }
                },
                serverFiltering: true,
                filter: {
                    field: "BookingItemID",
                    operator: "eq",
                    value: data.BookingItemID
                }
            }),

Any one can help, Thanks.


3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 10 May 2014, 01:24 PM
Thank you for the provided code snippets. I reviewed them, but I am really not sure what exactly is causing this, as I did not notice anything unusual in the configuration. Could you please provide a runnable project where the issue is reproduced? This would help us pinpoint the exact reason for this behavior and advise you further.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Gorka S.
Top achievements
Rank 1
answered on 21 Oct 2019, 09:04 AM

I'm having a similar problema with version 2019.2.514.545. 

It seems that the scheduler is deleting all the events and recreating them again all the time, so when you delete an event it posts the creation of all the remaining events. When you modify one, it makes a POST for all the existing events, including the modified one. It never does a PUT or DELETE.

I've tried to reproduce this behavior in a separate project but I have not succeeded. Please, any hint about it?

0
Dimitar
Telerik team
answered on 23 Oct 2019, 05:25 AM

Hello Gorka,

Could you provide a sample Dojo where the described issue can be reproduced?

If the Scheduler DataSource is configured correctly, deleting an event should trigger an ajax request to the DataSource destroy URL that is configured. The request will contain only data regarding the deleted event. Important to note is that the Scheduler expects to receive response from the server that contains the deleted appointment data. Refer to the following demo where the described process could be observed through the browser dev tools:

Regards,
Dimitar
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.
Tags
Scheduler
Asked by
IT
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Gorka S.
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or