Пример #1
0
        protected ObjectResult Element <TElement>(IApiResource elementToReturn)
            where TElement : IApiResource
        {
            var view = new ElementView <TElement>(elementToReturn);

            return(new ObjectResult(view));
        }
Пример #2
0
        void IActionFilter.OnActionExecuted(ActionExecutedContext context)
        {
            IActionResult actionResult = context.Result;

            if (actionResult is ObjectResult &&
                !(actionResult is BadRequestObjectResult))
            {
                IResultView result = actionResult.GetClosestResultView();

                if (result is CollectionView)
                {
                    CollectionView output = (CollectionView)result;
                    (context.Result as ObjectResult).Value = GetHateoasCollectionView(output);
                    return;
                }
                else if (result is ElementView)
                {
                    ElementView output = (ElementView)result;
                    (context.Result as ObjectResult).Value = GetHateoasElementView(output.ViewModel);
                    return;
                }
                else
                {
                    throw new Exception("Can't generate a HATEOAS context for this IActionResult");
                }
            }
        }