// GET: /Workflow/
        public ActionResult Display(int id)
        {
            //DataObjectLoader DOL = new API.ExternalData.DataObjectLoader();
            WorkflowDisplay wfDisplay = new WorkflowDisplay();

            WFNodeInfo nextNode = null;

            ScreenViewer.API.WorkflowController WFC = new API.WorkflowController();
            var actionResult      = WFC.GetScriptWorkflow(id);
            DataObjectManager DOM = new DataObjectManager();

            if (actionResult != null)
            {
                var response = actionResult as OkNegotiatedContentResult <ScriptWorkflow>;
                ViewBag.WorkflowName   = response.Content.WorkflowName;
                wfDisplay.workflowName = response.Content.WorkflowName;

                nextNode = DetermineNextNode((ScriptWorkflow)response.Content, currentNode, direction);

                if (nextNode != null)
                {
                    if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null && nextNode.nodeType.Equals(NodeType.Section))
                    {
                        SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                    }

                    if (nextNode.nodeActions != "") //&& fireactions
                    {
                        FireActions(nextNode.nodeActions);
                    }

                    switch (nextNode.nodeType)
                    {
                    case NodeType.Section:
                        AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                        break;

                    case NodeType.Workflow:
                        return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));

                    case NodeType.PreviousWorkflow:
                        return(RedirectToAction("DisplayByDirection", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName), currentNode = nextNode.DocUID, moveDirection = MoveDirection.Current }));

                    case NodeType.SignPost:
                        MoveDirection direction2 = direction == MoveDirection.Start ? MoveDirection.Forward : direction;
                        WFNodeInfo    holdNode   = nextNode;
                        nextNode = DetermineNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID, direction2);
                        if (nextNode == null)
                        {
                            direction = MoveDirection.Current;
                            return(Display(Convert.ToInt32(Request.Form["hdnWorkflowId"])));
                            //nextNode = holdNode;
                        }
                        else
                        {
                            if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                            {
                                SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                                AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                            }

                            if (nextNode.nodeType.Equals(NodeType.Workflow))
                            {
                                return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));
                            }
                        }
                        FireActions(nextNode.nodeActions);
                        if (nextNode.nodeType.Equals(NodeType.SignPost))
                        {
                            nextNode = DetermineNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID, direction2);

                            if (nextNode == null)
                            {
                                direction = MoveDirection.Current;
                                return(Display(Convert.ToInt32(Request.Form["hdnWorkflowId"])));
                                //nextNode = holdNode;
                            }
                            else
                            {
                                if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                                {
                                    SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                                    AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                                }

                                if (nextNode.nodeType.Equals(NodeType.Workflow))
                                {
                                    return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));
                                }
                            }
                            FireActions(nextNode.nodeActions);
                        }
                        break;
                    }

                    if (IsNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID))
                    {
                        wfDisplay.showNext = true;
                    }
                    else
                    {
                        wfDisplay.showNext = false;
                    }
                }
                else
                {
                    direction = MoveDirection.Current;
                    return(Display(Convert.ToInt32(Request.Form["hdnWorkflowId"])));
                }
            }

            if (AddHistory)
            {
                if (SessionManager.GetWorkflowHistory(HttpContext.Session).Length >= 2)
                {
                    wfDisplay.showPrevious = true;
                }
                else
                {
                    wfDisplay.showPrevious = false;
                }
            }
            Session["layout"]    = null;
            wfDisplay.nextNode   = nextNode;
            wfDisplay.workflowID = id.ToString();
            nextNode.DocUID      = id;
            SessionManager.StoreNextNode(HttpContext.Session, nextNode);
            wfDisplay.callNotes = SessionManager.GetContactNotes(HttpContext.Session);

            string layoutname = "_default";

            if (!string.IsNullOrEmpty(SessionManager.GetScreenLayout(HttpContext.Session)))
            {
                layoutname = SessionManager.GetScreenLayout(HttpContext.Session);
            }

            WorkflowLayoutsController WLC = new WorkflowLayoutsController();

            //var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, ScreenViewer.ClientHelper.GetClientIdByUserID(System.Web.HttpContext.Current.User.Identity.GetUserId()));
            var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, SessionManager.GetScriptParameterByKey("ClientId", HttpContext.Session));

            if (actionResult2 != null)
            {
                var response = actionResult2 as OkNegotiatedContentResult <string>;
                wfDisplay.Layout = response.Content;
            }
            ScriptProject scriptproject = null;

            API.ProjectController PC = new API.ProjectController();
            var actionResult3        = PC.GetScriptProject(SessionManager.GetProjectId(HttpContext.Session));

            if (actionResult3 != null)
            {
                var response = actionResult3 as OkNegotiatedContentResult <ScriptProject>;
                scriptproject = response.Content;
            }

            string notif = scriptproject.NotificationText;

            wfDisplay.menuHTML = SessionManager.GetMenuHTML(HttpContext.Session);

            wfDisplay.Notifications = scriptproject.NotificationText; //notif.Replace(System.Environment.NewLine,"");

            return(View("_WorkFlowViewLayout1", wfDisplay));
        }
        public ActionResult Display(int id, int currentNode, MoveDirection moveDirection)
        {
            WFNodeInfo      nextNode  = null;
            WorkflowDisplay wfDisplay = new WorkflowDisplay();

            ScreenViewer.API.WorkflowController WFC = new API.WorkflowController();
            var actionResult = WFC.GetScriptWorkflow(id);

            if (actionResult != null)
            {
                var response = actionResult as OkNegotiatedContentResult <ScriptWorkflow>;
                wfDisplay.workflowName = response.Content.WorkflowName;

                nextNode = DetermineNextNode((ScriptWorkflow)response.Content, currentNode, moveDirection);

                if (nextNode != null)
                {
                    if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                    {
                        SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                    }

                    if (nextNode.nodeActions != "" && FireAway)
                    {
                        FireActions(nextNode.nodeActions);
                    }

                    switch (nextNode.nodeType)
                    {
                    case NodeType.Section:
                        AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                        break;

                    case NodeType.Workflow:
                        return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));

                    case NodeType.PreviousWorkflow:
                        return(RedirectToAction("DisplayByDirection", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName), moveDirection = MoveDirection.Current }));

                    case NodeType.SignPost:

                        nextNode = DetermineNextNode((ScriptWorkflow)response.Content, currentNode, direction);

                        if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                        {
                            SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                        }

                        if (nextNode.nodeActions != "" & FireAway)
                        {
                            FireActions(nextNode.nodeActions);
                        }
                        break;
                    }

                    if (IsNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID))
                    {
                        wfDisplay.showNext = true;
                    }
                    else
                    {
                        wfDisplay.showNext = false;
                    }
                }
            }

            if (AddHistory)
            {
                if (SessionManager.GetWorkflowHistory(HttpContext.Session).Length >= 2)
                {
                    wfDisplay.showPrevious = true;
                }
                else
                {
                    wfDisplay.showPrevious = false;
                }
            }

            wfDisplay.nextNode   = nextNode;
            wfDisplay.workflowID = id.ToString();

            string layoutname = "_default";

            if (!string.IsNullOrEmpty(SessionManager.GetScreenLayout(HttpContext.Session)))
            {
                layoutname = SessionManager.GetScreenLayout(HttpContext.Session);
            }

            WorkflowLayoutsController WLC = new WorkflowLayoutsController();

            //var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, ScreenViewer.ClientHelper.GetClientIdByUserID(System.Web.HttpContext.Current.User.Identity.GetUserId()));
            var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, SessionManager.GetScriptParameterByKey("ClientId", HttpContext.Session));

            if (actionResult2 != null)
            {
                var response = actionResult2 as OkNegotiatedContentResult <string>;
                wfDisplay.Layout = response.Content;
            }
            wfDisplay.menuHTML = SessionManager.GetMenuHTML(HttpContext.Session);

            return(View("_WorkFlowViewLayout1", wfDisplay));
        }