-
Notifications
You must be signed in to change notification settings - Fork 6
/
MainViewModel.vb
40 lines (38 loc) · 1.3 KB
/
MainViewModel.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Imports DevExpress.Mvvm
Imports EntityFrameworkIssues.Issues
Imports DevExpress.Mvvm.DataAnnotations
Imports System.Linq
Imports System.Collections.Generic
Imports DevExpress.Mvvm.Xpf
Public Class MainViewModel
Inherits ViewModelBase
Private _Context As IssuesContext
Private _ItemsSource As IList(Of User)
Public ReadOnly Property ItemsSource As IList(Of User)
Get
If _ItemsSource Is Nothing AndAlso Not DevExpress.Mvvm.ViewModelBase.IsInDesignMode Then
_Context = New IssuesContext()
_ItemsSource = _Context.Users.ToList()
End If
Return _ItemsSource
End Get
End Property
<Command>
Public Sub ValidateRow(ByVal args As RowValidationArgs)
Dim item = CType(args.Item, User)
If args.IsNewItem Then _Context.Users.Add(item)
_Context.SaveChanges()
End Sub
<Command>
Public Sub ValidateRowDeletion(ByVal args As ValidateRowDeletionArgs)
Dim item = CType(args.Items.Single(), User)
_Context.Users.Remove(item)
_Context.SaveChanges()
End Sub
<Command>
Public Sub DataSourceRefresh(ByVal args As DataSourceRefreshArgs)
_ItemsSource = Nothing
_Context = Nothing
RaisePropertyChanged(Nameof(ItemsSource))
End Sub
End Class