Пример #1
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);
        }
Пример #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
        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);
        }
Пример #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;
        }