Created
September 8, 2011 08:21
-
-
Save alexbeletsky/1202916 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 HostedByCheckAttribute : ActionFilterAttribute { | |
public override void OnActionExecuting(ActionExecutingContext filterContext) { | |
var postId = filterContext.ActionParameters["id"] as int; | |
var postsRepo = new PostsRepository(); | |
var post = postsRepo.Get(postId); | |
if (!post.IsHostedBy(/* ... */)) { | |
filterContext.Result = new ViewResult { ViewName = "InvalidOwner", ViewBag = filterContext.Controller.ViewBag, ViewData = filterContext.Controller.ViewData }; | |
} | |
} | |
} | |
public class HostedByCheckAttribute : ActionFilterAttribute { | |
[Inject] | |
public IPostRepository Repo { get; set; } | |
public override void OnActionExecuting(ActionExecutingContext filterContext) { | |
var postId = filterContext.ActionParameters["id"] as int; | |
var post = Repo.Get(postId); | |
if (!post.IsHostedBy(/* ... */)) { | |
filterContext.Result = new ViewResult { ViewName = "InvalidOwner", ViewBag = filterContext.Controller.ViewBag, ViewData = filterContext.Controller.ViewData }; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment