//public ActionResult Equivalences(string wordselection)
        public ActionResult Equivalences()
        {
            // keep
            QuestionModel model         = new QuestionModel();
            List <string> smethods      = new List <string>();
            string        wordselection = "";

            model.Results         = new List <StudyItem>();
            model.SelectedStudies = new List <string>();

            if (wordselection == null)
            {
                model.WordSelection = "";
                wordselection       = "";
            }
            if (wordselection.Length != 0)
            {
                model.WordList = EquivalenceHelper.GetList(wordselection);
            }
            if (wordselection.Length == 0)
            {
                model.WordList = new List <Word>();
            }
            model.WordSelection = wordselection;

            //Serialize to JSON string.
            List <TreeViewNode> nodes = new List <TreeViewNode>();

            model              = RepositoryHelper.BuildStudiesTree(model, nodes);
            ViewBag.Json       = (new JavaScriptSerializer()).Serialize(nodes);
            model.AllQuestions = new List <RepositoryItemMetadata>();
            model.AllVariables = new List <RepositoryItemMetadata>();
            model.AllConcepts  = new List <RepositoryItemMetadata>();
            return(View(model));
        }
        //public ActionResult Equivalences(QuestionModel model, string Study, string selectedItems, string wordselection, string command, HttpPostedFileBase postedFile)
        public ActionResult Equivalences(QuestionModel model, string Study, string selectedItems, string fileName, string command, HttpPostedFileBase postedFile)
        {
            string wordselection                = "";
            List <TreeViewNode> nodes           = new List <TreeViewNode>();
            List <TreeViewNode> selectedstudies = new List <TreeViewNode>();

            if (selectedItems != null)
            {
                selectedstudies = (new JavaScriptSerializer()).Deserialize <List <TreeViewNode> >(selectedItems);
            }
            if (postedFile != null)
            {
                model        = GetEquivalences(model, postedFile);
                model        = RepositoryHelper.BuildStudiesTree(model, nodes);
                ViewBag.Json = (new JavaScriptSerializer()).Serialize(nodes);
                return(View(model));
            }
            model.Results         = new List <StudyItem>();
            model                 = RepositoryHelper.BuildStudiesTree(model, nodes);
            model.SelectedStudies = new List <string>();
            ViewBag.Json          = (new JavaScriptSerializer()).Serialize(nodes);
            ViewBag.selectedItems = selectedItems;


            switch (command)
            {
            case "Save":
                QuestionModel newmodel = new QuestionModel();
                newmodel = SaveItem(newmodel, model.Word, model.WordSelection);
                var wordlist      = newmodel.WordList;
                var selectedwords = newmodel.WordSelection;
                newmodel.Results         = new List <StudyItem>();
                newmodel                 = RepositoryHelper.BuildStudiesTree(model, nodes);
                newmodel.SelectedStudies = new List <string>();
                newmodel.Word            = null;
                newmodel.WordList        = wordlist;
                newmodel.WordSelection   = selectedwords;
                return(RedirectToAction("Equivalences", new { selectedItems = selectedItems, wordselection = newmodel.WordSelection }));

            case "Display Questions":
                model.AllQuestions = new List <RepositoryItemMetadata>();
                model.AllVariables = new List <RepositoryItemMetadata>();
                model.AllConcepts  = new List <RepositoryItemMetadata>();
                // model.SelectedStudies = selectedstudies;
                model = LoadSelectedStudies(model, selectedstudies);
                model = ProcessStudies(model);
                var           Start = DateTime.Now;
                QuestionModel m2    = new QuestionModel();
                m2          = PopulateQuestionMessages(model, nodes, "Question");
                m2.FileName = fileName;
                m2.Type     = "Question";
                var Finish         = DateTime.Now;
                var ElapsedMinutes = (Finish - Start).Minutes;
                var ElapsedSeconds = (Finish - Start).Seconds;
                TempData["myModel"] = m2;
                return(View("Display", m2));

            case "Display Variables":
                model.AllQuestions = new List <RepositoryItemMetadata>();
                model.AllVariables = new List <RepositoryItemMetadata>();
                model.AllConcepts  = new List <RepositoryItemMetadata>();
                // model.SelectedStudies = selectedstudies;
                model = LoadSelectedStudies(model, selectedstudies);
                model = ProcessStudies(model);
                QuestionModel m3 = new QuestionModel();
                m3                  = PopulateQuestionMessages(model, nodes, "Variable");
                m3.FileName         = fileName;
                m3.Type             = "Variable";
                TempData["myModel"] = m3;
                return(View("Display", m3));

            default:
                break;
            }

            DateTime dateTime1 = DateTime.Now;
            ResetMatchesModelStepOne stepOneModel = new ResetMatchesModelStepOne();

            model.Results = new List <StudyItem>();

            model = RepositoryHelper.GetStudies(model, null);
            model.SelectedStudies = new List <string>();
            if (wordselection == null)
            {
                model.WordList = new List <Word>();
            }
            else
            {
                if (wordselection.Length != 0)
                {
                    model.WordList = EquivalenceHelper.GetList(wordselection);
                }
                if (wordselection.Length == 0)
                {
                    model.WordList = new List <Word>();
                }
            }
            if (selectedItems == "")
            {
                return(View(model));
            }
            //if (selectedItems != "")
            //{
            //    switch (nodes)
            //    {
            //        case 0:
            //            return View(model);
            //        case 1:
            //            return View(model);
            //    }
            //}
            model = RepositoryHelper.GetStudies(model, null);
            model = LoadSelectedStudies(model, nodes);


            DateTime dateTime2 = DateTime.Now;
            var      diff      = dateTime2.Subtract(dateTime1);
            var      res       = String.Format("{0}:{1}:{2}", diff.Hours, diff.Minutes, diff.Seconds);

            stepOneModel.Duration = res.ToString();
            return(View(model));
        }