Ejemplo n.º 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var request = filterContext.HttpContext.Request;

            Visitor visitor = new Visitor()
            {
                Login = (request.IsAuthenticated) ? filterContext.HttpContext.User.Identity.Name : "null",
                Ip    = request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.UserHostAddress,
                Url   = request.RawUrl,
                Date  = DateTime.UtcNow
            };

            using (var db = new MakeItContext())
            {
                db.Visitors.Add(visitor);
                db.SaveChanges();
            }
            base.OnActionExecuting(filterContext);
        }
Ejemplo n.º 2
0
        public void OnException(ExceptionContext filterContext)
        {
            var exceptionDetail = new ExceptionDetail()
            {
                ExceptionMessage = filterContext.Exception.Message,
                StackTrace       = filterContext.Exception.StackTrace,
                ControllerName   = filterContext.RouteData.Values["controller"].ToString(),
                ActionName       = filterContext.RouteData.Values["action"].ToString(),
                Date             = DateTime.Now
            };

            using (var db = new MakeItContext())
            {
                db.ExceptionDetails.Add(exceptionDetail);
                db.SaveChanges();
            }

            filterContext.ExceptionHandled = true;
        }
 /// <summary>
 /// Saves all pending changes
 /// </summary>
 /// <returns>The number of objects in an Added, Modified, or Deleted state</returns>
 public int SaveChanges()
 {
     // Save changes with the default options
     return(_dbContext.SaveChanges());
 }