Back to Devexpress

AppointmentCRUDEventArgs Class

wpf-devexpress-dot-xpf-dot-scheduling-2b1c2a5b.md

latest3.9 KB
Original Source

AppointmentCRUDEventArgs Class

The base class for CRUD (create, read, update, delete) events.

Namespace : DevExpress.Xpf.Scheduling

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

NuGet Package : DevExpress.Wpf.Scheduling

Declaration

csharp
public class AppointmentCRUDEventArgs :
    RoutedEventArgs
vb
Public Class AppointmentCRUDEventArgs
    Inherits RoutedEventArgs

Remarks

The code snippet below saves changes to 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()) {
        dbContext.AppointmentEntities.AddRange(args.AddToSource.Select(x => (AppointmentEntity)x.SourceObject));

        foreach(var appt in args.UpdateInSource.Select(x => (AppointmentEntity)x.SourceObject))
            AppointmentEntityHelper.CopyProperties(appt, dbContext.AppointmentEntities.Find(appt.Id));

        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()
        dbContext.AppointmentEntities.AddRange(args.AddToSource.Select(Function(x) CType(x.SourceObject, AppointmentEntity)))

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

        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

Inheritance

Object EventArgs RoutedEventArgs AppointmentCRUDEventArgs AppointmentAddedEventArgs

AppointmentEditedEventArgs

AppointmentRemovedEventArgs

AppointmentRestoredEventArgs

See Also

AppointmentCRUDEventArgs Members

DevExpress.Xpf.Scheduling Namespace