@@ -11,14 +11,27 @@ namespace CorporateEvents.SharePointWeb.Controllers {
11
11
public class EventsController : Controller {
12
12
#region [ Index ]
13
13
[ SharePointContextFilter ]
14
- public ActionResult Index ( int offset = 0 ) {
14
+ public ActionResult Index ( string category = "" ) {
15
+ var spContext = SharePointContextProvider . Current . GetSharePointContext ( HttpContext ) ;
16
+
15
17
using ( var clientContext = HttpContext . GetUserClientContextForSPHost ( ) ) {
18
+ ViewBag . SPHostUrl = spContext . SPHostUrl ;
19
+ ViewBag . Category = category ;
20
+
16
21
var list = clientContext . Web . GetListByTitle ( ListDetails . EventsListName ) ;
22
+ var categoryQuery = string . Empty ;
23
+ if ( ! string . IsNullOrEmpty ( category ) ) {
24
+ categoryQuery = CAML . Where ( CAML . Eq ( CAML . FieldValue ( Event . FIELD_CATEGORY , "Text" , category ) ) ) ;
25
+ }
26
+ var orderByQuery = CAML . OrderBy ( new OrderByField ( "Title" ) ) ;
27
+
17
28
var caml = new CamlQuery ( ) {
18
- ViewXml = CAML . ViewQuery ( )
29
+ ViewXml = CAML . ViewQuery ( categoryQuery , orderByQuery , rowLimit : 50 )
19
30
} ;
20
31
var events = list . GetItems ( caml ) ;
32
+ clientContext . Load ( events ) ;
21
33
clientContext . ExecuteQuery ( ) ;
34
+
22
35
var eventsList = events . Cast < ListItem > ( ) . Select ( item => new Event ( item ) ) . ToList ( ) ;
23
36
return View ( eventsList ) ;
24
37
}
@@ -55,7 +68,7 @@ public ActionResult Item(int id) {
55
68
/// <param name="maxCount">Maximum number of items to return.</param>
56
69
/// <returns></returns>
57
70
[ SharePointContextFilter ]
58
- public ActionResult Featured ( int maxCount = 5 ) {
71
+ public ActionResult Featured ( int maxCount = 3 ) {
59
72
using ( var clientContext = HttpContext . GetUserClientContextForSPHost ( ) ) {
60
73
ViewBag . SPHostUrl = HttpContext . Request . QueryString [ "SPHostUrl" ] ;
61
74
@@ -71,7 +84,8 @@ public ActionResult Featured(int maxCount = 5) {
71
84
)
72
85
)
73
86
) ,
74
- CAML . OrderBy ( new OrderByField ( Event . FIELD_DATE ) ) )
87
+ CAML . OrderBy ( new OrderByField ( Event . FIELD_DATE ) ) ,
88
+ rowLimit : maxCount )
75
89
} ;
76
90
77
91
var list = clientContext . Web . Lists . GetByTitle ( ListDetails . EventsListName ) ;
0 commit comments