コード例 #1
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());
            }
        }
コード例 #2
0
 public ActionResult Index()
 {
     SessionSettings.AssignAllSessions();
     return(View("Index"));
 }