Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DxScheduler.AppointmentUpdating Event

Fires before an updated appointment is saved to the AppointmentsSource object.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[Parameter]
public EventCallback<SchedulerAppointmentOperationEventArgs> AppointmentUpdating { get; set; }

#Event Data

The AppointmentUpdating 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 updated. If validation is successful, pass the appointment further. If not, you can cancel the appointment update (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 updated appointment and change it, use the event argument’s Appointment property.

If the operation is not canceled, the updated appointment is saved to the AppointmentsSource object and the AppointmentUpdated event is raised.

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

@code {
    ...

    async Task AppointmentUpdating(SchedulerAppointmentOperationEventArgs e) {
        MedicalAppointments updatedItem = e.Appointment.SourceObject as MedicalAppointments;

        var myContent = JsonSerializer.Serialize(updatedItem);
        var request = new HttpRequestMessage(HttpMethod.Put, fullWebAPIUrl + Convert.ToInt32(updatedItem.id));
        request.Content = new StringContent(myContent, Encoding.Unicode, "application/json");

        var response = await Http.SendAsync(request);
        if(!response.IsSuccessStatusCode)
            e.Cancel = true;
    }
}    

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

#Task-Based Examples

#Restrict User Actions

The following code snippet uses the Cancel property to restrict non-Admin users from updating appointments in the DxScheduler:

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

@if (PopupVisible) {
    <DxPopup HeaderText="Warning" CloseButtonClick="@(() => PopupVisible = false)">
        <p>You are not allowed to update appointments in 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 AppointmentUpdating(SchedulerAppointmentOperationEventArgs e) {
        if (currentUser.Role != "Admin") {
          e.Cancel = true;
          PopupVisible = true;
        }
    }
}

Run Demo: Scheduler - User Action Customization

#Keep User Changes

After you cancel an appointment update, the component discards user edits and closes the edit form. To keep user input, handle the AppointmentFormClosing event and enable its Cancel event argument. The following example prevents users from creating reccurent appointments that occur only once:

<DxScheduler @bind-StartDate="@StartDate"
             DataStorage="@DataStorage"
             AppointmentUpdating="AppointmentUpdating"
             AppointmentInserting="AppointmentInserting"
             AppointmentFormClosing="AppointmentFormClosing">
    <DxSchedulerWeekView ShowWorkTimeOnly="true"></DxSchedulerWeekView>
</DxScheduler>
<DxPopup @bind-Visible="@AlertVisible"
         CloseOnEscape="true"
         CloseOnOutsideClick="true"
         ShowCloseButton="true"
         HeaderText="Note"
         BodyText="The recurrent appointment occurs only once. Increase the appointment count or create a regular appointment.">
</DxPopup>

@code {
    bool AlertVisible = false;
    bool ValidationFailed = false;
    DateTime StartDate { get; set; } = DateTime.Today;

    DxSchedulerDataStorage DataStorage = new DxSchedulerDataStorage() {
        AppointmentsSource = RecurringAppointmentCollection.GetAppointments(),
        AppointmentMappings = new DxSchedulerAppointmentMappings() {
            Type = "AppointmentType",
            Start = "StartDate",
            End = "EndDate",
            Subject = "Caption",
            AllDay = "AllDay",
            Location = "Location",
            Description = "Description",
            LabelId = "Label",
            StatusId = "Status",
            RecurrenceInfo = "Recurrence"
        }
    };
    bool IsAppointmentValid(DxSchedulerAppointmentItem appointment) {
        if (appointment.IsRecurring && 
                appointment.RecurrenceInfo.Range == SchedulerRecurrenceRange.OccurrenceCount &&
                appointment.RecurrenceInfo.OccurrenceCount == 1)
            return false;
        return true;
    }

    void AppointmentUpdating(SchedulerAppointmentOperationEventArgs e) {
        if (!IsAppointmentValid(e.Appointment)) {
            e.Cancel = true;
            AlertVisible = true;
            ValidationFailed = true;
        }
    }
    void AppointmentInserting(SchedulerAppointmentOperationEventArgs e) {
        if (!IsAppointmentValid(e.Appointment)) {
            e.Cancel = true;
            AlertVisible = true;
            ValidationFailed = true;
        }
    }
    void AppointmentFormClosing(SchedulerAppointmentFormClosingEventArgs e) {
        if (ValidationFailed) {
            e.Cancel = true;
            ValidationFailed = false;
        }
    }
}
See Also