BlazorScheduler
BlazorScheduler copied to clipboard
How to prevent overlap appoitments?
Hi,
I have implemented a function within the Scheduler class to prevent the creation of overlapping appointments. The CheckAppointmentOverlap method checks if a given date falls within the range of existing appointments. By calling this function, I can ensure that appointments do not overlap when initiating a drag operation. However, I am currently facing challenges in preventing the ability to end an appointment on an existing appointment.
public bool CheckAppointmentOverlap(DateTime date) { foreach (var existingAppointment in _appointments) { // Check if the given date falls within the existing appointment range if (date >= existingAppointment.Start.Date && date <= existingAppointment.End.Date) { return true; // Overlap detected } } return false; // No overlap }
and call it from here:
` public void BeginDrag(SchedulerDay day) { if (!EnableAppointmentsCreationFromScheduler) return;
if (_appointments.IsNotEmpty())
{
if (CheckAppointmentOverlap(day.Day))
{
return;
}
}
_draggingStart = _draggingEnd = day.Day;
_showNewAppointment = true;
_draggingAppointmentAnchor = _draggingStart;
StateHasChanged();
} `
Any idea how to prevent that?