Skip to content

Instantly share code, notes, and snippets.

@ryansroberts
Created July 27, 2010 15:44
Show Gist options
  • Save ryansroberts/492389 to your computer and use it in GitHub Desktop.
Save ryansroberts/492389 to your computer and use it in GitHub Desktop.
Will render the View 'Document' as the convention is from model type. If there's no view (or you force the content type), it will render it as xml / json / text/plain depending on negotiation
public static class Extensions
{
public static ResourceResult NotFoundOnNull<TResult>(this ResourceController controller,Func<TResult> f) where TResult:class
{
var result = f();
return result == null ? controller.NotFound() : controller.OK(result);
}
}
public class DocumentController : ResourceController
{
readonly IDocumentService documentService;
public DocumentController(IDocumentService documentService)
{
this.documentService = documentService;
}
public ResourceResult Get(DocumentUrl url)
{
return this.NotFoundOnNull(() => documentService.ById(url.Id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment