Created
May 18, 2017 21:05
-
-
Save dcomartin/3ad9b1eabbc912492bc6214c3b8764f5 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 TodoCollectionConverter : IStateConverter | |
{ | |
public Task<object> ConvertAsync(StateConverterContext context) | |
{ | |
var todos = (context.Object as IEnumerable<TodoModel>); | |
var path = context.HttpContext.Request.GetDisplayUrl(); | |
var properties = new | |
{ | |
count = todos.Count() | |
}; | |
var document = new Document | |
{ | |
Class = new Class {"todo", "collection"}, | |
Properties = properties, | |
Href = path, | |
}; | |
var entities = todos.Select(a => new Entity | |
{ | |
Class = new Class {"todo"}, | |
Properties = a, | |
Href = $"{path}/{a.TodoId}", | |
}); | |
document.Entities.Add(entities); | |
return Task.FromResult<object>(document); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment