コード例 #1
0
        public void SetResult(ExceptionContext filterContext)
        {
            if (filterContext.ActionIsEqualsThan(EAction.New))
            {
                var routeValue = new RouteValueDictionary(new { controller = filterContext.ControllerName(), action = EAction.Index });
                filterContext.Result = new RedirectToRouteResult(routeValue);
            }

            if (filterContext.ActionIsEqualsThan(EAction.Edit))
            {
                var routeValue = new RouteValueDictionary(new { controller = filterContext.ControllerName(), action = EAction.Index });
                filterContext.Result = new RedirectToRouteResult(routeValue);
            }
        }
コード例 #2
0
        public static object DeserializeContext(this ExceptionContext filterContext, string contextModel)
        {
            var controllerName = filterContext.ControllerName();
            var typeArgument   = ModelDictionary.ModelToEntityType[controllerName];
            var methodType     = typeof(StringExtensions).GetMethod("Deserialize");
            var genericMethod  = methodType.MakeGenericMethod(new[] { typeArgument });

            return(genericMethod.Invoke(typeof(ContextExtensions), new object[] { contextModel }));
        }
コード例 #3
0
        public void SetResult(ExceptionContext filterContext)
        {
            if (filterContext.ActionIsEqualsThan(ActionType.Login))
            {
                SessionSettings.AssignAllSessions();

                var tempData = filterContext.Controller.TempData;
                filterContext.Result = new ViewResult {
                    ViewName = ActionType.Login.ToString(), TempData = tempData
                };
            }

            if (filterContext.ControllerIsEqualsThan(EntityType.Account))
            {
                var tempData = filterContext.Controller.TempData;
                filterContext.Result = new ViewResult {
                    ViewName = ActionType.Login.ToString(), TempData = tempData
                };
            }

            if (filterContext.ActionIsEqualsThan(ActionType.ChangePassword))
            {
                var routeValue = new RouteValueDictionary(new { controller = EntityType.Account, action = ActionType.Login });
                filterContext.Result = new RedirectToRouteResult(routeValue);
            }

            if (filterContext.ActionIsEqualsThan(ActionType.New))
            {
                var routeValue = new RouteValueDictionary(new { controller = filterContext.ControllerName(), action = ActionType.Index });
                filterContext.Result = new RedirectToRouteResult(routeValue);
            }

            if (filterContext.ActionIsEqualsThan(ActionType.Edit))
            {
                var routeValue = new RouteValueDictionary(new { controller = filterContext.ControllerName(), action = ActionType.Index });
                filterContext.Result = new RedirectToRouteResult(routeValue);
            }

            if (filterContext.ActionIsEqualsThan(ActionType.Export))
            {
                new TempDataFactory().RemoveFailure(filterContext.ControllerBase());
                var csv    = new CsvExport().RetrieveError();
                var stream = new StreamFactory().Csv(csv, "Error");
                filterContext.Result = stream;
            }

            if (filterContext.ActionIsEqualsThan(ActionType.Create))
            {
                var idCreated = SessionSettings.RetrieveIdCreated;
                if (idCreated.IsGreaterThanZero())
                {
                    var routeValue = new RouteValueDictionary(new { controller = filterContext.ControllerName(), action = ActionType.Edit, id = idCreated });
                    filterContext.Result = new RedirectToRouteResult(routeValue);
                }
                else
                {
                    var contextModel = filterContext.DeserializeContext(SessionSettings.RetrieveContextModel);
                    var viewData     = idCreated.IsGreaterThanZero() ? new { id = idCreated } : contextModel;
                    var tempData     = filterContext.Controller.TempData;
                    filterContext.Result = new ViewResult {
                        ViewName = ActionType.New.ToString(), ViewData = new ViewDataDictionary(viewData), TempData = tempData
                    };
                }
            }

            if (filterContext.ActionIsEqualsThan(ActionType.Update))
            {
                var routeValue = new RouteValueDictionary(new { controller = filterContext.ControllerName(), action = ActionType.Edit, id = filterContext.IdToRequest() });
                filterContext.Result = new RedirectToRouteResult(routeValue);
            }

            if (filterContext.Exception.GetType() == typeof(SessionNotFoundException) || filterContext.Exception.GetType() == typeof(InvalidSerialException))
            {
                var controller = SessionSettings.ExistsLoginType ? SessionSettings.RetrieveLoginType.ToString() : EntityType.Account.ToString();
                var routeValue = new RouteValueDictionary(new { controller = controller, action = ActionType.Login });
                filterContext.Result = new RedirectToRouteResult(routeValue);
            }

            if (filterContext.Exception.GetType() == typeof(UnauthorizedAccessException) || filterContext.ActionIsEqualsThan(ActionType.ExternalLogin))
            {
                filterContext.Result = new JsonFactory().Failure(typeof(UnauthorizedAccessException), filterContext.MessageException());
            }
        }
コード例 #4
0
 public static bool ControllerIsEqualsThan(this ExceptionContext filterContext, EController eControllerName)
 {
     return(filterContext.ControllerName().IsEqualTo(eControllerName.ToString()));
 }
コード例 #5
0
 public static bool ControllerIsEqualsThan(this ExceptionContext filterContext, EntityType entityType)
 {
     return(filterContext.ControllerName().IsEquals(entityType.ToString()));
 }