예제 #1
0
 public List <Student> GetAllStudents()
 {
     using (var context = new OnlineExamSystem())
     {
         return(context.Students.ToList());
     }
 }
예제 #2
0
        /*public Question GetNextQuestionFromDB()
         * {
         *  using (var context = new ExamSystem())
         *  {
         *      var questions = context.Questions.Where(x => x.IsAnswered == false).OrderBy(o => o.Id);
         *
         *      return questions.FirstOrDefault();
         *  }
         * }*/

        public void CreateStudentIfNotExists(Student student)
        {
            using (var context = new OnlineExamSystem())
            {
                var std = context.Students.Where(x => x.StudentId == student.StudentId).SingleOrDefault();

                if (std == null)
                {
                    context.Students.Add(student);

                    var questions = context.Questions;

                    var answers = new List <Answer>();
                    foreach (var question in questions)
                    {
                        var answer = new Answer
                        {
                            StudentId  = student.Id,
                            QuestionId = question.Id,
                            IsAnswered = false
                        };

                        answers.Add(answer);
                    }

                    context.Answers.AddRange(answers);


                    context.SaveChanges();
                }
            }
        }
예제 #3
0
        public Student GetStudentById(int id)
        {
            using (var context = new OnlineExamSystem())
            {
                var student = context.Students.SingleOrDefault(x => x.StudentId == id);

                return(student);
            }
        }
예제 #4
0
        public void InsertAnswerIntoDatabase(Question question)
        {
            using (var context = new OnlineExamSystem())
            {
                context.Questions.Add(question);

                context.SaveChanges();
            }
        }
예제 #5
0
        public void UpdateStudent(Student student)
        {
            using (var context = new OnlineExamSystem())
            {
                var std = context.Students.Where(x => x.StudentId == student.StudentId).SingleOrDefault();

                if (std != null)
                {
                    context.Students.Remove(std);
                    context.Students.Add(student);
                    context.SaveChanges();
                }
            }
        }
예제 #6
0
 public void InsertQuestionIntoDatabase(List <Question> questions)
 {
     using (var context = new OnlineExamSystem())
     {
         /* var dbQuestions = context.Questions.ToList();
          * context.Questions.RemoveRange(dbQuestions);
          *
          * //context.SaveChanges();
          * //dbQuestions = context.Questions.ToList();
          * context.Questions.AddRange(questions);
          *
          * context.SaveChanges();*/
     }
 }