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
Add a sample with composite key
- Loading branch information
Showing
4 changed files
with
67 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,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OData.Query; | ||
using ODataRoutingSample.Models; | ||
|
||
namespace ODataRoutingSample.Controllers | ||
{ | ||
public class PeopleController : ControllerBase | ||
{ | ||
private static IList<Person> _persons = new List<Person> | ||
{ | ||
new Person | ||
{ | ||
FirstName = "Goods", | ||
LastName = "Zhangg", | ||
}, | ||
new Person | ||
{ | ||
FirstName = "Magazine", | ||
LastName = "Jingchan", | ||
}, | ||
new Person | ||
{ | ||
FirstName = "Fiction", | ||
LastName = "Hollewye" | ||
}, | ||
}; | ||
|
||
|
||
[HttpGet] | ||
[EnableQuery] | ||
public IActionResult Get(CancellationToken token) | ||
{ | ||
return Ok(_persons); | ||
} | ||
|
||
[EnableQuery] | ||
public IActionResult Get(string keyFirstName, string keyLastName) | ||
{ | ||
var person = _persons.FirstOrDefault(p => p.FirstName == keyFirstName && p.LastName == keyLastName); | ||
if (person == null) | ||
{ | ||
return NotFound($"Not found person with FirstName = {keyFirstName} and LastName = {keyLastName}"); | ||
} | ||
|
||
return Ok(person); | ||
} | ||
} | ||
} |
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
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,12 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
namespace ODataRoutingSample.Models | ||
{ | ||
public class Person | ||
{ | ||
public string FirstName { get; set; } | ||
|
||
public string LastName { get; set; } | ||
} | ||
} |