diff --git a/Ads-REST-Services/Ads.Common/Ads.Common.csproj b/Ads-REST-Services/Ads.Common/Ads.Common.csproj
index e0b0888..de8b855 100644
--- a/Ads-REST-Services/Ads.Common/Ads.Common.csproj
+++ b/Ads-REST-Services/Ads.Common/Ads.Common.csproj
@@ -34,6 +34,7 @@
+
diff --git a/Ads-REST-Services/Ads.Common/CollectionExtensions.cs b/Ads-REST-Services/Ads.Common/CollectionExtensions.cs
new file mode 100644
index 0000000..ca1623a
--- /dev/null
+++ b/Ads-REST-Services/Ads.Common/CollectionExtensions.cs
@@ -0,0 +1,12 @@
+namespace Ads.Common
+{
+ using System.Collections.Generic;
+
+ public static class CollectionExtensions
+ {
+ public static IEnumerable ToEnumerable(this IEnumerable collection)
+ {
+ return collection;
+ }
+ }
+}
diff --git a/Ads-REST-Services/Ads.Web/Controllers/CategoriesController.cs b/Ads-REST-Services/Ads.Web/Controllers/CategoriesController.cs
index 136335d..589e02a 100644
--- a/Ads-REST-Services/Ads.Web/Controllers/CategoriesController.cs
+++ b/Ads-REST-Services/Ads.Web/Controllers/CategoriesController.cs
@@ -4,6 +4,10 @@
using System.Linq;
using System.Web.Http;
+ using Newtonsoft.Json;
+ using System.Web.Http.Results;
+
+ using Ads.Common;
using Ads.Data;
using Ads.Models;
@@ -22,10 +26,10 @@ public CategoriesController(IAdsData data)
// GET api/Categories
/// List of all categories sorted by Id
[HttpGet]
- public IEnumerable GetCategories()
+ public JsonResult> GetCategories()
{
- var categories = this.Data.Categories.All().OrderBy(category => category.Id).ToList();
- return categories;
+ var categories = this.Data.Categories.All().OrderBy(category => category.Id).ToEnumerable();
+ return Json(categories, new JsonSerializerSettings());
}
}
}
diff --git a/Ads-REST-Services/Ads.Web/Controllers/TownsController.cs b/Ads-REST-Services/Ads.Web/Controllers/TownsController.cs
index 7fb68fb..360582b 100644
--- a/Ads-REST-Services/Ads.Web/Controllers/TownsController.cs
+++ b/Ads-REST-Services/Ads.Web/Controllers/TownsController.cs
@@ -4,6 +4,10 @@
using System.Linq;
using System.Web.Http;
+ using Newtonsoft.Json;
+ using System.Web.Http.Results;
+
+ using Ads.Common;
using Ads.Data;
using Ads.Models;
@@ -22,10 +26,10 @@ public TownsController(IAdsData data)
// GET api/Towns
/// List of all towns sorted by Id
[HttpGet]
- public IEnumerable GetTowns()
+ public JsonResult> GetTowns()
{
- var towns = this.Data.Towns.All().OrderBy(town => town.Id).ToList();
- return towns;
+ var towns = this.Data.Towns.All().OrderBy(town => town.Id).ToEnumerable();
+ return Json(towns, new JsonSerializerSettings());
}
}
}