コード例 #1
0
        public async Task <ActionResult <List <Question> > > GetTest([FromBody] string id = "test-1")
        {
            // Check password and return questionnaire
            if (id == null)
            {
                return(StatusCode(400));
            }
            Test test = _context.Tests.FirstOrDefault(a => a.Id.Equals(id));

            if (test == null)
            {
                return(StatusCode(400));
            }

            test.Themes = _context.TestThemes.Where(a => a.TestId.Equals(test.Id)).ToList();
            for (var i = 0; i < test.Themes.Count; i++)
            {
                test.Themes[i].Thema           = _context.Themes.FirstOrDefault(a => a.Id.Equals(test.Themes[i].ThemaId));
                test.Themes[i].Thema.Questions = _context.Questions
                                                 .Where(a => a.ThemaId.Equals(test.Themes[i].Thema.Id)).ToList();
            }

            var questions = CreateQuestionsStudent.TestToQuestions(test);

            Response.Cookies.Append("test", test.Id);
            Response.Cookies.Append("dateStart", DateTime.Now.Ticks.ToString());

            Response.Headers.Add("test", test.Id);
            Response.Headers.Add("dateStart", DateTime.Now.Ticks.ToString());

            return(Ok(questions));
        }
コード例 #2
0
        public ActionResult <List <Question> > Password([FromForm] string password)
        {
            // Check password and return questionnaire

            Test test = null;

            try
            {
                test = _context.Tests.AsEnumerable().FirstOrDefault(a => a.Passwords.Contains(password));
            }
            catch (Exception e)
            {
                return(StatusCode(404));
            }

            test.Themes = _context.TestThemes.Where(a => a.TestId.Equals(test.Id)).ToList();
            for (var i = 0; i < test.Themes.Count; i++)
            {
                test.Themes[i].Thema           = _context.Themes.FirstOrDefault(a => a.Id.Equals(test.Themes[i].ThemaId));
                test.Themes[i].Thema.Questions = _context.Questions
                                                 .Where(a => a.ThemaId.Equals(test.Themes[i].Thema.Id)).ToList();
            }

            if (test == null)
            {
                return(StatusCode(400));
            }

            var questions = CreateQuestionsStudent.TestToQuestions(test);

            Response.Cookies.Append("test", test.Id);
            Response.Cookies.Append("dateStart", DateTime.Now.Ticks.ToString());

            return(Ok(questions));
        }
コード例 #3
0
        public ActionResult <List <Question> > UserMy([FromBody] string fullname,
                                                      [FromBody] string group, [FromBody] string departament)
        {
            Test test = null;
            //var testId = Request.Cookies["test"];

            //if (testId != null)
            //{
            //    test = _context.GetTest(testId);
            //}
            //else
            //{
            //    return StatusCode(400);
            //}
            //if (test == null)
            //{
            //    return StatusCode(400);
            //}

            // Added user in users
            //if(){// Если пользователь не авторизован!

            //}else{


            //}

            //Response.Cookies.Append("fullname", fullname);
            //Response.Cookies.Append("group", group);
            //Response.Cookies.Append("departament", departament);

            var questions = CreateQuestionsStudent.TestToQuestions(test);

            return(Ok(questions));
        }
コード例 #4
0
        public ActionResult <TestStudent> Result([FromBody] ICollection <Question> array)// List<Question> array
        {
            // Check answered and return database
            // Дописать null
            Console.WriteLine("result = " + (array == null));
            if (array == null)
            {
                return(null);
            }

            string idTest    = Request.Cookies["test"];
            var    startDate = Request.Cookies["dateStart"];

            if (idTest == null)
            {
                idTest = Request.Headers["test"];
            }
            if (startDate == null)
            {
                startDate = Request.Headers["dateStart"];
            }

            Console.WriteLine($"test id = {idTest}");
            Test test = _context.Tests.FirstOrDefault(a => a.Id.Equals(idTest));

            TestStudent testStudent = new TestStudent();

            testStudent.Id = Guid.NewGuid().ToString();
            //testStudent.IpAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            testStudent.Test   = test;
            testStudent.TestId = idTest;

            List <QuestionAnswer> questionAnswers = new List <QuestionAnswer>();
            QuestionAnswer        answer;

            long allTime = 0;

            foreach (var quest in array)
            {
                answer             = new QuestionAnswer();
                answer.Id          = Guid.NewGuid().ToString();
                answer.TestStudent = testStudent;

                answer.QuestionId = quest.Id;// (string) array[i]["id"].ToString();
                answer.Question   = _context.Questions.FirstOrDefault(a => a.Id.Equals(quest.Id));

                answer.Answers = quest.RightAnswers;// Users answers
                answer.Time    = quest.Time;
                allTime       += answer.Time;

                answer.Name        = answer.Question.Name;
                answer.Description = answer.Question.Description;

                answer.QuestionAnswers      = answer.Question.Answers;
                answer.QuestionRightAnswers = answer.Question.RightAnswers;
                answer.Appraisal            = answer.Question.Appraisal;

                questionAnswers.Add(answer);
            }
            testStudent.Time            = allTime;
            testStudent.QuestionAnswers = questionAnswers;
            testStudent            = CreateQuestionsStudent.ResultTest(testStudent);
            testStudent.DateFinish = DateTime.Now;
            testStudent.DateStart  = new DateTime(long.Parse(startDate));

            return(Ok(testStudent));
        }