Example #1
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (!filterContext.Canceled)
            {
                var cache = new CacheWrapper(filterContext.HttpContext.Cache);
                var values = filterContext.RouteData.Values;
                if (!(values.ContainsKey("controller") && values.ContainsKey("action") && values.ContainsKey("id")))
                {
                    throw new ArgumentException("Necessary route values not found in controller context.");
                }
                if (Service == null)
                {
                    throw new NullReferenceException("The service is null, where an instance of ITopicsService was required.");
                }

                if (!cache.VisitedActionAlready(values["controller"].ToString(), values["action"].ToString(), values["id"].ToString(), filterContext.HttpContext.Request.UserHostAddress))
                {
                    Service.AddVisit(Convert.ToInt32(values["id"]));
                }
            }
            base.OnActionExecuted(filterContext);
        }