blazor-devexpress-dot-blazor-dot-dxscheduler-53ed869a.md
Fires before an updated appointment is saved to the AppointmentsSource object.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
[Parameter]
public EventCallback<SchedulerAppointmentOperationEventArgs> AppointmentUpdating { get; set; }
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. |
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.
<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
The following code snippet uses the Cancel property to restrict non-Admin users from updating appointments in the DxScheduler:
<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
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;
}
}
}
public class Appointment {
public Appointment() {}
public int AppointmentType { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string Caption { get; set; }
public string Description { get; set; }
public string Location { get; set; }
public int Label { get; set; }
public int Status { get; set; }
public bool AllDay { get; set; }
public string Recurrence { get; set; }
}
public static partial class RecurringAppointmentCollection {
public static List<Appointment> GetAppointments() {
DateTime date = DateTimeUtils.GetBeginOfMonth(DateTime.Now);
date = DateTimeUtils.GetWeekStart(date);
return new List<Appointment>() {
new Appointment {
AppointmentType = 1,
Caption = "Watercolor Landscape",
Label = 5,
StartDate = date + (new TimeSpan(2, 13, 0, 0)),
EndDate = date + (new TimeSpan(2, 14, 30, 0)),
Recurrence = string.Format("<RecurrenceInfo Start=\"{0}\" End=\"{1}\" WeekDays=\"36\" Id=\"04dcc127-df56-49d7-baff-ce4b6264addd\" OccurrenceCount=\"10\" Range=\"1\" Type=\"1\" />", ToString(date + (new TimeSpan(2, 13, 0, 0))), ToString(date + (new TimeSpan(2, 14, 30, 0)))),
ResourceId = 0
},
new Appointment {
AppointmentType = 1,
Caption = "Oil Painting for Beginners",
Label = 2,
StartDate = date + (new TimeSpan(1, 12, 0, 0)),
EndDate = date + (new TimeSpan(1, 13, 30, 0)),
Recurrence = string.Format("<RecurrenceInfo Start=\"{0}\" End=\"{1}\" WeekDays=\"18\" Id=\"72e3db8f-cdb6-4aaa-afe1-e3c6b80ce99e\" OccurrenceCount=\"10\" Range=\"1\" Type=\"1\" />", ToString(date + (new TimeSpan(1, 12, 0, 0))), ToString(date + (new TimeSpan(1, 13, 30, 0)))),
ResourceId = 0
},
new Appointment {
AppointmentType = 1,
Caption = "Testing",
Label = 8,
StartDate = date + (new TimeSpan(1, 14, 0, 0)),
EndDate = date + (new TimeSpan(1, 15, 0, 0)),
Recurrence = string.Format("<RecurrenceInfo Start=\"{0}\" End=\"{1}\" WeekDays=\"2\" Id=\"15129fd3-9eb0-4861-8c43-c61844137f17\" OccurrenceCount=\"2\" Frequency=\"2\" Range=\"1\" Type=\"1\" />", ToString(date + (new TimeSpan(1, 14, 0, 0))), ToString(date + (new TimeSpan(1, 15, 0, 0)))),
ResourceId = 1
},
new Appointment {
AppointmentType = 1,
Caption = "Meeting of Instructors",
Label = 1,
StartDate = date + (new TimeSpan(1, 10, 0, 0)),
EndDate = date + (new TimeSpan(1, 10, 45, 0)),
Recurrence = string.Format("<RecurrenceInfo Start=\"{0}\" End=\"{1}\" WeekDays=\"62\" Id=\"6de79b21-6b16-4dea-9736-c500058ec858\" OccurrenceCount=\"25\" Range=\"1\" Type=\"1\" />", ToString(date + (new TimeSpan(1, 10, 0, 0))), ToString(date + (new TimeSpan(1, 10, 45, 0)))),
ResourceId = 1
},
new Appointment {
AppointmentType = 1,
Caption = "Monthly Planning",
Label = 1,
StartDate = date + (new TimeSpan(3, 16, 0, 0)),
EndDate = date + (new TimeSpan(3, 17, 0, 0)),
Recurrence = string.Format("<RecurrenceInfo Start=\"{0}\" End=\"{1}\" DayNumber=\"24\" WeekOfMonth=\"0\" Id=\"cd9da802-d166-47d1-a8df-1101fcc50d53\" OccurrenceCount=\"2\" Range=\"1\" Type=\"2\" />", ToString(date + (new TimeSpan(3, 16, 0, 0))), ToString(date + (new TimeSpan(3, 17, 0, 0)))),
ResourceId = 2
},
new Appointment {
AppointmentType = 1,
Caption = "Annual Open Day",
Label = 6,
StartDate = date + (new TimeSpan(27, 10, 30, 0)),
EndDate = date + (new TimeSpan(27, 14, 0, 0)),
Recurrence = string.Format("<RecurrenceInfo Start=\"{0}\" Month=\"{1}\" DayNumber=\"{2}\" WeekOfMonth=\"0\" Id=\"bd5dc726-0fa6-4965-99e0-bf69063218e6\" Type=\"3\" />", ToString(date + (new TimeSpan(27, 10, 30, 0))), (date + (new TimeSpan(27, 10, 30, 0))).Month, (date + (new TimeSpan(27, 10, 30, 0))).Day),
ResourceId = 3
}
};
}
private static string ToString(DateTime dateTime) {
return dateTime.ToString(CultureInfo.InvariantCulture);
}
}
See Also