-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainViewModel.vb
52 lines (49 loc) · 2.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
41
42
43
44
45
46
47
48
49
50
51
52
Imports DevExpress.Mvvm
Imports EntityFrameworkIssues.Issues
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
Imports System
Imports System.Linq.Expressions
Imports DevExpress.Data.Filtering
Imports DevExpress.Xpf.Data
Imports System.Linq
Imports System.Threading.Tasks
Imports System.Data.Entity
Imports System.Collections
Public Class MainViewModel
Inherits ViewModelBase
Private Function MakeFilterExpression(ByVal filter As CriteriaOperator) As Expression(Of Func(Of Issue, Boolean))
Dim converter = New GridFilterCriteriaToExpressionConverter(Of Issue)()
Return converter.Convert(filter)
End Function
<Command>
Public Sub FetchPage(ByVal args As FetchPageAsyncArgs)
Const pageTakeCount As Integer = 5
args.Result = Task.Run(Of FetchRowsResult)(Function()
Dim context = New IssuesContext()
Dim queryable = context.Issues.AsNoTracking().SortBy(args.SortOrder, defaultUniqueSortPropertyName:=NameOf(Issue.Id)).Where(MakeFilterExpression(CType(args.Filter, CriteriaOperator)))
Return queryable.Skip(args.Skip).Take(args.Take * pageTakeCount).ToArray()
End Function)
End Sub
<Command>
Public Sub GetTotalSummaries(ByVal args As GetSummariesAsyncArgs)
args.Result = Task.Run(Function()
Dim context = New IssuesContext()
Dim queryable = context.Issues.Where(MakeFilterExpression(CType(args.Filter, CriteriaOperator)))
Return queryable.GetSummaries(args.Summaries)
End Function)
End Sub
Private _Users As IList
Public ReadOnly Property Users As IList
Get
If _Users Is Nothing AndAlso Not DevExpress.Mvvm.ViewModelBase.IsInDesignMode Then
Dim context = New IssuesContext()
_Users = context.Users.[Select](Function(user) New With {
.Id = user.Id,
.Name = user.FirstName & " " + user.LastName
}).ToArray()
End If
Return _Users
End Get
End Property
End Class