using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Text.RegularExpressions;
using Forms4.Models.Entities;

namespace Forms4.Filters
{
    public class TagsFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            
            var post = ((Post)filterContext.ActionParameters["post"]);
            if (!string.IsNullOrEmpty(post.Content))
            {
                Regex scripts = new Regex("<script>[^<>]*</script>");
                post.Content = scripts.Replace(post.Content, "");
            }
            base.OnActionExecuting(filterContext);
             
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }

        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {

        }

        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {

        }
    }
}