Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
Created September 8, 2011 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbeletsky/1202916 to your computer and use it in GitHub Desktop.
Save alexbeletsky/1202916 to your computer and use it in GitHub Desktop.
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