Oops ...think I blame Grammarly and a slow internet for that.
Before I upgraded to 17.4.47, on updating an event, on the scheduler, the post results in a normal patch, which obviously worked like a gem.
So after upgrading to "@syncfusion/ej2": "17.4.47" on updating an event, on the scheduler, the post results in a $batch update, obviously fails because I did not write the code to handle a batch update. How should I fix this?
Is there a setting on the scheduler that makes it go in batch mode?
|
@using Syncfusion.EJ2
@{
ViewData["Title"] = "Home Page";
}
@{
var dataManager = new DataManager() { Url = "/Home/LoadData", CrudUrl = "Home/UpdateData", Adaptor = "UrlAdaptor", CrossDomain = true };
}
<ejs-schedule id="schedule" width="100%" selectedDate="new DateTime(2020, 1, 1)" height="650px" currentView="Week">
<e-schedule-group byGroupID="true" resources="@ViewBag.Resources"></e-schedule-group>
<e-schedule-views>
<e-schedule-view option="Day"></e-schedule-view>
<e-schedule-view option="Week"></e-schedule-view>
<e-schedule-view option="WorkWeek"></e-schedule-view>
<e-schedule-view option="Month"></e-schedule-view>
</e-schedule-views>
<e-schedule-resources>
<e-schedule-resource dataSource="@ViewBag.Projects" field="ProjectId" title=" Choose Project" name="Projects" textField="text" idField="id" colorField="color"></e-schedule-resource>
<e-schedule-resource dataSource="@ViewBag.Categories" field="CategoryId" title="Category" name="Categories" textField="text" idField="id" groupIDField='groupId' colorField="color" allowMultiple="true"></e-schedule-resource>
</e-schedule-resources>
<e-schedule-eventsettings dataSource="dataManager">
</e-schedule-eventsettings>
</ejs-schedule> |
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2ScheduleSample.Models;
using EJ2ScheduleSample.Data;
using Newtonsoft.Json;
namespace EJ2ScheduleSample.Controllers
{
public class HomeController : Controller
{
private ScheduleDataContext _context;
public IActionResult Index()
{
List<ResourceDataSourceModel> projects = new List<ResourceDataSourceModel>();
projects.Add(new ResourceDataSourceModel { text = "PROJECT 1", id = 1, color = "#cb6bb2" });
projects.Add(new ResourceDataSourceModel { text = "PROJECT 2", id = 2, color = "#56ca85" });
ViewBag.Projects = projects;
List<ResourceDataSourceModel> categories = new List<ResourceDataSourceModel>();
categories.Add(new ResourceDataSourceModel { text = "Nancy", id = 1, groupId = 1, color = "#df5286" });
categories.Add(new ResourceDataSourceModel { text = "Steven", id = 2, groupId = 1, color = "#7fa900" });
categories.Add(new ResourceDataSourceModel { text = "Robert", id = 3, groupId = 2, color = "#ea7a57" });
categories.Add(new ResourceDataSourceModel { text = "Smith", id = 4, groupId = 2, color = "#5978ee" });
ViewBag.Categories = categories;
ViewBag.Resources = new string[] { "Projects", "Categories" };
return View();
}
public IActionResult Schedule()
{
return View();
}
class ResourceDataSourceModel
{
public int id { set; get; }
public string text { set; get; }
public string color { set; get; }
public int? groupId { set; get; }
}
[HttpPost]
public List<ScheduleEvent> LoadData([FromBody]Params param)
{
DateTime start = (param.CustomStart != new DateTime()) ? param.CustomStart : param.StartDate;
DateTime end = (param.CustomEnd != new DateTime()) ? param.CustomEnd : param.EndDate;
return _context.ScheduleEvents.Where(app => (app.StartTime >= start && app.StartTime <= end) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList(); // Here filtering the events based on the start and end date value.
}
public class Params
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime CustomStart { get; set; }
public DateTime CustomEnd { get; set; }
}
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; }
}
[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
{
int intMax = _context.ScheduleEvents.ToList().Count > 0 ? _context.ScheduleEvents.ToList().Max(p => p.Id) : 1;
for (var i = 0; i < param.added.Count; i++)
{
var value = (param.action == "insert") ? param.value : param.added[i];
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
ScheduleEvent appointment = new ScheduleEvent()
{
StartTime = startTime,
EndTime = endTime,
Subject = value.Subject,
IsAllDay = value.IsAllDay,
StartTimezone = value.StartTimezone,
EndTimezone = value.EndTimezone,
RecurrenceRule = value.RecurrenceRule,
RecurrenceID = value.RecurrenceID,
RecurrenceException = value.RecurrenceException,
Description = value.Description,
CategoryId = value.CategoryId,
ProjectId = value.ProjectId
};
_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;
appointment.EndTime = endTime;
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.ProjectId = value.ProjectId;
appointment.CategoryId = value.CategoryId;
}
_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();
}
return _context.ScheduleEvents.ToList();
}
public HomeController(ScheduleDataContext context)
{
_context = context;
}
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
}
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View();
}
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
} |
<ejs-schedule id="schedule" width="100%" height="670px" selectedDate=@ViewBag.Today popupClose="onPopupClose" popupOpen="onPopupOpen" editorTemplate="#EditorTemplate" showQuickInfo="false">
<e-schedule-eventsettings>
<e-data-manager url="/OData/Appointments"
adaptor="ODataV4Adaptor"
crossDomain="true"
headers='@new Object[]{ new Dictionary<string, object>{ { "organisationid", ViewBag.Organisation.Id} } }'>
</e-data-manager>
<e-eventsettings-fields id="Id">
<e-field-subject id="Subject" name="Subject" title="Subject"></e-field-subject>
<e-field-starttime id="StartTime" name="StartTime"></e-field-starttime>
<e-field-endtime id="EndTime" name="EndTime"></e-field-endtime>
<e-field-location id="Location" name="Location" title="Location"></e-field-location>
<e-field-description id="Description" name="Description" title="Description"></e-field-description>
</e-eventsettings-fields>
</e-schedule-eventsettings>
</ejs-schedule>
Thank you for your support
Basil
|
<ejs-schedule id="schedule" height="750px" selectedDate="new DateTime(2018,10,4)" currentView="Week" popupOpen="onPopupOpen" editorTemplate="#EventEditorTemplate">
<e-schedule-eventsettings query="new ej.data.Query().from('EventDatas')">
<e-data-manager Url="http://localhost:25255/odata" adaptor="ODataV4Adaptor" headers='@new Object[]{ new Dictionary<string, object>{ { "organisationid", ViewBag.organisationId} } }' crossDomain="true">
</e-data-manager>
</e-schedule-eventsettings>
</ejs-schedule> |