コード例 #1
0
        public ActionResult SaveSession(CompletedSessionAjaxViewModel completedSession)
        {
            var reply = new AjaxResponse();
            reply.Success = false;
            reply.Message = "Nothing happened";

            var entities = new Models.db38bab79d27554b96b50aa57c010cd149Entities3();

            var sessionRecord = entities.Sessions.Where(x => x.Id == completedSession.SessionId).SingleOrDefault();

            if (sessionRecord == null)
            {
                reply.Message = "Session ID not found";
                return Json(reply);
            }

            return Json(ProcessSessionRequest(completedSession));
        }
コード例 #2
0
        public ActionResult DeleteSession(int sessionID)
        {
            var reply = new AjaxResponse();
            reply.Success = false;
            reply.Message = "Nothing happened";

            var entities = new Models.db38bab79d27554b96b50aa57c010cd149Entities3();

            var sessionRecord = entities.Sessions.Where(x => x.Id == sessionID).SingleOrDefault();

            if (sessionRecord == null)
            {
                reply.Message = "Session ID not found";
                return Json(reply);
            }

            if (!sessionRecord.Completed)
            {
                reply.Message = "Session not completed";
                return Json(reply);
            }

            while(sessionRecord.TrialBlocks.Count > 0)
            {
                var tb = sessionRecord.TrialBlocks.First();
                while (tb.Trials.Count > 0)
                {
                    var t = tb.Trials.First();
                    entities.Trials.Remove(t);
                }

                tb.PassProfiles.Clear();
                tb.FailProfiles.Clear();

                entities.TrialBlocks.Remove(tb);
            }

            entities.Sessions.Remove(sessionRecord);
            entities.SaveChanges();

            return Json(reply);
        }
コード例 #3
0
        //[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);
        }
コード例 #4
0
        private AjaxResponse ProcessSessionRequest(CompletedSessionAjaxViewModel completedSession)
        {
            var entities = new Models.db38bab79d27554b96b50aa57c010cd149Entities3();
            var reply = new AjaxResponse();
            reply.Success = false;
            reply.Message = "Failed to save to database";

            Dictionary<string,Word> WordsByEnglish = new Dictionary<string,Word>();
            foreach(var w in entities.Words)
            {
                if (!WordsByEnglish.ContainsKey(w.English))
                {
                    WordsByEnglish.Add(w.English, w);
                }
            }

            var sessionToUpdate = entities.Sessions.Where(x => x.Id == completedSession.SessionId).SingleOrDefault();
            if(sessionToUpdate != null)
            {
                int tbi = 0;
                foreach(var tb in sessionToUpdate.TrialBlocks)
                {
                    int TrialCount = completedSession.TrialBlocks[tbi].Latencies.Length;
                    tb.Duration = completedSession.TrialBlocks[tbi].Duration;

                    for(int ti = 0; ti < TrialCount; ti++)
                    {
                        var newTrial = new Trial();
                        newTrial.Answer = WordsByEnglish[completedSession.TrialBlocks[tbi].TranslationsClicked[ti]];
                        newTrial.IndexInTrialBlock = ti;
                        newTrial.Latency = completedSession.TrialBlocks[tbi].Latencies[ti];
                        newTrial.Word = completedSession.TrialBlocks[tbi].WordsDisplayed[ti];

                        newTrial.Option1 = completedSession.TrialBlocks[tbi].OptionsDisplayed[ti][0];
                        newTrial.Option2 = completedSession.TrialBlocks[tbi].OptionsDisplayed[ti][1];
                        newTrial.Option3 = completedSession.TrialBlocks[tbi].OptionsDisplayed[ti][2];

                        tb.Trials.Add(newTrial);
                    }
                    tbi++;
                }
                sessionToUpdate.Completed = true;
                entities.SaveChanges();
                reply.Success = true;
                reply.Message = "Session saved";
            }
            return reply;
        }