예제 #1
0
        public RepositoryResult <bool> CreateQuestionAnswer(List <string> Answers)
        {
            try
            {
                var MaxAnswers = db.Answers.Count() + 1;
                for (int i = 0; i < Answers.Count; i++)
                {
                    Answer NewAnswer = new Answer();
                    NewAnswer.AnswerID       = MaxAnswers + i;
                    NewAnswer.QuestionAnswer = Answers[i];
                    db.Answers.Add(NewAnswer);

                    QuestionAnswer NewQuestionAnswer = new QuestionAnswer();
                    NewQuestionAnswer.QuestionID = db.Questions.Count();
                    NewQuestionAnswer.AnswerID   = NewAnswer.AnswerID;
                    db.QuestionAnswers.Add(NewQuestionAnswer);
                }
                db.SaveChanges();

                return(RepositoryResult <bool> .SuccessFunc());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(RepositoryResult <bool> .ErrorFunc());
            }
        }
예제 #2
0
        public RepositoryResult <bool> RemoveQuestion(int id)
        {
            try
            {
                var RemoveQuestion = db.Questions.Find(id);
                db.Questions.Remove(RemoveQuestion);

                var questionAnswers           = db.QuestionAnswers;
                var getCurrentQuestionAnswers = questionAnswers.Where(i => i.QuestionID == id);

                foreach (var answer in getCurrentQuestionAnswers)
                {
                    db.Answers.Remove(answer.Answers);
                }

                db.SaveChanges();

                return(RepositoryResult <bool> .SuccessFunc());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(RepositoryResult <bool> .ErrorFunc());
            }
        }
예제 #3
0
        public RepositoryResult <bool> EditQuestion(Question question, List <string> InputAnswers)
        {
            try
            {
                db.Entry(question).State = EntityState.Modified;
                db.SaveChanges();

                var getQuestion = db.QuestionAnswers;
                var getCurrentQuestionAnswers = getQuestion.Where(i => i.QuestionID == question.ID);


                int Counter = 0;
                foreach (var realAnswer in getCurrentQuestionAnswers)
                {
                    Answer RealAnswer = realAnswer.Answers;
                    RealAnswer.QuestionAnswer = InputAnswers[Counter];
                    Counter++;

                    db.Entry(RealAnswer).State = EntityState.Modified;
                }
                db.SaveChanges();

                return(RepositoryResult <bool> .SuccessFunc());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(RepositoryResult <bool> .ErrorFunc());
            }
        }
예제 #4
0
        public RepositoryResult <Question> GetNextQuestion(Question question, string id)
        {
            try
            {
                if (id == "Skipped")
                {
                    TempClass.NextQuestionNumber++;
                    TempClass.TotallyAnsweredQuestions++;
                }

                var Question = NextQuetion(question.ID, question.TestName, question.DifficultyLevel, question.UserName);
                if (Question != null)
                {
                    return(RepositoryResult <Question> .SuccessFunc("", Question));
                }
                else
                {
                    return(RepositoryResult <Question> .ErrorFunc());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(null);
        }
예제 #5
0
        public RepositoryResult <User> EditUser(User user)
        {
            try
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RepositoryResult <User> .SuccessFunc("", user));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(RepositoryResult <User> .ErrorFunc("", user));
            }
        }
예제 #6
0
        public RepositoryResult <bool> ClearTempClass()
        {
            try
            {
                TempClass.NextQuestionNumber       = 0;
                TempClass.TotallyAnsweredQuestions = 0;
                TempClass.GradeForAnswer           = 0;

                return(RepositoryResult <bool> .SuccessFunc());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(RepositoryResult <bool> .ErrorFunc());
            }
        }
예제 #7
0
        public RepositoryResult <User> Register(User user)
        {
            try
            {
                using (var db = new TestContext())
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                }

                return(RepositoryResult <User> .SuccessFunc("User " + user.UserName + " registered successfully", user));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(RepositoryResult <User> .ErrorFunc("User " + user.UserName + " can not be resigtered", user));
            }
        }
예제 #8
0
 public RepositoryResult <User> UserExists(int id)
 {
     try
     {
         var userExists = db.Users.FirstOrDefault(i => i.ID == id);
         if (userExists != null)
         {
             return(RepositoryResult <User> .SuccessFunc("", userExists));
         }
         else
         {
             return(RepositoryResult <User> .ErrorFunc());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
     return(null);
 }
예제 #9
0
 public RepositoryResult <bool> CreateQuestion(Question question)
 {
     try
     {
         var questionExists = db.Questions.FirstOrDefault(i => i.TestQuestion == question.TestQuestion);
         if (questionExists == null)
         {
             db.Questions.Add(question);
             db.SaveChanges();
             return(RepositoryResult <bool> .SuccessFunc());
         }
         else
         {
             return(RepositoryResult <bool> .ErrorFunc());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
     return(null);
 }
예제 #10
0
 public RepositoryResult <ForLogIn> UserExistsForLogIn(ForLogIn user)
 {
     try
     {
         using (var db = new TestContext())
         {
             var userExists = db.Users.FirstOrDefault(i => i.UserName == user.UserName && i.UserPassword == user.UserPassword);
             if (userExists != null)
             {
                 return(RepositoryResult <ForLogIn> .SuccessFunc("User " + user.UserName + " exists", user));
             }
             else
             {
                 return(RepositoryResult <ForLogIn> .ErrorFunc("User " + user.UserName + " doesn't exist", user));
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
     return(null);
 }
예제 #11
0
        public RepositoryResult <bool> CheckAnswer(Question question)
        {
            if (question.CorrectAnswer == question.SelectedAnswer)
            {
                TempClass.NextQuestionNumber++;
                TempClass.TotallyAnsweredQuestions++;
                TempClass.GradeForAnswer += question.Grade;

                var user = db.Users.FirstOrDefault(i => i.UserName == question.UserName);
                user.Points         += question.Grade;
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                Thread.Sleep(2000);
                return(RepositoryResult <bool> .SuccessFunc());
            }
            else
            {
                TempClass.NextQuestionNumber = question.ID;
                Thread.Sleep(2000);
                return(RepositoryResult <bool> .ErrorFunc());
            }
        }