@@ -70,7 +70,7 @@ The example below shows the signature of the event handlers so you can copy the
7070> caption Example of handling the CUD events in a Scheduler.
7171
7272```` CSHTML
73- @using System.ComponentModel.DataAnnotations @* only for the Required validation in the model *@
73+ @* This sample implements only updates to the view model. Your app must also update the database in the CUD events *@
7474
7575<TelerikScheduler Data="@Appointments"
7676 OnUpdate="@UpdateAppointment"
@@ -92,54 +92,66 @@ The example below shows the signature of the event handlers so you can copy the
9292</TelerikScheduler>
9393
9494@code {
95- // Sample CUD operations over the local data
96- // In a real case, carry the information over to the actual data source
97- void UpdateAppointment(SchedulerUpdateEventArgs args)
95+ // Sample CUD operations over the local data
96+ // In a real case, carry the information over to the actual data source
97+ void UpdateAppointment(SchedulerUpdateEventArgs args)
98+ {
99+ SchedulerAppointment item = (SchedulerAppointment)args.Item;
100+ var matchingItem = Appointments.FirstOrDefault(a => a.Id == item.Id);
101+ if (matchingItem != null)
98102 {
99- SchedulerAppointment item = (SchedulerAppointment)args.Item;
100- var matchingItem = Appointments.FirstOrDefault(a => a.Id == item.Id);
101- if (matchingItem != null)
102- {
103- matchingItem.Title = item.Title;
104- matchingItem.Description = item.Description;
105- matchingItem.StartTime = item.StartTime;
106- matchingItem.EndTime = item.EndTime;
107- matchingItem.IsAllDay = item.IsAllDay;
108- }
103+ matchingItem.Title = item.Title;
104+ matchingItem.Description = item.Description;
105+ matchingItem.StartTime = item.StartTime;
106+ matchingItem.EndTime = item.EndTime;
107+ matchingItem.IsAllDay = item.IsAllDay;
109108 }
110109
111- void AddAppointment(SchedulerCreateEventArgs args)
112- {
113- SchedulerAppointment item = args.Item as SchedulerAppointment;
114- Appointments.Add(item);
115- }
110+ // save to the actual data source here
111+ }
116112
117- void DeleteAppointment(SchedulerDeleteEventArgs args)
118- {
119- SchedulerAppointment item = (SchedulerAppointment)args.Item;
120- Appointments.Remove(item);
121- }
113+ void AddAppointment(SchedulerCreateEventArgs args)
114+ {
115+ SchedulerAppointment item = args.Item as SchedulerAppointment;
116+ Appointments.Add(item);
117+
118+ // save to the actual data source here
119+ }
122120
123- //Handlers for application logic flexibility
124- void EditHandler(SchedulerEditEventArgs args)
121+ void DeleteAppointment(SchedulerDeleteEventArgs args)
122+ {
123+ SchedulerAppointment item = (SchedulerAppointment)args.Item;
124+ Appointments.Remove(item);
125+
126+ // save to the actual data source here
127+ }
128+
129+ //Handlers for application logic flexibility
130+ void EditHandler(SchedulerEditEventArgs args)
131+ {
132+ SchedulerAppointment item = args.Item as SchedulerAppointment;
133+ if (!args.IsNew) // an edit operation, otherwise - an insert operation
125134 {
126- SchedulerAppointment item = args.Item as SchedulerAppointment;
127- if (item != null) // an edit operation, otherwise - an insert operation
135+ // you can prevent opening an item for editing based on a condition
136+ if (item.Title.Contains("vet", StringComparison.InvariantCultureIgnoreCase))
128137 {
129- // you can prevent opening an item for editing based on a condition
130- if (item.Title.Contains("vet", StringComparison.InvariantCultureIgnoreCase))
131- {
132- args.IsCancelled = true;
133- }
138+ args.IsCancelled = true;
134139 }
135140 }
136-
137- void CancelHandler(SchedulerCancelEventArgs args)
141+ else
138142 {
139- // you can know when a user wanted to modify an appointment but decided not to
140- // the model you get contains the new data from the edit form so you can see what they did
141- SchedulerAppointment item = args.Item as SchedulerAppointment ;
143+ // get the time range of the slot the user clicked to add an appointment
144+ DateTime slotStart = item.StartTime;
145+ DateTime slotEnd = item.EndTime ;
142146 }
147+ }
148+
149+ void CancelHandler(SchedulerCancelEventArgs args)
150+ {
151+ // you can know when a user wanted to modify an appointment but decided not to
152+ // the model you get contains the new data from the edit form so you can see what they did
153+ SchedulerAppointment item = args.Item as SchedulerAppointment;
154+ }
143155
144156 // sample data and scheduler settings
145157 public DateTime StartDate { get; set; } = new DateTime(2019, 11, 29);
@@ -180,7 +192,6 @@ The example below shows the signature of the event handlers so you can copy the
180192 public class SchedulerAppointment
181193 {
182194 public int Id { get; set; }
183- [Required]
184195 public string Title { get; set; }
185196 public string Description { get; set; }
186197 public DateTime StartTime { get; set; }
0 commit comments