DxScheduler.AppointmentInserted Event
Fires after a new appointment is added to the AppointmentsSource object.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public EventCallback<DxSchedulerAppointmentItem> AppointmentInserted { get; set; }
Parameters
Type | Description |
---|---|
DxSchedulerAppointmentItem | A DxSchedulerAppointmentItem object that stores an added appointment. |
Remarks
Use the AppointmentInserted
event to access an added appointment after it has been saved to the AppointmentsSource object.
Note
To cancel an appointment insertion or to modify an inserted appointment before it is saved, use the AppointmentInserting event.
The following code snippet does the following:
- Creates a DxSchedulerDataStorage object, sets its AppointmentsSource to
null
. - Assigns the created data storage object to the Scheduler’s DataStorage property.
- In the OnInitialized lifecycle method, creates a new DbContext and loads data from the DbContext to the DxSchedulerDataStorage.AppointmentsSource property.
Handles
AppointmentInserted
, AppointmentUpdated, and AppointmentRemoved events to implement CRUD operations in the Scheduler. To access a target appointment, the SourceObject property is used.You can also use AppointmentInserting, AppointmentUpdating, and AppointmentRemoving events to implement CRUD operations. These events fire before modifications are applied to Scheduler’s appointment collection. You can access the database or service and validate that an appointment was in fact inserted/updated/removed. If validation is successful, pass the appointment further. If not, 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).Uses the DbContext.Dispose method to track the context for the component lifetime.
@inject IDbContextFactory<MedicsSchedulingContext> MedicsSchedulingContextFactory
@implements IDisposable
<DxScheduler StartDate="@startDate"
DataStorage="@DataStorage"
AppointmentUpdated="@AppointmentUpdated"
AppointmentInserted="@AppointmentInserted"
AppointmentRemoved="@AppointmentRemoved"
GroupType="SchedulerGroupType.Resource">
<DxSchedulerDayView DayCount="1" ShowWorkTimeOnly="true"></DxSchedulerDayView>
...
<Scales>
<DxSchedulerTimeScale Unit="@SchedulerTimeScaleUnit.Day" UnitCount="1"></DxSchedulerTimeScale>
<DxSchedulerTimeScale Unit="@SchedulerTimeScaleUnit.Hour" UnitCount="2"></DxSchedulerTimeScale>
</Scales>
</DxSchedulerTimelineView>
</DxScheduler>
@code {
DateTime startDate { get; set; } = new DateTime(2016, 10, 10);
MedicsSchedulingContext dbContext { get; set; }
DxSchedulerDataStorage DataStorage = new DxSchedulerDataStorage() {
AppointmentsSource = null,
AppointmentMappings = new DxSchedulerAppointmentMappings() {
Id = "Id",
Type = "EventType",
Start = "StartTime",
End = "EndTime",
Subject = "Subject",
AllDay = "AllDay",
Location = "Location",
Description = "Description",
LabelId = "Label",
StatusId = "Status",
ResourceId = "MedicId",
RecurrenceInfo = "RecurrenceInfo"
},
ResourcesSource = null,
ResourceMappings = new DxSchedulerResourceMappings() {
Id = "Id",
Caption = "DisplayName"
}
};
protected override void OnInitialized() {
dbContext = MedicsSchedulingContextFactory.CreateDbContext();
DataStorage.AppointmentsSource = dbContext.MedicalAppointments.ToList();
DataStorage.ResourcesSource = dbContext.Medics.ToList();
}
void AppointmentInserted(DxSchedulerAppointmentItem e) {
dbContext.Add(e.SourceObject);
dbContext.SaveChanges();
}
void AppointmentUpdated(DxSchedulerAppointmentItem e) {
dbContext.SaveChanges();
}
void AppointmentRemoved(DxSchedulerAppointmentItem e) {
dbContext.Remove(e.SourceObject);
dbContext.SaveChanges();
}
public void Dispose() {
dbContext?.Dispose();
}
}