Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created May 18, 2017 21:05
Show Gist options
  • Save dcomartin/3ad9b1eabbc912492bc6214c3b8764f5 to your computer and use it in GitHub Desktop.
Save dcomartin/3ad9b1eabbc912492bc6214c3b8764f5 to your computer and use it in GitHub Desktop.
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