Why always trigger POST event when DELETE one event?

4 posts, 0 answers
  1. IT
    IT avatar
    1 posts
    Member since:
    Sep 2013

    Posted 08 May 2014 Link to this post

    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.


  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1444 posts

    Posted 10 May 2014 Link to this post

    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!
     
  3. Gorka S.
    Gorka S. avatar
    9 posts
    Member since:
    Feb 2009

    Posted 21 Oct 2019 Link to this post

    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?

  4. Dimitar
    Admin
    Dimitar avatar
    796 posts

    Posted 23 Oct 2019 Link to this post

    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.
Back to Top