Skip to main content

DxScheduler.AppointmentInserting Event

Fires before a new appointment is added to the AppointmentsSource object.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public EventCallback<SchedulerAppointmentOperationEventArgs> AppointmentInserting { get; set; }

Event Data

The AppointmentInserting event's data class is SchedulerAppointmentOperationEventArgs. The following properties provide information specific to this event:

Property Description
Appointment Specifies the target appointment.
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.

Remarks

This event fires before modifications are applied to the Scheduler’s appointment collection. You can access a database or another service and validate that an appointment was inserted. If validation is successful, pass the appointment further. If not, you can cancel appointment insertion (set the event argument’s Cancel property to true) and display an error message (the service is unavailable or the appointment conflicts with another appointment in the database).

To access the inserted appointment and modify its properties, use the event argument’s Appointment property.

If the operation is not canceled, the appointment is added to the AppointmentsSource object and the AppointmentInserted event is raised.

<DxScheduler DataStorage="..."
             AppointmentInserting="@AppointmentInserting">
    <DxSchedulerDayView ShowWorkTimeOnly="true"></DxSchedulerDayView>
</DxScheduler>


@code {
    ...

    async Task AppointmentInserting(SchedulerAppointmentOperationEventArgs e) {
        MedicalAppointments insertedItem = e.Appointment.SourceObject as MedicalAppointments;
        HttpResponseMessage response = await PostItemAsync(insertedItem);

        if(response.IsSuccessStatusCode) {
            using var responseStream = await response.Content.ReadAsStreamAsync();
            MedicalAppointments newItem = await JsonSerializer.DeserializeAsync<MedicalAppointments>(responseStream);
            insertedItem.id = newItem.id;
        }
        else
            e.Cancel = true;
    }
}    

View Example: Scheduler for Blazor - How to implement CRUD operations with a Web API Service

The following code snippet uses the Cancel property to restrict non-Admin users from adding appointments to the DxScheduler.

<DxScheduler StartDate="@(new DateTime(2018, 10, 10))"
             DataStorage="@DataStorage" 
             AppointmentInserting="(e) => AppointmentInserting(e)">
</DxScheduler>


@if (PopupVisible) {
    <DxPopup HeaderText="Warning" CloseButtonClick="@(() => PopupVisible = false)">
        <p>You are not allowed to add new appointments to the scheduler. Please contact your system administrator for details.</p>
    </DxPopup>
}

@code {
    bool popupVisible = false;
    bool PopupVisible { get => popupVisible; set { popupVisible = value; InvokeAsync(StateHasChanged); } }

  void AppointmentInserting(SchedulerAppointmentOperationEventArgs e) {
      if (currentUser.Role != "Admin") {
          e.Cancel = true;
          PopupVisible = true;
      }
  }
}

Run Demo: Scheduler - User Action Customization

See Also