Created
May 25, 2017 23:36
-
-
Save dcomartin/176beb08e9cf81256a20df740430b25c 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 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