wpf-devexpress-dot-xpf-dot-scheduling-2b1c2a5b.md
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
public class AppointmentCRUDEventArgs :
RoutedEventArgs
Public Class AppointmentCRUDEventArgs
Inherits RoutedEventArgs
The code snippet below saves changes to the data source.
// 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();
}
}
' 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
Object EventArgs RoutedEventArgs AppointmentCRUDEventArgs AppointmentAddedEventArgs
See Also