예제 #1
0
        public int Run(User user, Knowledgesections knowledgesections)
        {
            int id;

            Console.WriteLine("Select knowledge section. Enter Id:");
            knowledgesections.Show();
            int.TryParse(Console.ReadLine(), out id);
            Console.ReadKey();
            var quiz    = questions.Where(q => q.KnowledgesectionId == id).ToList();
            int counter = 0;
            int point   = 0;

            foreach (var item in quiz)
            {
                if (counter < 20)
                {
                    if (item.Run())
                    {
                        point++;
                    }
                    ;
                    counter++;
                }
            }
            return(point);
        }
예제 #2
0
        public void Add(Knowledgesections knowledgesections)
        {
            Console.Clear();
            int id;

            knowledgesections.Show();
            Console.WriteLine("Select knowledgesection id:");
            int.TryParse(Console.ReadLine(), out id);
            Console.WriteLine("Enter question:");
            string        qwestion = Console.ReadLine();
            List <Answer> answers  = new List <Answer>();
            bool          isTrue;
            bool          next = true;

            while (next)
            {
                Console.WriteLine("Enter answer:");
                string answer = Console.ReadLine();
                Console.WriteLine("This answer is true?(y/n)");
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.Y:
                    isTrue = true;
                    break;

                case ConsoleKey.N:
                    isTrue = false;
                    break;

                default:
                    isTrue = false;
                    break;
                }
                answers.Add(new Answer {
                    Text = answer, IsTrue = isTrue
                });
                Console.WriteLine("Next answer?(y/n)");
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.Y:
                    next = true;
                    break;

                case ConsoleKey.N:
                    next = false;
                    break;

                default:
                    next = false;
                    break;
                }
            }
            Question quiz = new Question
            {
                KnowledgesectionId = id,
                Text    = qwestion,
                answers = answers
            };

            questions.Add(quiz);
        }