Skip to content

Instantly share code, notes, and snippets.

@dcomartin dcomartin/todo.cs

Created May 25, 2017
Embed
What would you like to do?
public class TodoConverter : IStateConverter
{
public Task<object> ConvertAsync(StateConverterContext context)
{
var urlHelper = context.HttpContext.RequestServices.GetRequiredService<IUrlHelper>();
var todo = context.Object as TodoModel;
var actions = new List<Siren.Core.Action>();
actions.Add(new Siren.Core.Action
{
Name = "delete",
Title = "Delete Todo",
Method = "DELETE",
Href = urlHelper.Action("Delete", "Todo"),
});
if (todo.IsCompleted == false)
{
actions.Add(
new Siren.Core.Action
{
Name = "complete",
Title = "Complete Todo",
Method = "PUT",
Href = urlHelper.Action("Complete", "Todo"),
});
}
var document = new Document
{
Class = new Class { "todo" },
Properties = todo,
Href = urlHelper.Action("Get", "Todo"),
Actions = new Actions(actions)
};
return Task.FromResult<object>(document);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.