예제 #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            // Get the instanceId to identify the current page flow.

            var instanceId = GetInstanceIdValue();

            if (instanceId != null)
            {
                // Get the current state for the identified page flow.

                Pageflow = _pageflowEngine.GetPageflow <TPageflow>(instanceId.Value);
            }

            // If no state then start a page flow.

            if (Pageflow == null)
            {
                Pageflow = CreatePageflow();
                _pageflowEngine.StartPageflow(Pageflow);
            }

            // If the user is not at the right point in the flow then reset them.

            var currentStep = CurrentStep;

            if (filterContext.ActionDescriptor.ActionName != currentStep.Name)
            {
                var step = Pageflow.GetStep(filterContext.ActionDescriptor.ActionName);
                if (step != null && step.CanBeMovedTo)
                {
                    _pageflowEngine.MoveToStep(Pageflow, filterContext.ActionDescriptor.ActionName);
                }
                else
                {
                    // Propagate any query string.

                    var routeUrl  = GetRoute(currentStep).RouteReference.GenerateUrl(new { instanceId = Pageflow.Id }).AsNonReadOnly();
                    var clientUrl = HttpContext.GetClientUrl().AsNonReadOnly();
                    if (clientUrl.QueryString != null)
                    {
                        clientUrl.QueryString.Remove("instanceId");
                        if (clientUrl.QueryString.Count > 0)
                        {
                            routeUrl.QueryString.Add(clientUrl.QueryString);
                        }
                    }
                    filterContext.Result = RedirectToUrl(routeUrl);
                }
            }
        }
예제 #2
0
 protected virtual ActionResult Step(string name)
 {
     _pageflowEngine.MoveToStep(Pageflow, name);
     return(RedirectToRoute(GetRoute(Pageflow.GetStep(name)).RouteReference, new { instanceId = Pageflow.Id }));
 }