Example #1
0
        private static void AddCategory()
        {
            var category = new Category();

            Console.WriteLine("Podaj nazwę kategorii");
            string categoryName = Console.ReadLine();

            category.CategoryName = categoryName;

            using (var context = new ExamContext())
            {
                var myCategory = context.Categories.FirstOrDefault(a => a.CategoryName == categoryName);

                if (myCategory == null)
                {
                    myCategory = new Category();
                    myCategory.CategoryName = categoryName;
                    context.Categories.Add(myCategory);
                    context.SaveChanges();
                }
                else
                {
                    Console.WriteLine("Taka kategoria juz istnieje");
                }
            }
        }
Example #2
0
        private static Category CheckCategory(ExamContext context)
        {
            Category category          = null;
            bool     isCategoryCorrect = false;

            do
            {
                Console.WriteLine("Podaj nazwę kategorii:");
                string categoryName = Console.ReadLine();

                var checkedCategory = context.Categories.FirstOrDefault(a => a.CategoryName == categoryName);

                if (checkedCategory == null)
                {
                    Console.WriteLine("Nie ma takiej kategorii. Podaj prawidłowa kategorie.");
                }
                else
                {
                    category          = checkedCategory;
                    isCategoryCorrect = true;
                }
            } while (!isCategoryCorrect);

            return(category);
        }
Example #3
0
        private static void TakeTest()
        {
            ResultsSaving.Result result = new ResultsSaving.Result();
            Console.Clear();
            int goodAnsw = 0, numberOfQuestions;

            using (var context = new ExamContext())
            {
                Category category = CheckCategory(context);

                foreach (var question in category.Questions)
                {
                    Console.WriteLine(question);

                    foreach (var answer in RandomPermutation(question.Answers))
                    {
                        Console.WriteLine(answer);
                    }

                    Console.WriteLine("Twoja odpowiedz:");
                    var    userAnswer = Console.ReadLine();
                    Answer usAnswer;

                    usAnswer = question.Answers.FirstOrDefault(a => a.SingleAnswer
                                                               .Equals(userAnswer, StringComparison.CurrentCultureIgnoreCase) &&
                                                               a.isAnswerCorrect);

                    if (usAnswer != null)
                    {
                        goodAnsw++;
                    }
                    else
                    {
                        Console.WriteLine("Błędna odpowiedź");
                    }
                }
                numberOfQuestions     = category.Questions.Count();
                result.CategoryOfExam = category.CategoryName;
            }

            result.GoodAnswers  = goodAnsw;
            result.AllQuestions = numberOfQuestions;
            Saving.ResultsList.Add(result);

            Console.WriteLine(result);
            Saving.SerializeResult();
        }
Example #4
0
        private static void AddQuestion()
        {
            using (var context = new ExamContext())
            {
                var category = CheckCategory(context);

                var question = new Question();
                Console.WriteLine("Podaj pytanie");
                question.SingleQuestion = Console.ReadLine();

                question.Cat = category;
                context.Questions.Add(question);
                context.SaveChanges();

                Console.WriteLine("Pytanie zostalo dodane");

                for (int i = 1; i <= 4; i++)
                {
                    var answer = new Answer();
                    if (i == 1)
                    {
                        Console.WriteLine("Podaj prawidłową odpowiedź");
                        string myAnswer = Console.ReadLine();
                        answer.SingleAnswer    = myAnswer;
                        answer.isAnswerCorrect = true;
                    }
                    else
                    {
                        Console.WriteLine($"Podaj {i} błędą odpowiedź");
                        string myAnswer = Console.ReadLine();
                        answer.SingleAnswer    = myAnswer;
                        answer.isAnswerCorrect = false;
                    }

                    answer.Quest = question;
                    context.Answers.Add(answer);
                }
                context.SaveChanges();
            }
        }