Skip to content

Commit ae6be5e

Browse files
CopilotTsvetomir-Hr
andcommitted
Add documentation for RecurrenceEditMode in Scheduler CRUD events
Co-authored-by: Tsvetomir-Hr <106250052+Tsvetomir-Hr@users.noreply.github.com>
1 parent bc68782 commit ae6be5e

File tree

3 files changed

+171
-4
lines changed

3 files changed

+171
-4
lines changed

components/scheduler/editing/edit-appointments.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ By default, the user can only view the appointments, because creating, updating
3232
3333
Main events you need to implement so you can store the appointment information changed or created by the user:
3434

35-
* `OnCreate` - fires when the user saves a new appointment, including an exception for a recurring appointment.
36-
* `OnUpdate` - fires when the user changes an existing appointment. Fires for the recurring appointment when an exception has been created for it.
37-
* `OnDelete` - fires when the user deletes and appointment (including a recurring appointment). You can also enable a [delete confirmation dialog](#delete-confirmation-dialog).
35+
* `OnCreate` - fires when the user saves a new appointment, including an exception for a recurring appointment. The event arguments include a `RecurrenceEditMode` property that indicates whether the user is creating an exception to a recurring appointment (`RecurrenceEditMode.Occurrence`) or a new regular appointment.
36+
* `OnUpdate` - fires when the user changes an existing appointment. Fires for the recurring appointment when an exception has been created for it. The event arguments include a `RecurrenceEditMode` property that indicates whether the user chose to update the entire series (`RecurrenceEditMode.Series`) or only a single occurrence (`RecurrenceEditMode.Occurrence`).
37+
* `OnDelete` - fires when the user deletes an appointment (including a recurring appointment). You can also enable a [delete confirmation dialog](#delete-confirmation-dialog). The event arguments include a `RecurrenceEditMode` property that indicates whether the user chose to delete the entire series (`RecurrenceEditMode.Series`) or only a single occurrence (`RecurrenceEditMode.Occurrence`).
3838

3939
There are two other events that you are not required to handle - you can use them to implement application logic:
4040

@@ -90,6 +90,8 @@ When the user clicks the close button (`x`) of the appointment a confirmation di
9090

9191
The example below shows the signature of the event handlers so you can copy the proper arguments and start implementing your business logic and data storage operations. The example only updates the local collection of appointments used in the UI.
9292

93+
>tip The event arguments for `OnCreate`, `OnUpdate`, and `OnDelete` include a `RecurrenceEditMode` property. This property indicates whether the user chose to modify only a single occurrence or the entire series of a recurring appointment. For detailed information and examples, see the [Handling Recurring Appointments in CRUD Events](slug:scheduler-recurrence#handling-recurring-appointments-in-crud-events) section.
94+
9395
@[template](/_contentTemplates/common/general-info.md#event-callback-can-be-async)
9496

9597
>note It is up to the data access logic to save the data once it is changed in the data collection. The example below showcases when that happens and adds some code to provide a visual indication of the change. In a real application, the code for handling data updates may be entirely different.

components/scheduler/events.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ This article explains the events available in the Telerik Scheduler for Blazor:
2424

2525
## CUD Events
2626

27-
To implement appointment editing, the scheduler exposes the `OnCreate`, `OnDelete` and `OnUpdate` events. They let you propagate the changes the user makes in the UI to the view model and to the data storage. You can read mode in the [Appointment Editing](slug:scheduler-appointments-edit) article.
27+
To implement appointment editing, the scheduler exposes the `OnCreate`, `OnDelete` and `OnUpdate` events. They let you propagate the changes the user makes in the UI to the view model and to the data storage. You can read more in the [Appointment Editing](slug:scheduler-appointments-edit) article.
28+
29+
The event arguments for these events include a `RecurrenceEditMode` property that indicates the user's choice when editing or deleting recurring appointments:
30+
31+
* `RecurrenceEditMode.Series` - The user chose to modify the entire series of recurring appointments.
32+
* `RecurrenceEditMode.Occurrence` - The user chose to modify only a single occurrence of the recurring appointment.
33+
34+
For detailed examples of handling recurring appointments in CRUD events, see the [Handling Recurring Appointments in CRUD Events](slug:scheduler-recurrence#handling-recurring-appointments-in-crud-events) section.
2835

2936
## OnModelInit
3037

components/scheduler/recurrence.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The Telerik Scheduler for Blazor supports displaying and editing of recurring ap
1515
* Configure the Scheduler for using recurring appointments.
1616
* Define recurrence rules and recurrence exceptions in the Scheduler data.
1717
* Edit recurring appointments and exceptions.
18+
* Handle editing and deleting recurring appointments with the recurrence context.
1819

1920
## Basics
2021

@@ -219,6 +220,163 @@ A single Scheduler data item defines one series of recurring appointments. Set t
219220
}
220221
````
221222

223+
## Handling Recurring Appointments in CRUD Events
224+
225+
When users edit, update, or delete a recurring appointment, the Scheduler prompts them to choose whether to modify only the current occurrence or the entire series. This choice is reflected in the `RecurrenceEditMode` property of the event arguments.
226+
227+
### RecurrenceEditMode Property
228+
229+
The `OnCreate`, `OnUpdate`, and `OnDelete` event handlers receive event arguments that include a `RecurrenceEditMode` property. This property indicates the user's choice when interacting with recurring appointments:
230+
231+
* `RecurrenceEditMode.Series` - The user chose to edit or delete the entire series of recurring appointments.
232+
* `RecurrenceEditMode.Occurrence` - The user chose to edit or delete only a single occurrence of the recurring appointment.
233+
234+
### Usage in Event Handlers
235+
236+
You can use the `RecurrenceEditMode` property to implement different logic based on whether the user is modifying a single occurrence or the entire series.
237+
238+
>caption Handle RecurrenceEditMode in OnUpdate and OnDelete events
239+
240+
````RAZOR
241+
<TelerikScheduler Data="@SchedulerData"
242+
@bind-Date="@SchedulerDate"
243+
@bind-View="@SchedulerView"
244+
AllowCreate="true"
245+
AllowDelete="true"
246+
AllowUpdate="true"
247+
OnCreate="@OnSchedulerCreate"
248+
OnDelete="@OnSchedulerDelete"
249+
OnUpdate="@OnSchedulerUpdate"
250+
Height="600px">
251+
<SchedulerViews>
252+
<SchedulerDayView StartTime="@SchedulerViewStartTime" />
253+
<SchedulerWeekView StartTime="@SchedulerViewStartTime" />
254+
<SchedulerMonthView />
255+
</SchedulerViews>
256+
</TelerikScheduler>
257+
258+
@code {
259+
private List<Appointment> SchedulerData { get; set; } = new();
260+
private DateTime SchedulerDate { get; set; } = DateTime.Today;
261+
private SchedulerView SchedulerView { get; set; } = SchedulerView.Week;
262+
private DateTime SchedulerViewStartTime { get; set; } = DateTime.Today.AddHours(8);
263+
264+
private void OnSchedulerCreate(SchedulerCreateEventArgs args)
265+
{
266+
Appointment item = (Appointment)args.Item;
267+
268+
// When creating an exception to a recurring appointment,
269+
// RecurrenceEditMode will be Occurrence
270+
if (args.RecurrenceEditMode == RecurrenceEditMode.Occurrence)
271+
{
272+
// The item will have RecurrenceId set to the parent appointment's Id
273+
Console.WriteLine($"Creating exception for recurring appointment: {item.RecurrenceId}");
274+
}
275+
276+
SchedulerData.Add(item);
277+
}
278+
279+
private void OnSchedulerUpdate(SchedulerUpdateEventArgs args)
280+
{
281+
Appointment item = (Appointment)args.Item;
282+
283+
if (args.RecurrenceEditMode == RecurrenceEditMode.Series)
284+
{
285+
// User chose to update the entire series
286+
Console.WriteLine("Updating entire series of recurring appointments");
287+
288+
// Update the recurring appointment
289+
int originalItemIndex = SchedulerData.FindIndex(a => a.Id == item.Id);
290+
if (originalItemIndex >= 0)
291+
{
292+
SchedulerData[originalItemIndex] = item;
293+
}
294+
}
295+
else if (args.RecurrenceEditMode == RecurrenceEditMode.Occurrence)
296+
{
297+
// User chose to update only this occurrence
298+
Console.WriteLine("Creating exception for single occurrence");
299+
300+
// This creates a new exception appointment
301+
// The item will have RecurrenceId pointing to the parent
302+
int originalItemIndex = SchedulerData.FindIndex(a => a.Id == item.Id);
303+
if (originalItemIndex >= 0)
304+
{
305+
SchedulerData[originalItemIndex] = item;
306+
}
307+
}
308+
}
309+
310+
private void OnSchedulerDelete(SchedulerDeleteEventArgs args)
311+
{
312+
Appointment item = (Appointment)args.Item;
313+
314+
if (args.RecurrenceEditMode == RecurrenceEditMode.Series)
315+
{
316+
// User chose to delete the entire series
317+
Console.WriteLine("Deleting entire series");
318+
319+
// Remove the recurring appointment
320+
SchedulerData.Remove(item);
321+
322+
// Optionally, remove all exceptions for this series
323+
if (!string.IsNullOrEmpty(item.RecurrenceRule))
324+
{
325+
SchedulerData.RemoveAll(a => a.RecurrenceId?.Equals(item.Id) == true);
326+
}
327+
}
328+
else if (args.RecurrenceEditMode == RecurrenceEditMode.Occurrence)
329+
{
330+
// User chose to delete only this occurrence
331+
Console.WriteLine("Deleting single occurrence");
332+
333+
if (item.RecurrenceId != null)
334+
{
335+
// This is already an exception, just remove it
336+
SchedulerData.Remove(item);
337+
338+
// Update the parent appointment's RecurrenceExceptions list
339+
var parentAppointment = SchedulerData.FirstOrDefault(a => a.Id.Equals(item.RecurrenceId));
340+
if (parentAppointment != null)
341+
{
342+
// Remove the exception date from the parent's list
343+
parentAppointment.RecurrenceExceptions?.Remove(item.Start);
344+
}
345+
}
346+
else
347+
{
348+
// This is a recurring appointment, create an exception
349+
// The Scheduler automatically adds the occurrence date to RecurrenceExceptions
350+
SchedulerData.Remove(item);
351+
}
352+
}
353+
}
354+
355+
public class Appointment
356+
{
357+
public Guid Id { get; set; }
358+
public string Title { get; set; } = string.Empty;
359+
public DateTime Start { get; set; }
360+
public DateTime End { get; set; }
361+
public bool IsAllDay { get; set; }
362+
public string RecurrenceRule { get; set; } = string.Empty;
363+
public List<DateTime>? RecurrenceExceptions { get; set; }
364+
public Guid? RecurrenceId { get; set; }
365+
366+
public Appointment()
367+
{
368+
Id = Guid.NewGuid();
369+
}
370+
}
371+
}
372+
````
373+
374+
### Important Considerations
375+
376+
* When the user edits or deletes a single occurrence of a recurring appointment, the Scheduler automatically manages the `RecurrenceExceptions` list and creates exception appointments with the appropriate `RecurrenceId`.
377+
* The `RecurrenceEditMode` property is only relevant when working with recurring appointments. For regular (non-recurring) appointments, this property is not used.
378+
* When creating a new appointment in a time slot that matches a recurring appointment, the user can choose to create an exception or a new independent appointment.
379+
222380
## Recurrence Editor Components
223381

224382
Telerik UI for Blazor provides standalone components that you can use to edit recurring appointments outside the Scheduler or in a [custom Scheduler popup edit form](slug:scheduler-kb-custom-edit-form).

0 commit comments

Comments
 (0)