public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext.Response.IsSuccessStatusCode && actionExecutedContext.Request.Headers.SelectMany(x => x.Value).Any(x => x.Contains("hal"))) { ObjectContent responseContent = actionExecutedContext.Response.Content as ObjectContent; object responseValue = responseContent.Value; RestResourceBuilder.BuilderResource(responseValue, actionExecutedContext.Request); } }
//Depois que foi executada public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { //Só aplicar hateoas se o meu accept for 'application/hal+json' if (actionExecutedContext.Response.IsSuccessStatusCode && actionExecutedContext.Request.Headers.SelectMany(s => s.Value).Any(a => a.Contains("hal"))) //Verifica se deu sucesso ou não e contiver hal { ObjectContent responseContent = actionExecutedContext.Response.Content as ObjectContent; //No formato de um ObjectContent object responseValue = responseContent.Value; RestResourceBuilder.BuildResource(responseValue, actionExecutedContext.Request); } }