Created
July 27, 2010 15:44
-
-
Save ryansroberts/492389 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
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