Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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