Ejemplo n.º 1
0
 public List <Student> GetAllStudents()
 {
     using (var context = new OnlineExamSystem())
     {
         return(context.Students.ToList());
     }
 }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 3
0
        public Student GetStudentById(int id)
        {
            using (var context = new OnlineExamSystem())
            {
                var student = context.Students.SingleOrDefault(x => x.StudentId == id);

                return(student);
            }
        }
Ejemplo n.º 4
0
        public void InsertAnswerIntoDatabase(Question question)
        {
            using (var context = new OnlineExamSystem())
            {
                context.Questions.Add(question);

                context.SaveChanges();
            }
        }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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();*/
     }
 }