Last active
April 5, 2019 13:32
-
-
Save chamook/d109e35dfae293b1b9795262905917a4 to your computer and use it in GitHub Desktop.
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
public class Item | |
{ | |
public string Name { get; } | |
public string Id { get; } | |
public string ColourId { get; } | |
public Item(string name, string id, string colourId) | |
{ | |
Name = name ?? throw new ArgumentNullException(nameof(name)); | |
Id = id ?? throw new ArgumentNullException(nameof(id)); | |
ColourId = colourId ?? throw new ArgumentNullException(nameof(colourId)); | |
} | |
} | |
public class ItemController : Controller | |
{ | |
public static string RedId = "abc123"; | |
public static string YellowId = "def456"; | |
public static string BlueId = "ghi789"; | |
[HttpGet("/items/{colourId}")] | |
public IActionResult Get(string colourId) | |
{ | |
if (string.Equals(colourId, RedId, StringComparison.OrdinalIgnoreCase)) | |
{ | |
return Ok( | |
new { | |
Items = new [] { | |
new Item("Rose", "1", RedId) | |
}}); | |
} | |
if (string.Equals(colourId, BlueId, StringComparison.OrdinalIgnoreCase)) | |
{ | |
return Ok( | |
new { | |
Items = new [] { | |
new Item("Violet", "2", BlueId) | |
}}); | |
} | |
return Ok(new { Items = new Item[0]}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment