Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Categories and Towns Controllers return type changed to JSON #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Categories and Towns Controllers return type changed to JSON
Vladislav Hadzhiyski committed Jan 1, 2015
commit 7180ecf5b2ec883279a4a9d56e85cca8fe829824
1 change: 1 addition & 0 deletions Ads-REST-Services/Ads.Common/Ads.Common.csproj
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="CollectionExtensions.cs" />
<Compile Include="QueryableExtensions.cs" />
</ItemGroup>
<ItemGroup>
12 changes: 12 additions & 0 deletions Ads-REST-Services/Ads.Common/CollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Ads.Common
{
using System.Collections.Generic;

public static class CollectionExtensions
{
public static IEnumerable<T> ToEnumerable<T>(this IEnumerable<T> collection)
{
return collection;
}
}
}
10 changes: 7 additions & 3 deletions Ads-REST-Services/Ads.Web/Controllers/CategoriesController.cs
Original file line number Diff line number Diff line change
@@ -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
/// <returns>List of all categories sorted by Id</returns>
[HttpGet]
public IEnumerable<Category> GetCategories()
public JsonResult<IEnumerable<Category>> 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());
}
}
}
10 changes: 7 additions & 3 deletions Ads-REST-Services/Ads.Web/Controllers/TownsController.cs
Original file line number Diff line number Diff line change
@@ -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
/// <returns>List of all towns sorted by Id</returns>
[HttpGet]
public IEnumerable<Town> GetTowns()
public JsonResult<IEnumerable<Town>> 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());
}
}
}