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 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();
            }
        }