insert-url, remove-url, update-url, crud-url and batch-url. Does this mean that it only works in MVC? If not, how to correctly use the different properties?|
[IgnoreAntiforgeryToken(Order = 1001)] // This is necessary to trigger the method OnPostLoadData and OnPostUpdateData
public class IndexModel : PageModel
{
private ScheduleDataContext _context;
public IndexModel(ScheduleDataContext Context)
{
_context = Context;
}
} |
|
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(x => {
x.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
services.AddDbContext<ScheduleDataContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("ScheduleDataConnection")));
} |
|
<ejs-schedule id="schedule" height="550px">
<e-schedule-eventsettings>
<e-data-manager url="/Index?handler=LoadData" crudUrl="/Index?handler=UpdateData" adaptor="UrlAdaptor"></e-data-manager>
</e-schedule-eventsettings>
</ejs-schedule> |
|
[IgnoreAntiforgeryToken(Order = 1001)] // This is necessary to trigger the method OnPostLoadData and OnPostUpdateData
public class IndexModel : PageModel
{
private ScheduleDataContext _context;
public IndexModel(ScheduleDataContext Context)
{
_context = Context;
}
public void OnGet()
{
}
public JsonResult OnPostLoadData([FromBody]Params param)
{
var data = _context.ScheduleEvents.ToList();
return new JsonResult(data);
}
public class Params
{
public string StartDate { get; set; }
public string EndDate { get; set; }
}
public JsonResult OnPostUpdateData([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];
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
ScheduleEvent appointment = new ScheduleEvent()
{
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,
Location = value.Location
};
_context.ScheduleEvents.Add(appointment);
_context.SaveChanges();
}
if (param.action == "update" || (param.action == "batch" && param.changed.Count > 0)) // this block of code will execute while removing 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;
appointment.Location = value.Location;
}
_context.SaveChanges();
}
if (param.action == "remove" || (param.action == "batch" && param.deleted.Count > 0)) // this block of code will execute while updating 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();
}
var data = _context.ScheduleEvents.ToList(); //.Where(app => (app.StartTime >= param.StartDate && app.StartTime <= param.EndDate) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList(); // Here filtering the events based on the start and end date value.
return new JsonResult(data);
}
public class EditParams
{
public string key { get; set; }
public string action { get; set; }
public List<ScheduleEvent> added { get; set; }
public List<ScheduleEvent> changed { get; set; }
public List<ScheduleEvent> deleted { get; set; }
public ScheduleEvent value { get; set; }
}
} |