public QuestionOption GetQuestionOption(int questionOptionID)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.QuestionOptions.FirstOrDefault(qo => qo.QuestionOptionID == questionOptionID);
     }
 }
Esempio n. 2
0
 public User GetUser(int userID)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.Users.FirstOrDefault(u => u.UserID == userID);
     }
 }
 public QuizAttempt GetQuizAttempt(int quizAttemptID)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.QuizAttempts.FirstOrDefault(qa => qa.QuizAttemptID == quizAttemptID);
     }
 }
Esempio n. 4
0
 public Quiz GetQuiz(int quizID)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.Quizzes.FirstOrDefault(q => q.QuizID == quizID);
     }
 }
Esempio n. 5
0
 public User GetUser(string username, string password)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.Users.FirstOrDefault(u => u.UserName == username && u.Password == password);
     }
 }
Esempio n. 6
0
 public void SaveQuiz(Quiz quiz)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         ctx.AddToQuizzes(quiz);
         ctx.SaveChanges();
     }
 }
Esempio n. 7
0
 public void SaveUser(User user)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         ctx.AddToUsers(user);
         ctx.SaveChanges();
     }
 }
 public void SaveQuizAttempt(QuizAttempt quizAttempt)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         ctx.AddToQuizAttempts(quizAttempt);
         ctx.SaveChanges();
     }
 }
 public void SaveQuestionOption(QuestionOption questionOption)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         ctx.AddToQuestionOptions(questionOption);
         ctx.SaveChanges();
     }
 }
Esempio n. 10
0
 public List<Quiz> GetQuizzes()
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.Quizzes
              .OrderBy(q => q.QuizName)
              .ToList();
     }
 }
 public List<QuizAttempt> GetQuizAttempts(int userID)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.QuizAttempts
          .Where(qa => qa.UserID == userID)
          .OrderBy(qa => qa.QuizDate)
          .ToList();
     }
 }
 public List<QuestionOption> GetQuestionOptions(int questionID)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.QuestionOptions
            .Where(qo => qo.QuestionID == questionID)
            .OrderBy(qo => qo.OptionSequence)
            .ToList();
     }
 }
Esempio n. 13
0
 public List<User> GetUsers()
 {
     using (var ctx = new QuizBuilderEntities())
     {
         return ctx.Users
            .OrderBy(u => u.LastName)
            .OrderBy(u => u.FirstName)
            .ToList();
     }
 }
Esempio n. 14
0
        //added 4/10/2013
        public Question GetLast(int scenarioID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var question = ctx.Questions
                    .Where(s => s.ScenarioID == scenarioID)
                    .OrderByDescending(s => s.QuestionSequence)
                    .FirstOrDefault();

                return question;
            }
        }
Esempio n. 15
0
        //added 4/10/2013
        public Scenario GetLast(int quizID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var scenario = ctx.Scenarios
                    .Where(s => s.QuizID == quizID)
                    .OrderByDescending(s => s.ScenarioSequence)
                    .FirstOrDefault();

                return scenario;
            }
        }
        public QuestionResponse GetLastQuestionResponse(int quizAttemptID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                return ctx.QuestionResponses
                  .Where(qr => qr.QuizAttemptID == quizAttemptID)
                  .OrderByDescending(qr => qr.Question.Scenario.ScenarioSequence)
                  .ThenByDescending(qr => qr.Question.QuestionSequence)
                  .FirstOrDefault();

            }
        }
        //added 4/10/2013
        public QuestionOption GetLast(int questionID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var questionOption = ctx.QuestionOptions
                    .Where(q => q.QuestionID == questionID)
                    .OrderByDescending(o => o.OptionSequence)
                    .FirstOrDefault();

                return questionOption;
            }
        }
Esempio n. 18
0
        public void DeleteQuiz(int quizID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var quiz = ctx.Quizzes.FirstOrDefault(q => q.QuizID == quizID);

                if (quiz != null)
                {
                    ctx.DeleteObject(quiz);
                    ctx.SaveChanges();
                }
            }
        }
        public void DeleteQuestionResponse(int questionResponseID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var questionResponse = ctx.QuestionResponses.FirstOrDefault(qr => qr.QuestionResponseID == questionResponseID);

                if (questionResponse != null)
                {
                    ctx.DeleteObject(questionResponse);
                    ctx.SaveChanges();
                }
            }
        }
        public void DeleteQuizAttempt(int quizAttemptID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var quizAttempt = ctx.QuizAttempts.FirstOrDefault(qa => qa.QuizAttemptID == quizAttemptID);

                if (quizAttempt != null)
                {
                    ctx.DeleteObject(quizAttempt);
                    ctx.SaveChanges();
                }
            }
        }
Esempio n. 21
0
        public void DeleteScenario(int scenarioID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var scenario = ctx.Scenarios.FirstOrDefault(s => s.ScenarioID == scenarioID);

                if (scenario != null)
                {
                    ctx.DeleteObject(scenario);
                    ctx.SaveChanges();
                }
            }
        }
Esempio n. 22
0
        public void DeleteUser(int userID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var user = ctx.Users.FirstOrDefault(u => u.UserID == userID);

                if (user != null)
                {
                    ctx.DeleteObject(user);
                    ctx.SaveChanges();
                }
            }
        }
Esempio n. 23
0
        public void DeleteQuestion(int questionID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                var question = ctx.Questions.FirstOrDefault(q => q.QuestionID == questionID);

                if (question != null)
                {
                    ctx.DeleteObject(question);
                    ctx.SaveChanges();
                }
            }
        }
 public void UpdateQuizAttempt(QuizAttempt quizAttempt)
 {
     using (var ctx = new QuizBuilderEntities())
     {
         ctx.Attach(quizAttempt);
         var stateEntry = ctx.ObjectStateManager.GetObjectStateEntry(quizAttempt);
         foreach (var propertyName in stateEntry.CurrentValues
                              .DataRecordInfo.FieldMetadata
                              .Select(fm => fm.FieldType.Name))
         {
             stateEntry.SetModifiedProperty(propertyName);
         }
         ctx.SaveChanges();
     }
 }
Esempio n. 25
0
    protected void btnAddQuestion_Click(object sender, EventArgs e)
    {
        using (QuizBuilderEntities QBContext = new QuizBuilderEntities())
                {
                    Question question = new Question();
                    question.ScenarioID = Convert.ToInt32(txtNewQScenarioID.Text);
                    question.QuestionSequence = Convert.ToInt32(txtNewQSequenceNumb.Text);
                    question.QuestionText = txtNewQTxt.Text;

                    QuestionRepository qR = new QuestionRepository();
                    qR.SaveQuestion(question);

            /*Reload page so gridview will display new scenario */
            Response.Redirect("Admin_Quiz.aspx");
        }

            clearQuestionInputControls();
    }
Esempio n. 26
0
    protected void submitNewUserInfo_Click(object sender, EventArgs e)
    {
        using (QuizBuilderEntities QBContext = new QuizBuilderEntities())
        {
            User obj = new User();
            obj.FirstName = txtFirstName.Text;
            obj.LastName = txtLastName.Text;
            obj.UserName = txtUserName.Text;
            obj.Password = txtPassword.Text;
            obj.Email = txtEmail.Text;

            UserRepository uR = new UserRepository();
            uR.SaveUser(obj);

            Response.Redirect("Admin_Users.aspx");
        }

        clearInputControls();
    }
Esempio n. 27
0
    protected void btnAddScenario_Click(object sender, EventArgs e)
    {
        using (QuizBuilderEntities QBContext = new QuizBuilderEntities())
        {
            Scenario scenario = new Scenario();
            scenario.ScenarioName = txtNewScenarioTxt.Text;
            scenario.ScenarioSequence = Convert.ToInt32(txtNewScenarioSeq.Text);
            scenario.ScenarioText = txtNewScenarioTxt.Text;

            ScenarioRepository sR = new ScenarioRepository();
            sR.SaveScenario(scenario);

            /*Reload page so gridview will display new scenario */
            Response.Redirect("Admin_Quiz.aspx");
        }

            clearScenarioInputControls();
            PanelScenario.Visible = false;
    }
Esempio n. 28
0
        public Scenario GetPrevious(int scenarioID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                Scenario previousScenario = null;

                //fetch the scenario
                var currentScenario = ctx.Scenarios.FirstOrDefault(s => s.ScenarioID == scenarioID);
                if (currentScenario != null)
                {
                    //get the collection of scenarios based on the quiz
                    var quizScenarios = GetScenarios(currentScenario.QuizID);
                    //find this scenario in the collection
                    var current = quizScenarios.First(s => s.ScenarioID == scenarioID);
                    //is there a previous scenario? If not - return null
                    previousScenario = quizScenarios.ElementAtOrDefault(quizScenarios.IndexOf(current) - 1);
                }
                return previousScenario;
            }
        }
Esempio n. 29
0
        public Question GetPrevious(int questionID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                Question previousQuestion = null;

                //fetch the question
                var currentQuestion = ctx.Questions.FirstOrDefault(q => q.QuestionID == questionID);
                if (currentQuestion != null)
                {
                    //get the collection of questions based on the scenario
                    var quizQuestions = GetQuestions(currentQuestion.ScenarioID);
                    //find this question in the collection
                    var current = quizQuestions.First(q => q.QuestionID == questionID);
                    //is there a previous question? If not - return null
                    previousQuestion = quizQuestions.ElementAtOrDefault(quizQuestions.IndexOf(current) - 1);
                }
                return previousQuestion;
            }
        }
        //added 2/29/2012
        public QuestionResponse GetPrevious(int questionResponseID)
        {
            using (var ctx = new QuizBuilderEntities())
            {
                QuestionResponse previousQuestionResponse = null;

                //fetch the questionResponse
                var currentQuestionResponse = ctx.QuestionResponses.FirstOrDefault(q => q.QuestionResponseID == questionResponseID);
                if (currentQuestionResponse != null)
                {
                    //get the collection of questionResponses based on the scenario
                    var quizQuestionResponses = GetQuestionResponses(currentQuestionResponse.QuizAttemptID);
                    //find this questionResponse in the collection
                    var current = quizQuestionResponses.First(q => q.QuestionResponseID == questionResponseID);
                    //is there a previous questionResponse? If not - return null
                    previousQuestionResponse = quizQuestionResponses.ElementAtOrDefault(quizQuestionResponses.IndexOf(current) - 1);
                }
                return previousQuestionResponse;
            }
        }