Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Update to WebApi 4.0.0
add: Webapi odata controller for tests
  • Loading branch information
borzav committed Mar 11, 2013
1 parent 32c313a commit 0ab0a24
Show file tree
Hide file tree
Showing 8 changed files with 3,543 additions and 2 deletions.
199 changes: 199 additions & 0 deletions Controllers/GeoData/PlacesController.cs
@@ -0,0 +1,199 @@
using JayData.Models.GeoData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Spatial;
using System.Web.Http;
using System.Web.Http.OData;
using System.Web.Http.OData.Query;

namespace JayData.Controllers.GeoData
{
public class PlacesController : ODataController
{
protected List<Place> data { get; set; }

public PlacesController()
{
data = new List<Place>();
data.Add(new Place() { Id = 0, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-1.56, 29.76) });
data.Add(new Place() { Id = 1, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-2.56, 19.76) });
data.Add(new Place() { Id = 2, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-3.56, 9.76) });
data.Add(new Place() { Id = 3, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-4.56, -9.76) });
data.Add(new Place() { Id = 4, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-10.56, -19.76) });


for (int i = 0; i < data.Count; i++)
{
data[i].Gp = GeometryPoint.Create(-1.56 - i, 29.76 + i);

SpatialBuilder spatialBuilder = SpatialBuilder.Create();
GeographyPipeline geographyPipeline = spatialBuilder.GeographyPipeline;
geographyPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
geographyPipeline.BeginGeography(SpatialType.LineString);
geographyPipeline.BeginFigure(new GeographyPosition(-1.56, 29.76));
geographyPipeline.LineTo(new GeographyPosition(-1.58, 29.78));
geographyPipeline.LineTo(new GeographyPosition(5, 50));
geographyPipeline.EndFigure();
geographyPipeline.EndGeography();
data[i].Ls = (GeographyLineString)spatialBuilder.ConstructedGeography;

SpatialBuilder spatialBuilder1 = SpatialBuilder.Create();
GeographyPipeline geographyPipeline1 = spatialBuilder1.GeographyPipeline;
geographyPipeline1.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
geographyPipeline1.BeginGeography(SpatialType.MultiPoint);
geographyPipeline1.BeginFigure(new GeographyPosition(-1.56, 29.76));
geographyPipeline1.EndFigure();
geographyPipeline1.BeginFigure(new GeographyPosition(-3.56, 50));
geographyPipeline1.EndFigure();
geographyPipeline1.EndGeography();
data[i].Mp = (GeographyMultiPoint)spatialBuilder1.ConstructedGeography;

SpatialBuilder spatialBuilder2 = SpatialBuilder.Create();
GeographyPipeline geographyPipeline2 = spatialBuilder2.GeographyPipeline;
geographyPipeline2.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
geographyPipeline2.BeginGeography(SpatialType.Polygon);
geographyPipeline2.BeginFigure(new GeographyPosition(-2, 2));
geographyPipeline2.LineTo(new GeographyPosition(2, 2));
geographyPipeline2.LineTo(new GeographyPosition(2, -2));
geographyPipeline2.LineTo(new GeographyPosition(-2, -2));
geographyPipeline2.LineTo(new GeographyPosition(-2, 2));
geographyPipeline2.EndFigure();
geographyPipeline2.BeginFigure(new GeographyPosition(-1, 1));
geographyPipeline2.LineTo(new GeographyPosition(1, 1));
geographyPipeline2.LineTo(new GeographyPosition(1, -1));
geographyPipeline2.LineTo(new GeographyPosition(-1, -1));
geographyPipeline2.LineTo(new GeographyPosition(-1, 1));
geographyPipeline2.EndFigure();
geographyPipeline2.EndGeography();
data[i].Pol = (GeographyPolygon)spatialBuilder2.ConstructedGeography;

SpatialBuilder spatialBuilder3 = SpatialBuilder.Create();
GeographyPipeline geographyPipeline3 = spatialBuilder3.GeographyPipeline;
geographyPipeline3.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
geographyPipeline3.BeginGeography(SpatialType.MultiPolygon);
geographyPipeline3.BeginGeography(SpatialType.Polygon);
geographyPipeline3.BeginFigure(new GeographyPosition(-2, 2));
geographyPipeline3.LineTo(new GeographyPosition(2, 2));
geographyPipeline3.LineTo(new GeographyPosition(2, -2));
geographyPipeline3.LineTo(new GeographyPosition(-2, -2));
geographyPipeline3.LineTo(new GeographyPosition(-2, 2));
geographyPipeline3.EndFigure();
geographyPipeline3.BeginFigure(new GeographyPosition(-1, 1));
geographyPipeline3.LineTo(new GeographyPosition(1, 1));
geographyPipeline3.LineTo(new GeographyPosition(1, -1));
geographyPipeline3.LineTo(new GeographyPosition(-1, -1));
geographyPipeline3.LineTo(new GeographyPosition(-1, 1));
geographyPipeline3.EndFigure();
geographyPipeline3.EndGeography();
geographyPipeline3.BeginGeography(SpatialType.Polygon);
geographyPipeline3.BeginFigure(new GeographyPosition(-4, 4));
geographyPipeline3.LineTo(new GeographyPosition(4, 4));
geographyPipeline3.LineTo(new GeographyPosition(4, -4));
geographyPipeline3.LineTo(new GeographyPosition(-4, -4));
geographyPipeline3.LineTo(new GeographyPosition(-4, 4));
geographyPipeline3.EndFigure();
geographyPipeline3.BeginFigure(new GeographyPosition(-1, 1));
geographyPipeline3.LineTo(new GeographyPosition(1, 1));
geographyPipeline3.LineTo(new GeographyPosition(1, -1));
geographyPipeline3.LineTo(new GeographyPosition(-1, -1));
geographyPipeline3.LineTo(new GeographyPosition(-1, 1));
geographyPipeline3.EndFigure();
geographyPipeline3.EndGeography();
geographyPipeline3.EndGeography();
data[i].MPol = (GeographyMultiPolygon)spatialBuilder3.ConstructedGeography;

SpatialBuilder spatialBuilder4 = SpatialBuilder.Create();
GeographyPipeline geographyPipeline4 = spatialBuilder4.GeographyPipeline;
geographyPipeline4.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
geographyPipeline4.BeginGeography(SpatialType.MultiLineString);
geographyPipeline4.BeginGeography(SpatialType.LineString);
geographyPipeline4.BeginFigure(new GeographyPosition(-1.56, 29.76));
geographyPipeline4.LineTo(new GeographyPosition(-1.58, 29.78));
geographyPipeline4.LineTo(new GeographyPosition(5, 50));
geographyPipeline4.EndFigure();
geographyPipeline4.EndGeography();
geographyPipeline4.BeginGeography(SpatialType.LineString);
geographyPipeline4.BeginFigure(new GeographyPosition(-2.56, 30.76));
geographyPipeline4.LineTo(new GeographyPosition(-2.58, 30.78));
geographyPipeline4.LineTo(new GeographyPosition(6, 51));
geographyPipeline4.EndFigure();
geographyPipeline4.EndGeography();
geographyPipeline4.BeginGeography(SpatialType.LineString);
geographyPipeline4.BeginFigure(new GeographyPosition(-1.56, 29.76));
geographyPipeline4.LineTo(new GeographyPosition(-1.58, 29.78));
geographyPipeline4.LineTo(new GeographyPosition(5, 50));
geographyPipeline4.EndFigure();
geographyPipeline4.EndGeography();
geographyPipeline4.BeginGeography(SpatialType.LineString);
geographyPipeline4.BeginFigure(new GeographyPosition(-2.56, 30.76));
geographyPipeline4.LineTo(new GeographyPosition(-2.58, 30.78));
geographyPipeline4.LineTo(new GeographyPosition(8, 52));
geographyPipeline4.EndFigure();
geographyPipeline4.EndGeography();
geographyPipeline4.EndGeography();
data[i].MLs = (GeographyMultiLineString)spatialBuilder4.ConstructedGeography;



SpatialBuilder spatialBuilder5 = SpatialBuilder.Create();
GeographyPipeline geographyPipeline5 = spatialBuilder5.GeographyPipeline;
geographyPipeline5.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
geographyPipeline5.BeginGeography(SpatialType.Collection);
geographyPipeline5.BeginGeography(SpatialType.LineString);
geographyPipeline5.BeginFigure(new GeographyPosition(-1.56, 29.76));
geographyPipeline5.LineTo(new GeographyPosition(-1.58, 29.78));
geographyPipeline5.LineTo(new GeographyPosition(5, 50));
geographyPipeline5.EndFigure();
geographyPipeline5.EndGeography();
geographyPipeline5.BeginGeography(SpatialType.Point);
geographyPipeline5.BeginFigure(new GeographyPosition(-1.56, 29.76));
geographyPipeline5.EndFigure();
geographyPipeline5.EndGeography();
geographyPipeline5.BeginGeography(SpatialType.LineString);
geographyPipeline5.BeginFigure(new GeographyPosition(-1.56, 29.76));
geographyPipeline5.LineTo(new GeographyPosition(-1.58, 29.78));
geographyPipeline5.LineTo(new GeographyPosition(5, 50));
geographyPipeline5.EndFigure();
geographyPipeline5.EndGeography();
geographyPipeline5.EndGeography();
data[i].Coll = (GeographyCollection)spatialBuilder5.ConstructedGeography;

}

}

[Queryable(AllowedQueryOptions=AllowedQueryOptions.All)]
public IQueryable<Place> Get()
{
return data.AsQueryable();
}

public Place Get([FromODataUri] int key)
{
Place place = data.Where(a => a.Id == key).SingleOrDefault();
if (place == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}

return place;
}

public Place Patch([FromODataUri] int key, Delta<Place> patch)
{
Place movieToPatch = data.Where(a => a.Id == key).SingleOrDefault();
patch.Patch(movieToPatch);
return movieToPatch;
}

public Place Post(Place item)
{
item.Id = data.Count;
return item;
}

}
}
23 changes: 23 additions & 0 deletions Models/GeoData/Place.cs
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Spatial;
using System.Web;

namespace JayData.Models.GeoData
{
public class Place
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public GeographyPoint Entrance { get; set; }
public GeometryPoint Gp { get; set; }
public GeographyLineString Ls { get; set; }
public GeographyMultiPoint Mp { get; set; }
public GeographyPolygon Pol { get; set; }
public GeographyMultiPolygon MPol { get; set; }
public GeographyMultiLineString MLs { get; set; }
public GeographyCollection Coll { get; set; }
}
}
4 changes: 3 additions & 1 deletion jaydata.csproj
Expand Up @@ -86,7 +86,7 @@
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Http.OData">
<HintPath>packages\Microsoft.AspNet.WebApi.OData.4.0.0-rtm-130205\lib\net40\System.Web.Http.OData.dll</HintPath>
<HintPath>packages\Microsoft.AspNet.WebApi.OData.4.0.0\lib\net40\System.Web.Http.OData.dll</HintPath>
</Reference>
<Reference Include="System.Web.Routing" />
<Reference Include="System.Web.Services" />
Expand Down Expand Up @@ -157,13 +157,15 @@
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\GeoData\PlacesController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\ODataInheritance\CarsController.cs" />
<Compile Include="Controllers\WebApiOData\ArticlesController.cs" />
<Compile Include="Controllers\WebApiOData\CategoriesController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\GeoData\Place.cs" />
<Compile Include="Models\ODataInheritance\ODataInheritanceModels.cs" />
<Compile Include="Models\TaskManager\Category.cs">
<DependentUpon>TaskManagerModel.tt</DependentUpon>
Expand Down
2 changes: 1 addition & 1 deletion packages.config
Expand Up @@ -13,7 +13,7 @@
<package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.OData" version="4.0.0-rtm-130205" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.OData" version="4.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.Data.Edm" version="5.2.0" targetFramework="net45" />
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 0ab0a24

Please sign in to comment.