コード例 #1
0
        public List <Test> GetAllTestForUserWithMarks(string login)
        {
            List <Test> test = new List <Test>();

            try
            {
                List <Mark>     marksList    = new List <Mark>();
                List <Question> questionList = new List <Question>();

                List <Answer>      answerList = new List <Answer>();
                List <MarkAnswers> markAnsw   = new List <MarkAnswers>();

                AnswerRepository _answerRepository = new AnswerRepository(_connectionString);
                answerList = _answerRepository.GetAllUsersAnswers();

                MarkAnswerRepository _markAnswerRepository = new MarkAnswerRepository(_connectionString);
                markAnsw = _markAnswerRepository.GetMarksForCurrentUser(login);
                foreach (MarkAnswers item in markAnsw)
                {
                    item.Answer = answerList.Where(f => f.Id == item.AnswerId).First();
                }

                MarkRepository _markRepository = new MarkRepository(_connectionString);
                marksList = _markRepository.GetAllMarks();
                foreach (Mark item in marksList)
                {
                    item.MarkAnswer = new List <MarkAnswers>(markAnsw.Where(f => f.MarkId == item.Id));
                }

                QuestionRepository _questionRepository = new QuestionRepository(_connectionString);
                questionList = _questionRepository.GetAllUsersQuestion();
                foreach (Question item in questionList)
                {
                    item.Answers = new List <Answer>(answerList.Where(f => f.QuestionId == item.Id));
                    foreach (Answer itemA in answerList.Where(m => m.QuestionId == item.Id))
                    {
                        itemA.Question = item;
                    }
                }


                var user = base.ExecuteReader(spGetAllTests, TestParser.GetTest);
                test.AddRange(user);
                foreach (Test tempTest in test)
                {
                    tempTest.Marks     = new List <Mark>();
                    tempTest.Questions = new List <Question>();
                    foreach (Mark item in marksList.Where(m => m.TestId == tempTest.Id))
                    {
                        tempTest.Marks.Add(item);
                        tempTest.Marks.Last <Mark>().Test = tempTest;
                    }
                    foreach (Question item in questionList.Where(m => m.TestId == tempTest.Id))
                    {
                        tempTest.Questions.Add(item);
                        tempTest.Questions.Last <Question>().Test = tempTest;
                    }
                }
                return(test);
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception cathed in GetAllTestForUserWithMarks: " + e.Message);
                return(null);
            }
        }
コード例 #2
0
        public List <UserMarks> GetAllUsersScores()
        {
            try
            {
                List <UserMarks>   userList;
                List <Mark>        marksList;
                List <Answer>      listAnsw;
                List <Test>        listTest;
                List <Question>    listQuestion;
                List <MarkAnswers> markAnsw;

                UserMarkRepository _userMarkRepository = new UserMarkRepository(_connectionString);
                userList = _userMarkRepository.GetAllLogins();

                AnswerRepository _answerRepository = new AnswerRepository(_connectionString);
                listAnsw = _answerRepository.GetAllUsersAnswers();

                QuestionRepository _questionRepository = new QuestionRepository(_connectionString);
                listQuestion = _questionRepository.GetAllUsersQuestion();
                foreach (Question item in listQuestion)
                {
                    item.Answers = new List <Answer>(listAnsw.Where(f => f.QuestionId == item.Id));
                }

                MarkAnswerRepository _markAnswerRepository = new MarkAnswerRepository(_connectionString);
                markAnsw = _markAnswerRepository.GetAllUsersMarkAnswers();
                foreach (MarkAnswers item in markAnsw)
                {
                    item.Answer = listAnsw.Where(f => f.Id == item.AnswerId).First();
                }

                TestRepository _testRepository = new TestRepository(_connectionString);
                listTest = new List <Test>();
                listTest = _testRepository.GetAllTests();

                marksList = new List <Mark>();

                var user = base.ExecuteReader(spGetAllUsersMarks, MarkParser.GetMarkWithUserLogin);
                marksList.AddRange(user);

                foreach (Mark item in marksList)
                {
                    item.MarkAnswer = new List <MarkAnswers>(markAnsw.Where(f => f.MarkId == item.Id));
                    item.Test       = listTest.Where(f => f.Id == item.TestId).FirstOrDefault();
                }

                foreach (UserMarks item in userList)
                {
                    item.Marks = new List <Mark>();
                    item.Marks.AddRange(marksList.Where(m => m.User.Login == item.Login));
                }
                foreach (Answer item in listAnsw)
                {
                    item.Question = listQuestion.Where(m => m.Id == item.QuestionId).FirstOrDefault();
                }
                foreach (Question item in listQuestion)
                {
                    item.Test = listTest.Where(m => m.Id == item.TestId).FirstOrDefault();
                }
                foreach (Test item in listTest)
                {
                    item.Marks = new List <Mark>();
                    item.Marks.AddRange(marksList.Where(m => m.TestId == item.Id));
                    item.Questions = new List <Question>();
                    item.Questions.AddRange(listQuestion.Where(m => m.TestId == item.Id));
                }
                return(userList);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception cathed in GetAllUsersScores: " + ex.Message);
                return(null);
            }
        }