Implement Drag and Drop in Scheduler with OData or any other API adapter

Is is possible to implement Drag and Drop with OData V4 or any other api adapter? I am currently using OData V4 and drag and drop does not work.

<SfSchedule TValue=ScheduleItem Height="calc(100vh - 8rem">
    <ScheduleEventSettings TValue="ScheduleItem">
        <SfDataManager Url="https://localhost:5001/odata/ScheduleItems" Adaptor="Adaptors.ODataV4Adaptor"/>
        <ScheduleField>
            <FieldSubject Name="Title"/>
        </ScheduleField>
        </ScheduleEventSettings>
    <ScheduleViews>
        <ScheduleView Option="View.Day"></ScheduleView>
        <ScheduleView Option="View.Week"></ScheduleView>
        <ScheduleView Option="View.WorkWeek"></ScheduleView>
        <ScheduleView Option="View.Month"></ScheduleView>
        <ScheduleView Option="View.Agenda"></ScheduleView>
    </ScheduleViews>
</SfSchedule>



public class ScheduleItemsController : ODataController

    {
        private readonly string _connectionString;
        private readonly ApplicationDbContext db;


        public ScheduleItemsController(IConfiguration configuration, ApplicationDbContext _db)
        {
            _connectionString = configuration.GetConnectionString("DefaultConnection");
            db = _db;
        }




        // GET: odata/ODataV4
        [EnableQuery]
        [AcceptVerbs("GET")]
        public IQueryable<ScheduleItem> Get()
        {
            return db.ScheduleItems;
        }


        // GET: odata/ODataV4(5)
        [EnableQuery]
        [AcceptVerbs("GET")]
        public IQueryable<ScheduleItem> Get(string StartDate, string EndDate)
        {
            DateTime start = DateTime.Parse(StartDate);
            DateTime end = DateTime.Parse(EndDate);
            return db.ScheduleItems.Where(evt => evt.StartTime >= start && evt.EndTime <= end);
        }


        // POST: odata/ODataV4
        [AcceptVerbs("POST", "OPTIONS")]
        public void Post([FromBody]ScheduleItem eventData)
        {
            string studioId = "";


            //Get studioId from JWT token
            var identity = User.Identity as ClaimsIdentity;
            if (identity.Claims.Count() > 0)
            {
                IEnumerable<Claim> claims = identity.Claims;
                studioId = claims.Where(p => p.Type == ClaimTypes.GroupSid).FirstOrDefault()?.Value;
            }


            if (string.IsNullOrEmpty(studioId))
            {
                ModelState.AddModelError(key:"", errorMessage:$"Schedule item is not valid");
                //return StatusCode(401, ModelState);
            }


            if (eventData == null)
            {
                ModelState.AddModelError(key:"", errorMessage:"Bad Request");
                //return BadRequest(ModelState);
            }


            if (ModelState.IsValid)
            {
                ScheduleItem insertData = new ScheduleItem();
                insertData.Id = (db.ScheduleItems.ToList().Count > 0 ? db.ScheduleItems.ToList().Max(p => p.Id) : 1) + 1;
                insertData.StudioId = Int32.Parse(studioId);
                insertData.Title = eventData.Title;
                insertData.StartTime = Convert.ToDateTime(eventData.StartTime);
                insertData.EndTime = Convert.ToDateTime(eventData.EndTime);
                insertData.StartTimeZone = eventData.StartTimeZone;
                insertData.EndTimeZone = eventData.EndTimeZone;
                insertData.LocationId = eventData.LocationId;
                insertData.StaffId = eventData.StaffId;
                insertData.Description = eventData.Description;
                insertData.IsAllDay = eventData.IsAllDay;
                insertData.IsBlock = eventData.IsBlock;
                insertData.IsReadOnly = eventData.IsReadOnly;
                insertData.ScheduleItemTypeId = eventData.ScheduleItemTypeId;
                insertData.ProgramId = eventData.ProgramId;
                insertData.RecurrenceID = eventData.RecurrenceID;
                insertData.RecurrenceRule = eventData.RecurrenceRule;
                insertData.RecurrenceException = eventData.RecurrenceException;
                db.ScheduleItems.Add(insertData);
                db.SaveChanges();
            }
        }


        // PATCH: odata/ODataV4(5)
        [AcceptVerbs("PATCH", "MERGE", "OPTIONS")]
        public void Patch([FromBody]ScheduleItem eventData)
        {
            string studioId = "";


            //Get studioId from JWT token
            var identity = User.Identity as ClaimsIdentity;
            if (identity.Claims.Count() > 0)
            {
                IEnumerable<Claim> claims = identity.Claims;
                studioId = claims.Where(p => p.Type == ClaimTypes.GroupSid).FirstOrDefault()?.Value;
            }


            if (string.IsNullOrEmpty(studioId))
            {
                ModelState.AddModelError(key:"", errorMessage:$"Schedule item is not valid");
                //return StatusCode(401, ModelState);
            }


            if (eventData == null)
            {
                ModelState.AddModelError(key:"", errorMessage:"Bad Request");
                //return BadRequest(ModelState);
            }


            if (ModelState.IsValid)
            {
                ScheduleItem updateData = db.ScheduleItems.First(i => i.Id == Convert.ToInt32(eventData.Id));
                if (updateData != null)
                {
                    updateData.Title = eventData.Title;
                    updateData.StartTime = Convert.ToDateTime(eventData.StartTime);
                    updateData.EndTime = Convert.ToDateTime(eventData.EndTime);
                    updateData.StartTimeZone = eventData.StartTimeZone;
                    updateData.EndTimeZone = eventData.EndTimeZone;
                    updateData.LocationId = eventData.LocationId;
                    updateData.StaffId = eventData.StaffId;
                    updateData.Description = eventData.Description;
                    updateData.IsAllDay = eventData.IsAllDay;
                    updateData.IsBlock = eventData.IsBlock;
                    updateData.IsReadOnly = eventData.IsReadOnly;
                    updateData.ScheduleItemTypeId = eventData.ScheduleItemTypeId;
                    updateData.ProgramId = eventData.ProgramId;
                    updateData.RecurrenceID = eventData.RecurrenceID;
                    updateData.RecurrenceRule = eventData.RecurrenceRule;
                    updateData.RecurrenceException = eventData.RecurrenceException;
                    db.SaveChanges();
                }
            }
        }


        // DELETE: odata/ODataV4(5)
        [AcceptVerbs("DELETE", "OPTIONS")]
        public void Delete([FromODataUri]int key)
        {
            if (ModelState.IsValid)
            {
                ScheduleItem removeData = db.ScheduleItems.First(i => i.Id == key);
                if (removeData != null)
                {
                    db.ScheduleItems.Remove(removeData);
                    db.SaveChanges();
                }
            }
        }
    }

3 Replies

SK Satheesh Kumar Balasubramanian Syncfusion Team June 13, 2022 02:50 PM UTC

Hi Judi,

 

We have prepared a sample with ODataV4Adaptor. Drag and drop works properly at out end. Please find the attached sample and documentation for your reference. 

 

 

Kindly try the above links and let us know for further assistance.


Regards,

Satheesh Kumar B


Attachment: blazorschedulercrud_7d3f2251.zip


JS Judi Smith replied to Satheesh Kumar Balasubramanian June 13, 2022 10:15 PM UTC

Hi Satheesh,

When I look at the error, I am getting a 404 not found on the Patch route. It seems that the URL is being sent as 

https://localhost:5001/odata/ScheduleItems(6)?StartDate=6/12/2022%2012:00:00%20AM&EndDate=6/18/2022%2011:59:59%20PM 

Please note the key after "ScheduleItems". This was causing the 404 error. When I changed the patch method as follows, everything worked.

public void Patch([FromODataUri] int key, [FromBody] ScheduleItem eventData)

The issue is that all of the examples yours that I have seen show the patch method like this.

public void Patch([FromBody]EventData eventData)

So I am wondering if this is correct or if not where the error might be.

Thanks for your help
Judi



RV Ravikumar Venkatesan Syncfusion Team June 14, 2022 05:06 PM UTC

Hi Judi,


We have validated your query “I am getting a 404 not found on the Patch route” at our end. We have ensured the Patch method in our last shared sample and it works as expected and we didn’t receive any key. You can find the details from the below snip.



We suspect that you faced a problem in your sample project and we are happy that you have resolved it on your end.


Kindly let us know if you need any further assistance.


Regards,

Ravikumar Venkatesan


Loader.
Up arrow icon