/// <summary>
        /// Deletes test type by given string
        /// </summary>
        /// <param name="type"> Given string </param>
        public void DeleteTestTypeByType(string type)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testType = context.TestTypes.FirstOrDefault(r => r.Type == type);

                context.TestTypes.Remove(testType);
                context.SaveChanges();
            }
        }
Example #2
0
        //delete data
        /// <summary>
        /// Deletes an answer after a given Id.
        /// </summary>
        /// <param name="id"> Given Id </param>
        public void DeleteAnswer(int id)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var answer = context.Answers.FirstOrDefault(r => r.Id == id);

                context.Answers.Remove(answer);
                context.SaveChanges();
            }
        }
Example #3
0
        /// <summary>
        /// Delete user test by user id and test id
        /// </summary>
        /// <param name="userId"> Given user id </param>
        /// <param name="testId"> Given test id </param>
        public void DeleteUserTestByUserAndTestId(int userId, int testId)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var userTest = context.UserTests.FirstOrDefault(r => r.UserID == userId && r.TestId == testId);

                context.UserTests.Remove(userTest);
                context.SaveChanges();
            }
        }
Example #4
0
        /// <summary>
        /// Set if user is admin by a given username
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="status"></param>
        public void SetAdminByUsername(string Username, bool status)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var user = context.Users.FirstOrDefault(r => r.Username == Username);
                user.IsAdmin = status;

                context.SaveChanges();
            }
        }
Example #5
0
        /// <summary>
        /// Deletes test questions by a given user id and test id.
        /// </summary>
        /// <param name="userId"> Given userId </param>
        /// <param name="testId"> Given testId </param>
        public void DeleteTestQuestionsAnswersByUserAndTestId(int userId, int testId)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testQuestionsAnswers = context.TestQuestionsAnswers.Where(r => r.UserID == userId && r.TestId == testId).ToList();

                context.TestQuestionsAnswers.RemoveRange(testQuestionsAnswers);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Updates TestType by existing type
        /// </summary>
        /// <param name="oldType"> Old type </param>
        /// <param name="newType"> New Type </param>
        public void UpdateTestTypeByType(string oldType, string newType)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testType = context.TestTypes.FirstOrDefault(r => r.Type == oldType);

                testType.Type = newType;
                context.SaveChanges();
            }
        }
Example #7
0
        /// <summary>
        /// Sets isFinished state by id
        /// </summary>
        /// <param name="id"> Given Id  </param>
        /// <param name="isFinished"> Given state </param>
        public void SetStateById(int id, bool isFinished)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var userTest = context.UserTests.FirstOrDefault(r => r.Id == id);

                userTest.IsFinished = isFinished;
                context.SaveChanges();
            }
        }
Example #8
0
        //delete data
        /// <summary>
        ///  Deletes a user by a given Id.
        /// </summary>
        /// <param name="id"> Given user id </param>
        public void DeleteUserById(int id)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var user = context.Users.FirstOrDefault(r => r.Id == id);

                context.Users.Remove(user);
                context.SaveChanges();
            }
        }
        //delete data
        /// <summary>
        ///  Deletes test by id
        /// </summary>
        /// <param name="id"> Given id </param>
        public void DeleteTestById(int id)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var test = context.Tests.FirstOrDefault(r => r.Id == id);

                context.Tests.Remove(test);
                context.SaveChanges();
            }
        }
Example #10
0
        /// <summary>
        ///  Set if user is admin by a given id
        /// </summary>
        /// <param name="Id"> Given Id </param>
        /// <param name="status">Given status</param>
        public void SetAdminById(int Id, bool status)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var user = context.Users.FirstOrDefault(r => r.Id == Id);
                user.IsAdmin = status;

                context.SaveChanges();
            }
        }
Example #11
0
        /// <summary>
        ///  Deletes Technology Question by a given id
        /// </summary>
        /// <param name="id"> Question technology id </param>
        public void DeleteTechnologyQuestionById(int id)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var technologyQuestion = context.TechnologyQuestions.FirstOrDefault(r => r.Id == id);

                context.TechnologyQuestions.Remove(technologyQuestion);
                context.SaveChanges();
            }
        }
Example #12
0
        //delete data
        /// <summary>
        /// Deletes a test question by a given id.
        /// </summary>
        /// <param name="id"> Given id. </param>
        public void DeleteTestQuestionsAnswersById(int id)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testQuestionAnswer = context.TestQuestionsAnswers.FirstOrDefault(r => r.Id == id);

                context.TestQuestionsAnswers.Remove(testQuestionAnswer);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Updates TestType by id
        /// </summary>
        /// <param name="id"> Given id </param>
        /// <param name="type"> Given type </param>
        public void UpdateTestTypeById(int id, string type)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testType = context.TestTypes.FirstOrDefault(r => r.Id == id);

                testType.Type = type;
                context.SaveChanges();
            }
        }
Example #14
0
        /// <summary>
        /// Updates Technology Question by a given id
        /// </summary>
        /// <param name="id"> Question technology id </param>
        public void UpdateTechnologyQuestionById(int id, string givenTechnology)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var technologyQuestion = context.TechnologyQuestions.FirstOrDefault(r => r.Id == id);
                technologyQuestion.TechnologyQuestionText = givenTechnology;

                context.SaveChanges();
            }
        }
Example #15
0
        /// <summary>
        /// Deletes Technology Question by Name
        /// </summary>
        /// <param name="givenTechnology"> Given Technology question name </param>
        public void DeleteTechnologyQuestionByName(string givenTechnology)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var technologyQuestion = context.TechnologyQuestions.FirstOrDefault(r => r.TechnologyQuestionText == givenTechnology);

                context.TechnologyQuestions.Remove(technologyQuestion);
                context.SaveChanges();
            }
        }
Example #16
0
        /// <summary>
        /// Deletes a user by a given username.
        /// </summary>
        /// <param name="username"> Given Username </param>
        public void DeleteUserByUsername(string username)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var user = context.Users.FirstOrDefault(r => r.Username == username);

                context.Users.Remove(user);
                context.SaveChanges();
            }
        }
Example #17
0
        /// <summary>
        /// Sets isFinished state by user id and test id
        /// </summary>
        /// <param name="userId"> Given user id </param>
        /// <param name="testId"> Given test id </param>
        /// <param name="isFinished"> Given isFinished status </param>
        public void SetStateByUserAndTestId(int userId, int testId, bool isFinished)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var userTest = context.UserTests.FirstOrDefault(r => r.UserID == userId && r.TestId == testId);

                userTest.IsFinished = isFinished;
                context.SaveChanges();
            }
        }
Example #18
0
        /// <summary>
        /// Sets test id by id
        /// </summary>
        /// <param name="id"> Given id </param>
        /// <param name="testId"> Given test id</param>
        public void SetTestIdById(int id, int testId)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var userTest = context.UserTests.FirstOrDefault(r => r.Id == id);

                userTest.TestId = testId;
                context.SaveChanges();
            }
        }
Example #19
0
        //update data
        /// <summary>
        ///  Updates an answer after a given Id.
        /// </summary>
        /// <param name="id"> Given Id </param>
        /// <param name="textAnswer"> Given text of the answer </param>
        /// <param name="QuestionID"> Given question Id </param>
        /// <param name="Value"> Given value of the answer </param>
        public void UpdateAnswer(int id, string textAnswer, int QuestionID, bool value)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var answer = context.Answers.FirstOrDefault(r => r.Id == id);
                answer.Text_Answer = textAnswer;
                answer.QuestionID  = QuestionID;
                answer.Value       = value;

                context.SaveChanges();
            }
        }
Example #20
0
        /// <summary>
        ///  Updates questions with answers given by the user by deleting and then adding the test questions with answers.
        /// </summary>
        /// <param name="QuestionID"> Given QuestionID</param>
        /// <param name="testId"> Given TestID </param>
        /// <param name="answersId"> Given AnswerID </param>
        public void UpdateQuestionAnswersDal(int QuestionID, int testId, List <int> answersId, int userId, bool isReviewQuestion)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var _testQuestionsAnswerList = context.TestQuestionsAnswers.Where(r => r.QuestionID == QuestionID && r.TestId == testId && r.UserID == userId).ToList();

                context.TestQuestionsAnswers.RemoveRange(_testQuestionsAnswerList);
                context.SaveChanges();
            }

            AddQuestionsAnswersDal(QuestionID, testId, answersId, userId, isReviewQuestion);
        }
        //update data
        /// <summary>
        ///  Updates a testQuestion by a given Id.
        /// </summary>
        /// <param name="id"> Given Id. </param>
        /// <param name="testId"> Given TestId. </param>
        /// <param name="QuestionID"> Given QuestionID. </param>
        public void UpdateTestQuestion(int id, int testId, int QuestionID)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testQuestion = context.TestQuestions.FirstOrDefault(r => r.Id == id);

                testQuestion.TestId     = testId;
                testQuestion.QuestionID = QuestionID;

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Adds a test type to database
        /// </summary>
        /// <param name="type"> Given Type </param>
        public void AddTestType(string type)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testType = new TestType
                {
                    Type = type
                };

                context.TestTypes.Add(testType);
                context.SaveChanges();
            }
        }
Example #23
0
        //update data

        /// <summary>
        /// Updates user test
        /// </summary>
        /// <param name="id"> Given Id  </param>
        /// <param name="userId"> Given User Id  </param>
        /// <param name="testId"> Given Test Id </param>
        /// <param name="isFinished"> Given status </param>
        public void UpdateUserTest(int id, int userId, int testId, bool isFinished)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var userTest = context.UserTests.FirstOrDefault(r => r.Id == id);

                userTest.UserID     = userId;
                userTest.TestId     = testId;
                userTest.IsFinished = isFinished;

                context.SaveChanges();
            }
        }
Example #24
0
        /// <summary>
        ///  Adds a question technology
        /// </summary>
        /// <param name="givenTechnology"> Given technology </param>
        public void AddTechnologyQuestion(string givenTechnology)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var technologyQuestion = new TechnologyQuestion
                {
                    TechnologyQuestionText = givenTechnology
                };

                context.TechnologyQuestions.Add(technologyQuestion);
                context.SaveChanges();
            }
        }
Example #25
0
        public void UpdateQuestionAnswersDal(int QuestionID, int testId, int answerId, int userId, bool isReviewQuestion)
        {
            using (QuizEntities context = new QuizEntities())
            {
                TestQuestionsAnswer _testQuestionsAnswer = context.TestQuestionsAnswers.FirstOrDefault(r => r.QuestionID == QuestionID);

                _testQuestionsAnswer.AnswerId         = answerId;
                _testQuestionsAnswer.UserID           = userId;
                _testQuestionsAnswer.IsReviewQuestion = isReviewQuestion;

                context.SaveChanges();
            }
        }
Example #26
0
 //add data
 /// <summary>
 ///  Add answer to database
 /// </summary>
 /// <param name="textAnswer"> Given Answer text </param>
 /// <param name="QuestionID"> Given Question Id </param>
 /// <param name="value"> Given question value </param>
 public void AddAnswer(string textAnswer, int QuestionID, bool value)
 {
     using (QuizEntities context = new QuizEntities())
     {
         var answer = new Answer
         {
             Text_Answer = textAnswer,
             QuestionID  = QuestionID,
             Value       = value
         };
         context.Answers.Add(answer);
         context.SaveChanges();
     }
 }
        //add data
        /// <summary>
        ///  Adds a TestQuestion to database
        /// </summary>
        /// <param name="id"></param>
        /// <param name="testId"></param>
        /// <param name="QuestionID"></param>
        public void AddTestQuestion(int testId, int QuestionID)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var testQuestion = new TestQuestion
                {
                    TestId     = testId,
                    QuestionID = QuestionID
                };

                context.TestQuestions.Add(testQuestion);
                context.SaveChanges();
            }
        }
Example #28
0
        /// <summary>
        /// Updates a user by a given id.
        /// </summary>
        /// <param name="id"> Given Id </param>
        /// <param name="username"> Given Username </param>
        /// <param name="email"> Given email </param>
        /// <param name="isActive"> Given Active status </param>
        /// <param name="isAdmin"> Given Admin status </param>
        public void UpdateUser(int id, string username, string email, bool isActive, bool isAdmin)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var user = context.Users.FirstOrDefault(r => r.Id == id);

                user.Username    = username;
                user.Email       = email;
                user.ActivStatus = isActive;
                user.IsAdmin     = isAdmin;

                context.SaveChanges();
            }
        }
Example #29
0
        //update data

        /// <summary>
        ///  Updates test by given id
        /// </summary>
        /// <param name="id"> Given id </param>
        /// <param name="testTypeId"> Given test type id </param>
        /// <param name="name"> Given name </param>
        /// <param name="levelTest"> Given level test</param>
        /// <param name="numberOfQuestions"> Given number of questions </param>
        public void UpdateTest(int id, int testTypeId, string name, string levelTest, int numberOfQuestions)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var test = context.Tests.FirstOrDefault(r => r.Id == id);

                test.TestTypeId        = testTypeId;
                test.Name              = name;
                test.LevelTest         = levelTest;
                test.NumberOfQuestions = numberOfQuestions;

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Updates question by a given Id
        /// </summary>
        /// <param name="id"> Given question id </param>
        /// <param name="textQuestion"> Given Question Text </param>
        /// <param name="typeQuestion"> Given Question Type </param>
        /// <param name="levelQuestion"> Given Question Level </param>
        /// <param name="questionTechnologyId"> Given Question Technology Id </param>
        public void UpdateQuestion(int id, string textQuestion, string typeQuestion, string levelQuestion, int questionTechnologyId)
        {
            using (QuizEntities context = new QuizEntities())
            {
                var question = context.Questions.FirstOrDefault(r => r.Id == id);

                question.Text_Question        = textQuestion;
                question.TypeQuestion         = typeQuestion;
                question.LevelQuestion        = levelQuestion;
                question.QuestionTechnologyID = questionTechnologyId;

                context.SaveChanges();
            }
        }