CRUD operations documentation explanation

Hello, 

I would like to get more information about data saving from Scheduler.

I have been following documentation for Scheduler.

Then I got stopped at CRUD operations on this link: https://ej2.syncfusion.com/aspnetcore/documentation/schedule/crud-actions/#inserting-events-into-database-at-server-side


What confuses me is the following:

- There is no explanation of what type of method and what insert parameter or object has to be on the server-side in order to submit the created appointment in the scheduler.
- There is no explanation of how to bind such action to the backend method (saving apointment from scheduler) 

Note that I'm fresh with the Syncfusion and totally fresh with any kind of components such as this one, btw I'm using those in the .NET Core MVC 5.0 application.
Thank you, Jasmin 




6 Replies 1 reply marked as answer

HB Hareesh Balasubramanian Syncfusion Team January 11, 2021 07:25 AM UTC

Hi Jasmin, 

Greetings from Syncfusion Support..! 

We have validated your shared query “I would like to get more information about data saving from Scheduler” at our end and for that, binding the events into the Scheduler uses dataManager, which supports both RESTful JSON data services binding and local JavaScript object array binding. The dataSource property can be assigned either with the instance of dataManager or JavaScript object array collection. It supports two kinds of data binding method. 

  • Local data
  • Remote data

Any kind of remote data services can be bound to the Scheduler. To do so, create an instance of dataManager and provide the service URL to the Url option of dataManager and then assign it to the dataSource property within e-schedule-eventsettings. And for that, we have prepared a CRUD sample using UrlAdaptor, which can be downloaded from the following link. 


Client-side
<div class="control-label"> 
    <div class="control-section"> 
        <ejs-schedule id="schedule" height="550px" currentView="Month"> 
            <e-schedule-eventsettings> 
                <e-data-manager url="/Home/LoadData" crudUrl="/Home/UpdateData" adaptor="UrlAdaptor" crossDomain="true"></e-data-manager> 
            </e-schedule-eventsettings> 
        </ejs-schedule> 
    </div> 
</div> 

Server-side: 
        [HttpPost] 
        public List<ScheduleEvent> LoadData([FromBody]Params param) // this block of code will execute while initial loading 
        { 
            DateTime Start = param.StartDate; 
            DateTime End = param.EndDate; 
            return _context.ScheduleEvents.ToList().Where(app => (app.StartTime >= param.StartDate && app.StartTime <= param.EndDate) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList(); 
        } 
 
        public class Params 
        { 
            public DateTime StartDate { get; set; } 
            public DateTime EndDate { get; set; } 
        } 
 
        [HttpPost] 
        public List<ScheduleEvent> UpdateData([FromBody]EditParams param) 
        { 
            if (param.action == "insert" || (param.action == "batch" && param.added.Count > 0)) // this block of code will execute while inserting the appointments 
            { 
                var value = (param.action == "insert") ? param.value : param.added[0]; 
                int intMax = _context.ScheduleEvents.ToList().Count > 0 ? _context.ScheduleEvents.ToList().Max(p => p.Id) : 1; 
                DateTime startTime = Convert.ToDateTime(value.StartTime); 
                DateTime endTime = Convert.ToDateTime(value.EndTime); 
                ScheduleEvent appointment = new ScheduleEvent() 
                { 
                    Id = intMax + 1, 
                    StartTime = startTime.ToLocalTime(), 
                    EndTime = endTime.ToLocalTime(), 
                    Subject = value.Subject, 
                    IsAllDay = value.IsAllDay, 
                    StartTimezone = value.StartTimezone, 
                    EndTimezone = value.EndTimezone, 
                    RecurrenceRule = value.RecurrenceRule, 
                    RecurrenceID = value.RecurrenceID, 
                    RecurrenceException = value.RecurrenceException, 
                    Description = value.Description 
                }; 
                _context.ScheduleEvents.Add(appointment); 
                _context.SaveChanges(); 
            } 
            if (param.action == "update" || (param.action == "batch" && param.changed.Count > 0)) // this block of code will execute while updating the appointment 
            { 
                var value = (param.action == "update") ? param.value : param.changed[0]; 
                var filterData = _context.ScheduleEvents.Where(c => c.Id == Convert.ToInt32(value.Id)); 
                if (filterData.Count() > 0) 
                { 
                    DateTime startTime = Convert.ToDateTime(value.StartTime); 
                    DateTime endTime = Convert.ToDateTime(value.EndTime); 
                    ScheduleEvent appointment = _context.ScheduleEvents.Single(A => A.Id == Convert.ToInt32(value.Id)); 
                    appointment.StartTime = startTime.ToLocalTime(); 
                    appointment.EndTime = endTime.ToLocalTime(); 
                    appointment.StartTimezone = value.StartTimezone; 
                    appointment.EndTimezone = value.EndTimezone; 
                    appointment.Subject = value.Subject; 
                    appointment.IsAllDay = value.IsAllDay; 
                    appointment.RecurrenceRule = value.RecurrenceRule; 
                    appointment.RecurrenceID = value.RecurrenceID; 
                    appointment.RecurrenceException = value.RecurrenceException; 
                    appointment.Description = value.Description; 
                } 
                _context.SaveChanges(); 
            } 
            if (param.action == "remove" || (param.action == "batch" && param.deleted.Count > 0)) // this block of code will execute while removing the appointment 
            { 
                if (param.action == "remove") 
                { 
                    int key = Convert.ToInt32(param.key); 
                    ScheduleEvent appointment = _context.ScheduleEvents.Where(c => c.Id == key).FirstOrDefault(); 
                    if (appointment != null) _context.ScheduleEvents.Remove(appointment); 
                } 
                else 
                { 
                    foreach (var apps in param.deleted) 
                    { 
                        ScheduleEvent appointment = _context.ScheduleEvents.Where(c => c.Id == apps.Id).FirstOrDefault(); 
                        if (apps != null) _context.ScheduleEvents.Remove(appointment); 
                    } 
                } 
                _context.SaveChanges(); 
            } 
            return _context.ScheduleEvents.ToList(); 
        } 

Kindly try the above sample and get back to us if you need any further assistance. 

We will happy to assist you. 

Regards, 
Hareesh 


Marked as answer

JA Jasmin January 23, 2021 01:24 AM UTC

Hello Hareesh Balasubramanian , 

Thank you very much! It works great.


NR Nevitha Ravi Syncfusion Team January 25, 2021 04:06 AM UTC

Hi Jasmin, 

You are most welcome..! please get back to us if you need any further assistance. 

Regards, 
Nevitha 



HA Hafiz May 26, 2021 02:02 AM UTC

Hi Nevitha ,

I think there is a mistake at delete action below:
foreach (var apps in param.deleted) 
{ 
     ScheduleEvent appointment = _context.ScheduleEvents.Where(c => c.Id == apps.Id).FirstOrDefault(); 
     if (apps != null) _context.ScheduleEvents.Remove(appointment); 
} 

--> "if (apps != null)" should be "if (appointment != null)"

Also need to fix in the documentation


NR Nevitha Ravi Syncfusion Team May 26, 2021 08:42 AM UTC

Hi Rwem, 

Thanks for notifying the issue. 

We will make change and refresh this in live in all applicable topics within the end of June 2021. 

Regards, 
Nevitha  



NR Nevitha Ravi Syncfusion Team June 28, 2021 10:30 AM UTC

Hi Rwem, 

We have corrected our UG topics which were refreshed in live. 

Regards, 
Nevitha 


Loader.
Up arrow icon