Esempio n. 1
0
        public void DoTest()
        {
            var testStudent = new TestStudent();

            Assert.AreEqual(testStudent, testStudent.Do(x => x.Name = "Test"));
            Assert.IsTrue(testStudent.Name.Equals("Test"));
        }
Esempio n. 2
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // Ignore clicks that are not on button cells.
            if (e.RowIndex < 0 || e.ColumnIndex !=
                dataGridView1.Columns[buttonColumnName].Index)
            {
                return;
            }

            int  idTest = Int32.Parse(dataGridView1["id", e.RowIndex].Value.ToString());
            var  z      = tests.Find(o => o.id == idTest);
            Test test   = new Test()
            {
                id = (int)z.id, Name = z.Name, PassMark = (short)z.PassMark
            };


            if (user.Role == UserRole.Student)
            {
                TestStudent testStudent = new TestStudent(test, user);
                testStudent.Show();
                return;
            }
            if (user.Role == UserRole.Teacher || user.Role == UserRole.Admin)
            {
                TeacherStatisticks statisticks = new TeacherStatisticks(test, user);
                statisticks.Show();
                return;
            }
        }
Esempio n. 3
0
        public bool Post(TestStudent testStudent)
        {
            //manuelt filtrer og søg kurser fra database og vælg de rigtige id'er
            var courses = new List <TestCourse>();

            foreach (var testCourse in testStudent.TestCourses)
            {
                var dbCourse = db.TestCourses.FirstOrDefault(x => x.TestCourseName == testCourse.TestCourseName);
                courses.Add(dbCourse);
            }
            //opbyg student data container med kursus data fra database og student data fra postmetode
            var newStudent = new TestStudent
            {
                TestStudentName = testStudent.TestStudentName,
                TestCourses     = courses
            };

            //add student
            db.TestStudents.Add(newStudent);
            //gem ændringer
            int NumberOfTestStudentsSaved = db.SaveChanges();

            if (0 < NumberOfTestStudentsSaved)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        public bool Put(int id, TestStudent testStudent)
        {
            var modifiedStudent = db.TestStudents.Find(id);

            if (null != modifiedStudent)
            {
                //manuelt filtrer og søg kurser fra database og vælg de rigtige id'er
                var courses = new List <TestCourse>();
                foreach (var testCourse in testStudent.TestCourses)
                {
                    var dbCourse = db.TestCourses.FirstOrDefault(x => x.TestCourseName == testCourse.TestCourseName);
                    courses.Add(dbCourse);
                }

                modifiedStudent.TestStudentName = testStudent.TestStudentName;
                modifiedStudent.TestCourses.Clear();
                modifiedStudent.TestCourses = courses;

                //gem ændringer
                int NumberOfTestStudentsSaved = db.SaveChanges();

                if (0 < NumberOfTestStudentsSaved)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
        public static TestStudent CreateTest(Test test)
        {
            TestStudent testUser = new TestStudent()
            {
                Test      = test,
                DateStart = DateTime.Now
            };

            List <QuestionAnswer> questions = new List <QuestionAnswer>();

            foreach (TestThema thema in test.Themes)
            {
                for (var i = 0; i < 3; i++)// thema.Thema.Question
                {
                    var question = thema.Thema.Questions[new Random().Next(thema.Thema.Questions.Count)];
                    thema.Thema.Questions.Remove(question);
                    questions.Add(new QuestionAnswer()
                    {
                        Question             = question,
                        TestStudent          = testUser,
                        Name                 = question.Name,
                        Description          = question.Description,
                        QuestionRightAnswers = question.Answers,
                        Appraisal            = question.Appraisal
                    });
                }
            }
            testUser.QuestionAnswers = questions;

            return(testUser);
        }
Esempio n. 6
0
        public void Init()
        {
            Console.WriteLine("启动AttributesMapping.Init");
            using (var db = DBManager.GetInstance())
            {
                //查询
                var list = db.Queryable <TestStudent>()
                           .Where(it => it.className.Contains("小")).OrderBy(it => it.classSchoolId).Select <V_Student>(it => new V_Student()
                {
                    id = it.classId, name = it.className
                }).ToList();
                var list2 = db.Queryable <TestStudent>()
                            .JoinTable <TestSchool>((s1, s2) => s1.classSchoolId == s2.classId)
                            .OrderBy <TestSchool>((s1, s2) => s1.classId)
                            .Select <TestStudent, TestSchool, V_Student>((s1, s2) => new V_Student()
                {
                    id = s1.classId, name = s1.className, SchoolName = s2.className
                }).ToList();

                //添加
                TestStudent s = new TestStudent();
                s.className     = "属性名";
                s.classSchoolId = 1;
                s.classId       = new Random().Next(2000, 111111111);
                var id = db.Insert(s);
                s.classId = id.ObjToInt();

                s.classId = new Random().Next(2000, 111111111);;
                db.SqlBulkCopy(new List <TestStudent>()
                {
                    s
                });


                //更新
                db.Update(s);
                db.Update <TestStudent, int>(s, 100);
                db.Update <TestStudent>(s, it => it.classId == 100);
                db.SqlBulkReplace(new List <TestStudent>()
                {
                    s
                });

                //删除
                db.Delete <TestStudent>(it => it.classId == 100);

                //根据实体赋值实体一定要有主键,并且要有值。
                db.Delete(new TestStudent()
                {
                    classId = 200
                });
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> SetTestTimerAsync(TestViewModel model, string[] students)
        {
            try
            {
                if (students.Length == 0)
                {
                    this.ModelState.AddModelError(string.Empty, "Добавете поне един ученик.");

                    return(this.View(model));
                }

                // Get test from DB
                var test = await this.testService.GetTestAsync(model.TestId);

                // Set current Teacher Id to test
                test.TeacherId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

                // Set test timer from input model
                test.Timer = model.Timer;

                // Adding TestStudent in list before adding them to DB
                var testStudentForDB = new List <TestStudent>();

                // Adding "TestStudent" relation
                foreach (var student in students)
                {
                    var testStudent = new TestStudent()
                    {
                        StudentId = this.userService
                                    .GetStudents()
                                    .FirstOrDefault(s => s.Name == student).Id,

                        TestId = test.TestId,
                    };

                    testStudentForDB.Add(testStudent);
                }

                // Adding students in TestRoom
                string testRoomId = await this.testService.AddTestRoomAsync(students, test.TeacherId, model.TestId);

                // Add entity testStudent to DB
                await this.testService.AddTestStudentsAsync(testStudentForDB);

                return(this.RedirectToAction("StartTest", "Test", new { Id = test.TestId }));
            }
            catch (Exception exception)
            {
                this.TempData["ErrorMsg"] = exception.Message;

                return(this.Redirect("/Home/Error"));
            }
        }
Esempio n. 8
0
        public void Init()
        {
            Console.WriteLine("启动AttributesMapping.Init");
            using (var db = DBManager.GetInstance())
            {

                //查询
                var list = db.Queryable<TestStudent>()
                    .Where(it => it.className.Contains("小")).OrderBy(it => it.classSchoolId).Select<V_Student>(it => new V_Student() { id = it.classId, name = it.className }).ToList();
                var list2 = db.Queryable<TestStudent>()
                    .JoinTable<TestSchool>((s1, s2) => s1.classSchoolId == s2.classId)
                    .OrderBy<TestSchool>((s1, s2) => s1.classId)
                    .Select<TestStudent, TestSchool, V_Student>((s1, s2) => new V_Student() { id = s1.classId, name = s1.className, SchoolName = s2.className }).ToList();

                //添加
                TestStudent s = new TestStudent();
                s.className = "属性名";
                s.classSchoolId = 1;
                var id = db.Insert(s);
                s.classId = id.ObjToInt();

                db.SqlBulkCopy(new List<TestStudent>() { s });

                //更新
                db.Update(s);
                db.Update<TestStudent, int>(s, 100);
                db.Update<TestStudent>(s, it => it.classId == 100);
                db.SqlBulkReplace(new List<TestStudent>() { s });

                //删除
                db.Delete<TestStudent>(it => it.classId == 100);

                //根据实体赋值实体一定要有主键,并且要有值。
                db.Delete(new TestStudent() {  classId = 200 });
            }
        }
        public ResponseModel CreateStudentDetails(StudentDetails aObj)
        {
            //_aRepository.Insert(aObj);
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (aObj.StudentId == 0)
                    {
                        //var status = _aRepository.SelectAll().Where(a => a.StudentCode == aObj.StudentCode);
                        //if (status.Any())
                        //{
                        //    return _aModel.Respons(false, "Student Code Already Exist.");
                        //}

                        DateTime aDate = DateTime.Now;

                        TestStudent aStudent = new TestStudent()
                        {
                            StudentName  = aObj.StudentName,
                            StudentPhone = aObj.StudentPhone
                        };


                        //aObj.CreatedDate = aDate;
                        _db.TestStudents.Add(aStudent);
                        _db.SaveChanges();

                        TestStudentAddress aStudentAddress = new TestStudentAddress()
                        {
                            Address   = aObj.Address,
                            Country   = aObj.Country,
                            StudentId = aStudent.StudentId
                        };
                        // List<TestStudentAddress> aStudentAddress;
                        //foreach (var testStudentAddress in aStudentAddress)
                        //{
                        //    _db.TestStudentAddresses.Add(testStudentAddress);
                        //}
                        //_db.SaveChanges();
                        _db.TestStudentAddresses.Add(aStudentAddress);
                        // throw new Exception("good");

                        TestStudentHistory aStudentHistory = new TestStudentHistory()
                        {
                            HistoryDetials = aObj.HistoryDetials,
                            HistoryTitle   = aObj.HistoryTitle,
                            StudentId      = aStudent.StudentId
                        };
                        _db.TestStudentHistories.Add(aStudentHistory);
                        _db.SaveChanges();


                        transaction.Commit();
                        return(_aModel.Respons(true, "New Student Successfully Saved"));
                    }
                    else
                    {
                        DateTime aDate = DateTime.Now;
                        //aObj.CreatedDate = aDate;
                        //_aRepository.Update(aObj);
                        //_aRepository.Save();
                        return(_aModel.Respons(true, "New Student Successfully Updated"));
                    }
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(_aModel.Respons(false, "Sorry! Some Error Error Happned"));
                }
            }
        }
Esempio n. 10
0
        public void db()
        {
            super = new SuperUser()
            {
                Id               = "SuperUser",
                Password         = "******",
                Username         = "******",
                Firstname        = "SuperUser",
                Email            = "Email",
                Secondname       = "SuperUser",
                DateRegistration = DateTime.Now
            };

            students = new List <StudentUser>()
            {
                new StudentUser()
                {
                    Id               = "qw",
                    Username         = "******",
                    Firstname        = "FirstnameStudent",
                    Secondname       = "Seocndname",
                    Email            = "Email",
                    Password         = "******",
                    Group            = "Group",
                    DateRegistration = DateTime.Now
                },
                new StudentUser()
                {
                    //Id = "qw2",
                    Username         = "******",
                    Firstname        = "Firstname2Student",
                    Secondname       = "Seocndname2",
                    Password         = "******",
                    Email            = "Email",
                    Group            = "Group",
                    DateRegistration = DateTime.Now
                }
            };

            teacher = new TeacherUser()
            {
                Id               = "teacher2",
                Password         = "******",
                Firstname        = "Teacher2",
                Secondname       = "TeacherSencName2",
                Username         = "******",
                Email            = "Email",
                Department       = "Пара2",
                Discipline       = "Discipline",
                DateRegistration = DateTime.Now
            };
            List <string> answers = new List <string>()
            {
                "Ответ 1", "Ответ 2", "Ответ 3", "Ответ 4", "Ответ 5"
            };

            questions1 = new List <Question>()
            {
                new Question()
                {
                    Id           = "quest1",
                    Name         = "Question 1",
                    TypeAnswer   = AnswerType.Many,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 1"
                    }
                },
                new Question()
                {
                    Id           = "quest2",
                    Name         = "Question 2",
                    TypeAnswer   = AnswerType.Many,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 1", "Ответ 2",
                    }
                },
                new Question()
                {
                    Id           = "quest3",
                    Name         = "Question 1",
                    TypeAnswer   = AnswerType.One,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 3"
                    }
                }
            };
            questions2 = new List <Question>()
            {
                new Question()
                {
                    Id           = "quest21",
                    Name         = "Question 1",
                    TypeAnswer   = AnswerType.Many,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 1"
                    }
                },
                new Question()
                {
                    Id           = "quest22",
                    Name         = "Question 2",
                    TypeAnswer   = AnswerType.Many,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 1", "Ответ 2",
                    }
                },
                new Question()
                {
                    Id           = "quest23",
                    Name         = "Question 1",
                    TypeAnswer   = AnswerType.One,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 3"
                    }
                }
            };
            questions3 = new List <Question>()
            {
                new Question()
                {
                    Id           = "quest31",
                    Name         = "Question 1",
                    TypeAnswer   = AnswerType.Many,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 1"
                    }
                },
                new Question()
                {
                    Id           = "quest32",
                    Name         = "Question 2",
                    TypeAnswer   = AnswerType.Many,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 1", "Ответ 2",
                    }
                },
                new Question()
                {
                    Id           = "quest33",
                    Name         = "Question 1",
                    TypeAnswer   = AnswerType.One,
                    Appraisal    = 5,
                    Description  = "Текст ВОПРОСА 1",
                    Answers      = answers,
                    CountAnswers = 5,
                    RightAnswers = new List <string>()
                    {
                        "Ответ 3"
                    }
                }
            };

            themes = new List <Thema>()
            {
                new Thema()
                {
                    Id            = "thema-1",
                    Name          = "Thema 1",
                    Questions     = questions1,
                    TeacherUserId = "teacher2",
                },
                new Thema()
                {
                    Id            = "thema-2",
                    Name          = "Thema 2",
                    Questions     = questions2,
                    TeacherUserId = "teacher2",
                },
                new Thema()
                {
                    Id            = "thema-3",
                    Name          = "Thema 3",
                    Questions     = questions3,
                    TeacherUserId = "teacher2",
                }
            };

            for (int i = 0; i < questions1.Count; i++)
            {
                questions1[i].Thema = themes[0];
            }
            for (int i = 0; i < questions2.Count; i++)
            {
                questions2[i].Thema = themes[1];
            }
            for (int i = 0; i < questions3.Count; i++)
            {
                questions3[i].Thema = themes[2];
            }

            Marks1 = new List <Mark>()
            {
                new Mark()
                {
                    Id           = "mark-1",
                    Name         = "Оценка",
                    Successfully = 40,
                },
                new Mark()
                {
                    Id           = "mark-2",
                    Name         = "Оценка2",
                    Successfully = 60,
                },
                new Mark()
                {
                    Id           = "mark-3",
                    Name         = "Оценка3",
                    Successfully = 80,
                }
            };
            Marks2 = new List <Mark>()
            {
                new Mark()
                {
                    Id           = "mark-4",
                    Name         = "Оценка",
                    Successfully = 40,
                },
                new Mark()
                {
                    Id           = "mark-5",
                    Name         = "Оценка2",
                    Successfully = 60,
                }
            };
            TestThemas = new List <TestThema>();
            tests      = new List <Test>()
            {
                new Test()
                {
                    Id              = "test-1",
                    Name            = "test Nma",
                    Description     = "DEscription",
                    DateCreate      = DateTime.Now,
                    DateLastChanges = DateTime.Now,
                    TimeAll         = 2000000,
                    Passwords       = new List <string>()
                    {
                        "pas1"
                    },
                    Themes = new List <TestThema>()
                    {
                        new TestThema()
                        {
                            TestId     = "test-1",
                            Id         = "TestThem1",
                            Thema      = themes[0],
                            ThemaId    = themes[0].Id,
                            CountQuest = 2,
                            CountBalls = 2
                        },
                        new TestThema()
                        {
                            Id         = "TestThem2",
                            TestId     = "test-1",
                            Thema      = themes[1],
                            ThemaId    = themes[1].Id,
                            CountQuest = 2,
                            CountBalls = 2
                        }
                    },
                    TeacherUser = teacher,

                    TestType = TestType.Relative,
                    Marks    = Marks1
                },
                new Test()
                {
                    Id              = "test-2",
                    Name            = "test Nma2",
                    Description     = "DEscription2",
                    DateCreate      = DateTime.Now,
                    DateLastChanges = DateTime.Now,
                    TimeAll         = 400000,
                    Passwords       = new List <string>()
                    {
                        "pas2"
                    },
                    Themes = new List <TestThema>()
                    {
                        new TestThema()
                        {
                            Id         = "TestThem3",
                            TestId     = "test-2",
                            Thema      = themes[2],
                            ThemaId    = themes[2].Id,
                            CountQuest = 2,
                            CountBalls = 2
                        }
                    },
                    TeacherUser = teacher,
                    TestType    = TestType.Usual,
                    Marks       = Marks2
                }
            };
            tests[0].Themes[0].Test = tests[0];
            tests[0].Themes[1].Test = tests[0];
            tests[1].Themes[0].Test = tests[1];
            TestThemas.AddRange(tests[0].Themes);
            TestThemas.AddRange(tests[1].Themes);

            for (int i = 0; i < Marks1.Count; i++)
            {
                Marks1[i].Test = tests[0];
            }
            for (int i = 0; i < Marks2.Count; i++)
            {
                Marks2[i].Test = tests[1];
            }

            //Ответы студента
            studentUser     = students[0];
            questionAnswers = new List <QuestionAnswer>()
            {
                new QuestionAnswer()
                {
                    Id      = "questanswer 1",
                    Answers = new List <string>()
                    {
                        "Ответ 1", "Ответ 2"
                    },
                    DateAnswer           = DateTime.Now,
                    Time                 = 2000,
                    Appraisal            = 20.0,
                    Question             = questions1[0],
                    Name                 = questions1[0].Name,
                    Description          = questions1[0].Description,
                    QuestionAnswers      = questions1[0].Answers,
                    QuestionRightAnswers = questions1[0].RightAnswers
                },
                new QuestionAnswer()
                {
                    Id      = "questanswer 2",
                    Answers = new List <string>()
                    {
                        "Ответ 1"
                    },
                    DateAnswer           = DateTime.Now,
                    Time                 = 2000,
                    Appraisal            = 1.0,
                    Question             = questions1[1],
                    Name                 = questions1[1].Name,
                    Description          = questions1[1].Description,
                    QuestionAnswers      = questions1[1].Answers,
                    QuestionRightAnswers = questions1[1].RightAnswers
                },
                new QuestionAnswer()
                {
                    Id      = "questanswer 3",
                    Answers = new List <string>()
                    {
                        "Ответ 2"
                    },
                    DateAnswer           = DateTime.Now,
                    Time                 = 2000,
                    Appraisal            = 5.0,
                    Question             = questions2[0],
                    Name                 = questions2[0].Name,
                    Description          = questions2[0].Description,
                    QuestionAnswers      = questions2[0].Answers,
                    QuestionRightAnswers = questions2[0].RightAnswers
                }
            };

            testStudent = new TestStudent()
            {
                Id              = "test-student-1",
                DateStart       = DateTime.Now,
                DateFinish      = DateTime.Now,
                Mistakes        = 20,
                QuestionAnswers = questionAnswers,
                StudentUser     = studentUser,
                Correctly       = 15,
                Test            = tests[0],
                Time            = 20000
            };
            testStudents = new List <TestStudent>();
            testStudents.Add(testStudent);

            for (int i = 0; i < questionAnswers.Count; i++)
            {
                questionAnswers[i].TestStudent = testStudent;
            }
        }
Esempio n. 11
0
        public static TestStudent ResultTest(TestStudent testStudent)
        {
            int correctlyAll       = 0;
            int mistakeAll         = 0;
            int correctlyQuestions = 0;

            double balls    = 0;
            double ballsAll = 0;

            for (int i = 0; i < testStudent.QuestionAnswers.Count; i++)
            {
                int correctly = 0;
                int mistake   = 0;
                ballsAll += testStudent.QuestionAnswers[i].Appraisal;

                for (int a = 0; a < testStudent.QuestionAnswers[i].QuestionRightAnswers.Count; a++)
                {
                    if (testStudent.QuestionAnswers[i].Answers.SequenceEqual(testStudent.QuestionAnswers[i].QuestionRightAnswers))
                    {
                        correctly++;
                    }
                    else
                    {
                        mistake++;
                    }
                }

                if (mistake == 0)
                {
                    testStudent.QuestionAnswers[i].Status = true;
                    correctlyQuestions++;
                    balls        += testStudent.QuestionAnswers[i].Appraisal;
                    correctlyAll += correctly;
                }
                else
                {
                    testStudent.QuestionAnswers[i].Status = false;
                    mistakeAll++;
                }
                Console.WriteLine($"mistake {mistake}");
                Console.WriteLine($"Appraisal {balls}, {testStudent.QuestionAnswers[i].Appraisal}");
                // mistakeAll += mistake;
            }
            testStudent.Appraisal          = balls;
            testStudent.Correctly          = correctlyAll;
            testStudent.Mistakes           = mistakeAll;
            testStudent.CorrectlyQuestions = correctlyQuestions;

            // Double appraisal = 0;
            //if (testStudent.Test.TestType == TestType.Relative)
            //{
            //    if (correctlyAll != 0)
            //    {
            //        appraisal = (correctlyAll - mistakeAll) * 100 / correctlyAll;
            //    }
            //}
            //else if (testStudent.Test.TestType == TestType.Usual)
            //{
            //    if (ballsAll == 0)
            //    {
            //        appraisal = 0;
            //    }
            //    else
            //    {
            //        appraisal = balls * 100 / ballsAll;
            //    }
            //}
            // testStudent.Appraisal = appraisal;

            //Mark markNow = null;
            //var marks = testStudent.Test.Marks.OrderBy(a => a.Successfully);
            //foreach (Mark mark in marks)
            //{
            //    if (testStudent.Appraisal >= mark.Successfully)
            //    {
            //        markNow = mark;
            //    }
            //}
            //testStudent.Mark = markNow;

            return(testStudent);
        }
        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));
        }
Esempio n. 13
0
 public static void postSet_Testbogen(TestStudent obj)
 {
 }