-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeoplesController.cs
67 lines (57 loc) · 1.74 KB
/
PeoplesController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData;
using Microsoft.AspNetCore.OData.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace oData
{
public interface IPeopleService
{
IEnumerable<Person> Get();
}
public interface ITripsService
{
IEnumerable<Trip> Get();
}
[EnableQuery]
[ODataRoute("Peoples")]
public class PeoplesController : Controller
{
[HttpGet]
public IEnumerable<Person> Get()
{
return DemoDataSources.Instance.People.AsQueryable();
}
[ODataRoute("({key})")]
public IActionResult GetEntity(string key)
{
var entity = DemoDataSources.Instance.People.FirstOrDefault(c => c.ID == key);
return entity == null ? (IActionResult)NotFound() : new ObjectResult(entity);
}
[ODataRoute("({key})/Trips")]
public IActionResult GetTrips(string key)
{
var entity = DemoDataSources.Instance.People.FirstOrDefault(c => c.ID == key);
return entity == null ? (IActionResult)NotFound() : new ObjectResult(entity.Trips);
}
}
[EnableQuery]
[ODataRoute("Trips")]
public class TripsController : Controller
{
[HttpGet]
public IEnumerable<Trip> Get()
{
return DemoDataSources.Instance.Trips.AsQueryable();
}
[ODataRoute("({key})")]
public IActionResult GetEntity(string key)
{
var entity = DemoDataSources.Instance.Trips.FirstOrDefault(c => c.ID == key);
return entity == null ? (IActionResult)NotFound() : new ObjectResult(entity);
}
}
}