This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
8 changed files
with
3,543 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-175 KB
...AspNet.WebApi.OData.4.0.0-rtm-130205/Microsoft.AspNet.WebApi.OData.4.0.0-rtm-130205.nupkg
Binary file not shown.
Binary file added
BIN
+164 KB
packages/Microsoft.AspNet.WebApi.OData.4.0.0/Microsoft.AspNet.WebApi.OData.4.0.0.nupkg
Binary file not shown.
Binary file renamed
BIN
+349 KB
...30205/lib/net40/System.Web.Http.OData.dll → ...4.0.0/lib/net40/System.Web.Http.OData.dll
Binary file not shown.
Oops, something went wrong.