Back to Devexpress

AppointmentCRUDEventArgs.DeleteFromSource Property

wpf-devexpress-dot-xpf-dot-scheduling-dot-appointmentcrudeventargs-79b30499.md

latest4.3 KB
Original Source

AppointmentCRUDEventArgs.DeleteFromSource Property

Returns the list of appointments to delete from the data source.

Namespace : DevExpress.Xpf.Scheduling

Assembly : DevExpress.Xpf.Scheduling.v25.2.dll

NuGet Package : DevExpress.Wpf.Scheduling

Declaration

csharp
public IReadOnlyList<AppointmentItem> DeleteFromSource { get; }
vb
Public ReadOnly Property DeleteFromSource As IReadOnlyList(Of AppointmentItem)

Property Value

TypeDescription
IReadOnlyList<AppointmentItem>

A list of DevExpress.Xpf.Scheduling.AppointmentItem objects that have been deleted from the scheduler.

|

Remarks

When a user updates or deletes a pattern, the scheduler deletes all ChangedOccurrence and DeletedOccurrence appointments for the corresponding recurring series. The Occurrence appointments are not stored in any collection to avoid a stack overflow for infinite recurring series. These appointments are automatically generated at runtime based on the pattern’s AppointmentItem.RecurrenceInfo property.

When a user updates a pattern, the scheduler only adds the pattern appointment to the UpdateInSource and Appointments lists. The ChangedOccurrence and DeletedOccurrence appointments are added to the DeleteFromSource list.

When a user modifies or deletes an Occurrence appointment, the scheduler adds the corresponding exception ( ChangedOccurrence or DeletedOccurrence ) to the AddToSource and Appointments lists.

The code snippet below deletes appointments from the data source.

csharp
// data context
public class SchedulingContext : DbContext {
    public SchedulingContext() : base(CreateConnection(), true) { }
    static DbConnection CreateConnection() {
        //...
    }
    public DbSet<AppointmentEntity> AppointmentEntities { get; set; }
    public DbSet<ResourceEntity> ResourceEntities { get; set; }
}

// save changes to the data source
public void ProcessChanges(AppointmentCRUDEventArgs args) {
    using(var dbContext = new SchedulingContext()) {

        foreach(var appt in args.DeleteFromSource.Select(x => (AppointmentEntity)x.SourceObject))
            dbContext.AppointmentEntities.Remove(dbContext.AppointmentEntities.Find(appt.Id));

        dbContext.SaveChanges();
    }
}
vb
' data context
Public Class SchedulingContext
    Inherits DbContext

    Public Sub New()
        MyBase.New(CreateConnection(), True)
    End Sub
    Private Shared Function CreateConnection() As DbConnection
        '...
    End Function
    Public Property AppointmentEntities() As DbSet(Of AppointmentEntity)
    Public Property ResourceEntities() As DbSet(Of ResourceEntity)
End Class

' save changes to the data source
Public Sub ProcessChanges(ByVal args As AppointmentCRUDEventArgs)
    Using dbContext = New SchedulingContext()

        For Each appt In args.DeleteFromSource.Select(Function(x) CType(x.SourceObject, AppointmentEntity))
            dbContext.AppointmentEntities.Remove(dbContext.AppointmentEntities.Find(appt.Id))
        Next appt

        dbContext.SaveChanges()
    End Using
End Sub

See Also

AppointmentCRUDEventArgs Class

AppointmentCRUDEventArgs Members

DevExpress.Xpf.Scheduling Namespace