OpenSource » SampleCode » NexportWebApiMvcSampleSite Sample MVC 4 Website project that demonstrates the use of the NexPort WebApi
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

Updated to work with GetCatalogs method (GetCatalogIds has been obsoleted).

Changeset 138874f56881

Parent 490adac41f40

by Profile picture of User 240Clayton Miller <clayton.miller@nexportengineering.com>

Changes to 26 files · Browse files at 138874f56881 Showing diff from parent 490adac41f40 Diff from another changeset...

 
 
 
 
 
 
 
 
 
1
2
3
4
5
 
31
32
33
34
35
36
37
38
39
40
41
 
42
43
44
 
1
 
2
3
4
 
30
31
32
 
33
34
35
36
37
 
 
38
39
40
41
@@ -1,5 +1,4 @@
 using System; -using System.Collections;  using System.Collections.Generic;    namespace NexportWebApiDemo.ApiModels.v1 @@ -31,14 +30,12 @@
  public class CatalogRequest   {   public Guid group_id { get; set; } - public int availability { get; set; }   public int publishing_model { get; set; }   }     public class CatalogResponse   { - public IList<Guid> catalogs { get; set; } - public Guid id { get; set; } + public IList<CatalogResponseItem> catalogs { get; set; }   }     public class CatalogResponseItem
 
1
2
 
3
4
5
 
22
23
24
25
26
27
28
29
30
31
32
33
34
 
 
35
36
37
 
1
 
2
3
4
5
 
22
23
24
 
25
26
27
 
 
 
 
 
 
28
29
30
31
32
@@ -1,5 +1,5 @@
 using System; -using System.Collections.Generic; +using System.Linq;  using System.Web.Mvc;  using NexportWebApiDemo.ApiModels.v1;  using NexportWebApiDemoClient; @@ -22,16 +22,11 @@
  var catRequest = new CatalogRequest()   {   group_id = new Guid("ed5ba4ac-73e4-4e64-837f-b26cb8ef3c4b"), - availability = 2,   publishing_model = 0   };   - var catResponse = WebApiRequests.GetCatalogIds(catRequest, authToken.access_token); - var catalogs = new List<CatalogResponseItem>(); - for (var i = 0; i < 30; i++) - { - catalogs.Add(WebApiRequests.GetCatalog(catResponse.catalogs[i], authToken.access_token)); - } + var catResponse = WebApiRequests.GetCatalogs(catRequest, authToken.access_token); + var catalogs = catResponse.catalogs.ToList();   ViewBag.Catalogs = catalogs;   return View();   }
 
 
 
75
76
77
78
 
79
80
81
 
75
76
77
 
78
79
80
81
@@ -75,7 +75,7 @@
    <div class="col-md-9">   <div class="row"> - <table class="table"> + <table class="table table-striped">   <thead>   <tr>   <th>Catalog</th>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
41
42
43
44
45
46
47
 
48
49
 
50
51
52
 
40
41
42
 
43
44
45
 
46
47
 
48
49
50
51
@@ -40,13 +40,12 @@
  var catalogRequest = new CatalogRequest()   {   group_id = new Guid("f60904d7-0164-41cc-a246-46aa21a49af9"), - availability = 2,   publishing_model = 1   };   - var getCatalogIdsResponse = WebApiRequests.GetCatalogIds(catalogRequest, accessToken); + var getCatalogResponse = WebApiRequests.GetCatalogs(catalogRequest, accessToken);   - Console.WriteLine(getCatalogIdsResponse.catalogs); + Console.WriteLine(getCatalogResponse.catalogs);   }   }   }
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
15
16
17
18
19
20
 
21
22
23
 
36
37
38
39
 
40
41
42
43
 
44
45
46
 
1
 
 
2
 
 
 
3
4
5
6
7
8
 
9
10
11
12
13
14
 
15
16
17
18
 
31
32
33
 
34
35
36
37
 
38
39
40
41
@@ -1,23 +1,18 @@
 using System; -using System.Collections.Generic; -using System.Linq;  using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks;  using NexportWebApiDemo.ApiModels.v1;    namespace NexportWebApiDemoClient  {   public class WebApiRequests   { - private static string BaseUri = "http://local.nexportcampus.com/api/v1/"; + private const string BaseUri = "http://local.nexportcampus.com/api/v1/";     public static WAAuthenticationTokenResponse Authenticate(WAAuthTokenRequest request)   {   using (var client = new HttpClient())   { - var requestUri = BaseUri + "AdminApi/Authenticate"; + const string requestUri = BaseUri + "AdminApi/Authenticate";   var response = client.PostAsJsonAsync(requestUri, request).Result;     //TODO Check return status @@ -36,11 +31,11 @@
  }   }   - public static CatalogResponse GetCatalogIds(CatalogRequest request, Guid accessToken, int page = 1, int perPage = 30) + public static CatalogResponse GetCatalogs(CatalogRequest request, Guid accessToken, int page = 1, int perPage = 30)   {   using (var client = new HttpClient())   { - var requestUri = BaseUri + "LearningApi/GetCatalogIds?access_token=" + accessToken + "&page=" + page + + var requestUri = BaseUri + "LearningApi/GetCatalogs?access_token=" + accessToken + "&page=" + page +   "&per_page=" + perPage;   var response = client.PostAsJsonAsync(requestUri, request).Result;