public ConductTrialBlockViewModel(TrialBlock tb)
        {
            Fails = new List<ProfileViewModel>();
            Passes = new List<ProfileViewModel>();

            foreach (var fail in tb.FailProfiles)
            {
                Fails.Add(new ProfileViewModel(fail));
            }
            foreach (var pass in tb.PassProfiles)
            {
                Passes.Add(new ProfileViewModel(pass));
            }
            Id = tb.Id;
            IndexInSession = tb.IndexInSession;
        }
        public TrialBlockViewModel(TrialBlock coreModel, IQueryable<Profile> profileOptions)
        {
            ProfilesIDsToFail = new List<int>();
            ProfilesIDsToPass = new List<int>();
            ProfileOptions = new List<DropdownOption>();
            foreach (var opt in profileOptions)
            {
                ProfileOptions.Add(new DropdownOption(opt));
            }

            IndexInSession = coreModel.IndexInSession;
            foreach (var profile in coreModel.FailProfiles)
            {
                ProfilesIDsToFail.Add(profile.Id);
            }
            foreach (var profile in coreModel.PassProfiles)
            {
                ProfilesIDsToPass.Add(profile.Id);
            }
            ID = coreModel.Id;
        }
        //[HttpPost]
        //[AllowAnonymous]
        //public ActionResult ImportWords()
        //{
        //    var entities = new db38bab79d27554b96b50aa57c010cd149Entities3();
        //    string pathToExcelFile = ""
        //+ @"D:\Words.xls";
        //    string[] SheetNames = new string[] { "Session 1, 7", "Session 2, 8", "Session 3, 9", "Session 4, 10", "Session 5, 11", "Session 6, 12" };
        //    string[] stringSeparators = new string[] { ", " };
        //    var excelFile = new ExcelQueryFactory(pathToExcelFile);
        //    for (int i = 0; i < SheetNames.Length; i++ )
        //    {
        //        var sheetName = SheetNames[i];
        //        var rows = from a in excelFile.Worksheet(sheetName) select a;
        //        foreach (var r in rows)
        //        {
        //            var word = new Word();
        //            word.Arabic = r["Arabic"];
        //            word.English = r["English"];
        //            word.ListId = i;
        //            entities.Words.Add(word);
        //            entities.SaveChanges();
        //        }
        //    }
        //    AjaxResponse response = new AjaxResponse();
        //    response.Success = true;
        //    response.Message = "It worked.";
        //    return Json(response);
        //}
        public ActionResult UpdateSession(SessionViewModel form)
        {
            AjaxResponse response = new AjaxResponse();
            response.Success = false;
            response.Message = "Nothing happened.";

            var entities = new db38bab79d27554b96b50aa57c010cd149Entities3();

            Session newSession;
            if (form.SessionID == null || form.SessionID == string.Empty)
            {
                newSession = new Session();
                entities.Sessions.Add(newSession);
            }
            else
            {
                int parsedID = Int32.Parse(form.SessionID);
                newSession = entities.Sessions.Where(x => x.Id == parsedID).FirstOrDefault();
            }

            newSession.Name = form.Name;

            var part = entities.Participants.Where(x => x.Id == form.ParticipantID).FirstOrDefault();
            var feedback = entities.FeedbackConditions.Where(x => x.Id == form.FeedbackModeID).FirstOrDefault();

            newSession.FeedbackCondition = feedback;
            newSession.Participant = part;
            newSession.WordListId = form.WordListId;
            entities.SaveChanges();

            foreach(var block in form.TrialBlocks)
            {
                TrialBlock newTB;

                if (block.ID == null)
                {
                    newTB = new TrialBlock();
                }
                else
                {
                    newTB = entities.TrialBlocks.Where(x => x.Id == block.ID).FirstOrDefault();
                    newTB.FailProfiles.Clear();
                    newTB.PassProfiles.Clear();
                }

                newTB.IndexInSession = block.IndexInSession;

                foreach (var id in block.ProfilesIDsToFail)
                {
                    var profile = entities.Profiles.Where(x => x.Id == id).FirstOrDefault();
                    newTB.FailProfiles.Add(profile);
                }

                foreach (var id in block.ProfilesIDsToPass)
                {
                    var profile = entities.Profiles.Where(x => x.Id == id).FirstOrDefault();
                    newTB.PassProfiles.Add(profile);
                }
                if (block.ID == null)
                {
                    newSession.TrialBlocks.Add(newTB);
                }
            }
            entities.SaveChanges();

            response.Success = true;
            response.Message = "Changes saved to database";

            return Json(response);
        }