Created
April 21, 2020 18:28
-
-
Save Kikimora/ebc35806a85028a4908965e74b546861 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 interface IMyBriefDto | |
{ | |
public string Name { get; set; } | |
public string Address { get; set; } | |
} | |
public interface IMyDto : IMyBriefDto | |
{ | |
public int Age { get; set; } | |
public string Country { get; set; } | |
} | |
public interface IListItem | |
{ | |
string Id { get; } | |
} | |
public interface IMyListItem : IMyBriefDto, IListItem | |
{ | |
} | |
[DataContract] | |
class MyDto : IMyDto, IMyListItem | |
{ | |
[DataMember] | |
public string Id => Name; | |
[DataMember] | |
public string Name { get; set; } | |
[DataMember] | |
public string Address { get; set; } | |
[DataMember] | |
public int Age { get; set; } | |
[DataMember] | |
public string Country { get; set; } | |
} | |
[AllowAnonymous] | |
[Route("admin/sample")] | |
public class SampleController : ControllerBase | |
{ | |
[HttpGet("list.json")] | |
public IMyBriefDto[] GetListItems() | |
{ | |
return new IMyBriefDto[] | |
{ | |
new MyDto() {Name = "Andrey", Address = "Andrey Address"}, | |
new MyDto() {Name = "Maxim", Address = "Maxim Address"}, | |
new MyDto() {Name = "Sergey", Address = "Sergey Address"}, | |
}; | |
} | |
[HttpGet("{id}")] | |
public IMyDto GetMyDto([FromRoute] string id) | |
{ | |
return id switch | |
{ | |
"Andrey" => new MyDto() {Name = "Andrey", Address = "Andrey Address", Age = 35, Country = "Russia"}, | |
"Maxim" => new MyDto() {Name = "Andrey", Address = "Andrey Address", Age = 35, Country = "Russia"}, | |
"Sergey" => new MyDto() {Name = "Andrey", Address = "Andrey Address", Age = 35, Country = "Russia"}, | |
_ => throw new Exception("Unknown dto") | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment