We recommend you to use UrlAdaptor to perform CRUD operation with in Scheduler and for the same we have prepared the sample which can be download form the below location.
<Code>
<ej-schedule id="Schedule1" width="100%" height="525px" current-date="new DateTime(2014, 12, 5)">
<e-appointment-settings apply-time-offset="false" id="Id" subject='"Subject"' start-time='"StartTime"' end-time='"EndTime"' all-day='"AllDay"' recurrence='"Recurrence"' recurrence-rule='"RecurrenceRule"'>
<e-datamanager url="Home/GetData" crud-url="Home/Batch" adaptor="UrlAdaptor"></e-datamanager>
</e-appointment-settings>
</ej-schedule>
public List<DefaultSchedule> Batch([FromBody] EditParams param)
{
if (param.action == "insert" || (param.action == "batch" && (param.added.Count>0))) // this block of code will execute while inserting the appointments
{
DefaultSchedule appoint = new DefaultSchedule();
object result;
if (param.action == "insert")
{
var value = param.value;
foreach (var fieldName in value.GetType().GetProperties())
{
var newName = fieldName.ToString().Split(null);
if (newName[1] == "Id") result = (_context.DefaultSchedule.ToList().Count > 0 ? _context.DefaultSchedule.ToList().Max(p => p.Id) : 1) + 1;
else if (newName[1] == "StartTime" || newName[1] == "EndTime") result = Convert.ToDateTime(fieldName.GetValue(value));
else result = fieldName.GetValue(value);
fieldName.SetValue(appoint, result);
}
_context.DefaultSchedule.Add(appoint);
}
else
{
foreach (var item in param.added.Select((x, i) => new { Value = x, Index = i }))
{
var value = item.Value;
foreach (var fieldName in value.GetType().GetProperties())
{
var newName = fieldName.ToString().Split(null);
if (newName[1] == "Id") result = (_context.DefaultSchedule.ToList().Count > 0 ? _context.DefaultSchedule.ToList().Max(p => p.Id) : 1) + 1 +
else if (newName[1] == "StartTime" || newName[1] == "EndTime") result = Convert.ToDateTime(fieldName.GetValue(value));
else result = fieldName.GetValue(value);
fieldName.SetValue(appoint, result);
}
_context.DefaultSchedule.Add(appoint);
}
}
_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")
{
DefaultSchedule app = _context.DefaultSchedule.Where(c => c.Id == Convert.ToInt32(param.key)).FirstOrDefault();
if (app != null) _context.DefaultSchedule.Remove(app);
}
else
{
foreach (var a in param.deleted)
{
var app = _context.DefaultSchedule.ToList().Where(c => c.Id == Convert.ToInt32(a.Id)).FirstOrDefault();
if (app != null) _context.DefaultSchedule.Remove(app);
}
}
_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.DefaultSchedule.Where(c => c.Id == Convert.ToInt32(value.Id));
if (filterData.Count() > 0)
{
DefaultSchedule appoint = _context.DefaultSchedule.Single(A => A.Id == Convert.ToInt32(value.Id));
appoint.StartTime = Convert.ToDateTime(value.StartTime);
appoint.EndTime = Convert.ToDateTime(value.EndTime);
appoint.Subject = value.Subject;
appoint.Recurrence = value.Recurrence;
appoint.AllDay = value.AllDay;
appoint.RecurrenceRule = value.RecurrenceRule;
}
_context.SaveChanges();
}
List<DefaultSchedule> datas = _context.DefaultSchedule.Take(500).ToList();
return datas;
}
</Code>
Regards,
Karthigeyan