How to prevent the CRUD action on scheduler appointments for specific resources?
This knowledge base article explains how to prevent CRUD action on appointments for specific resource.
Step 1: Create an MVC application with default scheduler code example by referring the following knowledge base link.
https://www.syncfusion.com/kb/3606/how-to-add-the-ejmvc-schedule-control-in-the-mvc-application
Also, define the scheduler with Resources option, DragStop and BeforeAppointmentChange client-side events as shown below.
@(Html.EJ().Schedule("Schedule1")
.Width("100%")
.Height("525px")
.Orientation(Orientation.Horizontal)
.CurrentDate(new DateTime(2017, 04, 20))
.ScheduleClientSideEvents(evt => evt.DragStop("onDragStop")
.BeforeAppointmentChange("onBeforeAppointmentChange"))
.Resources(res =>
{
res.Field("OwnerId").Title("Owner").Name("Owners").AllowMultiple(true)
.ResourceSettings(flds => flds.Datasource(ViewBag.Owners).Text("text").Id("id").Color("color")).Add();
})
.Group(gr =>
{
gr.Resources(ViewBag.Resources);
})
.AppointmentSettings(fields => fields.Datasource(ViewBag.dataSource)
.Id("Id")
.Subject("Subject")
.StartTime("StartTime")
.EndTime("EndTime")
.AllDay("AllDay")
.Recurrence("Recurrence")
.RecurrenceRule("RecurrenceRule")
.ResourceFields("OwnerId")
)
)
Step 2: Within the DragStop and BeforeAppointmentChange scheduler events, any CRUD actions like edit and drag performed on specific resource appointments will be prevented. For example, in the below sample, 8-12 a appointment can be dragged and edited only for the resources with prefix as 8-12 series but not for other resources.
function onDragStop(args) {
var schObj = $("#Schedule1").ejSchedule("instance");
var dragRes = new ej.DataManager(schObj._resCollection[0].dataSource).executeLocal(new ej.Query().where(schObj._resCollection[0].id, ej.FilterOperators.equal, args.appointment.OwnerId));
var dragResname = dragRes[0].text;
if (dragResname.indexOf("8-12") != 0) {
args.cancel = true;
alert("It is restricted");
}
}
function onBeforeAppointmentChange(args) {
var schObj = $("#Schedule1").ejSchedule("instance");
var newRes = new ej.DataManager(schObj._resCollection[0].dataSource).executeLocal(new ej.Query().where(schObj._resCollection[0].id, ej.FilterOperators.equal, parseInt(args.appointment.changed[0].OwnerId)));
var newName = newRes[0].text;
if ((newName.indexOf("8-12") != 0)) {
args.cancel = true;
alert("It is restricted");
}
}
Step 3: Run the sample, now drag and drop the Meeting appointment from 8-12 a to 8-12 b resource, appointment will render in new resource cell as shown below.

Figure 1: Appointment displayed in a new resource with the name 8-12b.
Step 4: Now drag and drop the Meeting appointment from 8-12 b to k-1 resource, appointment will not render in new resource cell.
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/217370/ze/Sample459344947