public async Task <ActionResult> CreateQuiz(IFormCollection collection, QuizClass quiz)
        {
            try
            {
                if (!ModelState.IsValid) //validatie error
                {
                    return(View());
                }
                if (await quizRepo.GetQuizByNameAsync(quiz.Name) != null)
                {
                    ModelState.AddModelError("", "This name is already in use");
                    return(View());
                }
                var created = await quizRepo.Create(quiz);

                if (created == null)
                {
                    return(Redirect("/Error/0"));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception exc)
            {
                Console.WriteLine("Create is giving an error: " + exc.Message);
                ModelState.AddModelError("", "Create actie is failed try again");
                return(View());
            }
        }
Exemple #2
0
        public async static Task SeedQuizold(IQuizRepo quizRepo, IQuestionRepo questionRepo)
        {
            string[]         quizNames = { "Animals", "trivia", "geography" };
            List <QuizClass> quizzes   = new List <QuizClass>();

            foreach (var quizName in quizNames)
            {
                var quiz = await quizRepo.GetQuizByNameAsync(quizName);

                if (quiz == null)
                {
                    QuizClass newQuiz = new QuizClass()
                    {
                        Name        = quizName,
                        Difficulty  = 2,
                        Description = "A quiz about " + quizName
                    };
                    await quizRepo.Create(newQuiz);
                }
                quizzes.Add(quiz);
            }

            Question vraag1 = new Question()
            {
                Description = "hoeveel weegt pikachu"
            };
            Option option1 = new Option()
            {
                OptionDescription = "5 kg",
                CorrectAnswer     = true
            };
            Option option2 = new Option()
            {
                OptionDescription = "8 kg",
                CorrectAnswer     = false
            };

            List <Option> opties = new List <Option>();

            opties.Add(option1);
            opties.Add(option2);
            vraag1.PossibleOptions = opties;

            var question = await questionRepo.GetQuestionByDescriptionAsync(vraag1.Description);

            if (question == null)
            {
                await questionRepo.Create(vraag1);
            }
            await quizRepo.AddQuestionToQuizAsync(quizzes[0].QuizId, vraag1.QuestionId);
        }
        public async Task <ActionResult <Quiz_DTO> > getQuizzesByName(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(BadRequest("ongeldige naam"));
            }

            var quiz = await quizRepo.GetQuizByNameAsync(name);

            if (quiz == null)
            {
                return(NotFound("geen quiz gevonden"));
            }

            var quiz_DTO       = new Quiz_DTO();
            var quiz_DTOResult = Mapper.QuizTo_DTO(quiz, ref quiz_DTO);

            return(Ok(quiz_DTOResult));
        }
        public async Task InitQuizzes()
        {
            if (await _userMgr.FindByEmailAsync("*****@*****.**") != null)
            {
                var usr = await _userMgr.FindByEmailAsync("*****@*****.**");

                if (await _quizRepo.GetQuizByNameAsync("Music") == null)
                {
                    var quiz1 = new Quiz()
                    {
                        Name        = "Music",
                        Description = "Quiz About Music Facts",
                        Diff        = 0,
                        AppUserId   = usr.Id
                    };

                    Quiz quizMade = await _quizRepo.AddQuizAsync(quiz1);

                    List <String> qstList1 = new List <string> {
                        "Who is called the king of POP ?",
                        "Who made the most popular christmass song ?",
                        "Who is called GOAT in the rap industry ?",
                        "Who made the most cringy song that made his fame rise ?",
                        "Which artist has alot of numbers on his body ?",
                        "Which dutch rapper quit his show because someone throwed a beer at him ?",
                        "Which DJ is number one in 2020 ?",
                        "With what song did Martin Garrix blow up ?",
                        "What is Hawkeys' first song release ?",
                        "How old is Hawkeys ?"
                    };

                    List <List <string> > ansList = new List <List <string> > {
                        new List <string> {
                            "Drake", "Lady Gaga", "Nirvana", "Michael Jackson", "3"
                        },
                        new List <string> {
                            "Mariah Carey", "Britney Spears", "Eminem", "The Beatles", "0"
                        },
                        new List <string> {
                            "2pac", "Eminem", "Dr. Dre", "MGK", "1"
                        },
                        new List <string> {
                            "Ed Sheeran", "Daddy Yankee", "Biggie", "Justin Bieber", "3"
                        },
                        new List <string> {
                            "6IX9INE", "Lil Skies", "Lil Uzi", "Travis scott", "0"
                        },
                        new List <string> {
                            "Boef", "Moeman", "KA", "Lil Kleine", "3"
                        },
                        new List <string> {
                            "Fisher", "Oliver Heldens", "Martin Garrix", "Tiesto", "2"
                        },
                        new List <string> {
                            "High on Life", "Virus", "Poison", "Animals", "3"
                        },
                        new List <string> {
                            "Roses", "Rasta", "Bounce", "Ya head", "0"
                        },
                        new List <string> {
                            "25", "28", "20", "18", "2"
                        }
                    };

                    for (int i = 0; i < qstList1.Count; i++)
                    {
                        Question qst = new Question()
                        {
                            QuestionSelf = qstList1[i],
                            QuizId       = quizMade.Id,
                            Type         = 0,
                        };

                        // create Question
                        var resultqst = await _questionRepo.AddQuestionToQuiz(qst);

                        for (int a = 0; a < 4; a++)
                        {
                            if (a == int.Parse(ansList[i][4]))
                            {
                                Answer ans = new Answer()
                                {
                                    IsCorrect   = true,
                                    Answer_Text = ansList[i][a],
                                    QuestionId  = qst.Id
                                };
                                var resultans = await _answerRepo.AddAnswerToQuestion(ans);
                            }

                            else
                            {
                                Answer ans = new Answer()
                                {
                                    IsCorrect   = false,
                                    Answer_Text = ansList[i][a],
                                    QuestionId  = qst.Id
                                };
                                var resultans = await _answerRepo.AddAnswerToQuestion(ans);
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        public async static Task SeedQuiz(IQuizRepo quizRepo, IQuestionRepo questionRepo)
        {
            //quiz over Trivia aanmaken
            string quizName = "Trivia";

            if (await quizRepo.GetQuizByNameAsync(quizName) == null)
            {
                QuizClass newQuiz = new QuizClass()
                {
                    Name        = quizName,
                    Difficulty  = 5,
                    Description = "A quiz about all sorts of things"
                };
                await quizRepo.Create(newQuiz);

                List <Option> opties = new List <Option>();
                Question      vraag  = new Question()
                {
                    Description = "Which of the following items was owned by the fewest U.S. homes in 1990?"
                };
                if (await questionRepo.GetQuestionByDescriptionAsync(vraag.Description) == null)
                {
                    Option option1 = new Option()
                    {
                        OptionDescription = "home computer",
                        CorrectAnswer     = false
                    };
                    Option option2 = new Option()
                    {
                        OptionDescription = "compact disk player",
                        CorrectAnswer     = true
                    };
                    Option option3 = new Option()
                    {
                        OptionDescription = "dishwasher",
                        CorrectAnswer     = false
                    };
                    opties.Add(option1);
                    opties.Add(option2);
                    opties.Add(option3);
                    vraag.PossibleOptions = opties;
                    await questionRepo.Create(vraag);

                    await quizRepo.AddQuestionToQuizAsync(newQuiz.QuizId, vraag.QuestionId);
                }

                vraag = new Question()
                {
                    Description = "How tall is the tallest man on earth?"
                };
                if (await questionRepo.GetQuestionByDescriptionAsync(vraag.Description) == null)
                {
                    Option option1 = new Option()
                    {
                        OptionDescription = "2.72 m",
                        CorrectAnswer     = true
                    };
                    Option option2 = new Option()
                    {
                        OptionDescription = "2.64 m",
                        CorrectAnswer     = false
                    };
                    Option option3 = new Option()
                    {
                        OptionDescription = "3.05 m",
                        CorrectAnswer     = false
                    };
                    opties = new List <Option>();
                    opties.Add(option1);
                    opties.Add(option2);
                    opties.Add(option3);
                    vraag.PossibleOptions = opties;
                    await questionRepo.Create(vraag);

                    await quizRepo.AddQuestionToQuizAsync(newQuiz.QuizId, vraag.QuestionId);
                }
                vraag = new Question()
                {
                    Description = "Which racer holds the record for the most Grand Prix wins?"
                };
                if (await questionRepo.GetQuestionByDescriptionAsync(vraag.Description) == null)
                {
                    Option option1 = new Option()
                    {
                        OptionDescription = "Michael Schumacher",
                        CorrectAnswer     = true
                    };
                    Option option2 = new Option()
                    {
                        OptionDescription = "Mario Andretti",
                        CorrectAnswer     = false
                    };
                    Option option3 = new Option()
                    {
                        OptionDescription = "Lewis Hamilton",
                        CorrectAnswer     = false
                    };
                    opties = new List <Option>();
                    opties.Add(option1);
                    opties.Add(option2);
                    opties.Add(option3);
                    vraag.PossibleOptions = opties;
                    await questionRepo.Create(vraag);

                    await quizRepo.AddQuestionToQuizAsync(newQuiz.QuizId, vraag.QuestionId);
                }
            }
            return;
        }
Exemple #6
0
        public async Task InitQuizzes()
        {
            if (await _userMgr.FindByEmailAsync("*****@*****.**") != null)
            {
                var usr = await _userMgr.FindByEmailAsync("*****@*****.**");

                if (await _quizRepo.GetQuizByNameAsync("Weird Laws") == null)
                {
                    var quiz1 = new Quiz()
                    {
                        Name        = "Weird Laws",
                        Description = "Quiz About Wierd Laws Over The World",
                        Diff        = 0,
                        AppUserId   = usr.Id
                    };

                    Quiz quizMade = await _quizRepo.AddQuizAsync(quiz1);

                    List <String> qstList1 = new List <string> {
                        "In which country are only electricians allowed to change light bulbs ?",
                        "What is illegal on Germany's autobahns ?",
                        "Wearing what will get you told off at ancient sites in Greece ?",
                        "Where is chewing gum a no-go ?",
                        "In Portugal it's illegal to urinate in the what ?",
                        "In which country is it illegal to step on currency ?",
                        "In Spain you'll receive a fine for driving in what ?",
                        "In the US state of Kentucky, women can wear a swimsuit while driving, but only if they carry... ",
                        "Don't honk your car horn in Cyprus if you're...",
                        "In Barbados it's illegal to wear what ?"
                    };

                    List <List <string> > ansList = new List <List <string> > {
                        new List <string> {
                            "Kazakhstan", "Belgium", "Colombia", "Australia", "3"
                        },
                        new List <string> {
                            "Running out of fuel", " Driving With windows down", "Singing while driving", "using your hazard warning lights", "0"
                        },
                        new List <string> {
                            "Foam fingers", "High heels", "Signet rings", "Baseball caps", "1"
                        },
                        new List <string> {
                            "Texas", "Vatican City", "Switzerland", "Singapore", "3"
                        },
                        new List <string> {
                            "Sea", "Shower", "Sink", "Your neighbour's toilet", "0"
                        },
                        new List <string> {
                            "Saudi Arabia", "Wales", "Papua New Guinea", "Thailand", "3"
                        },
                        new List <string> {
                            "Russian-made car", "A Portugal football shirt", "Flip flops", "Both a hat and sunglasses", "2"
                        },
                        new List <string> {
                            "A crucifix", " A sarong", "A bumbag", "An self-defence object", "3"
                        },
                        new List <string> {
                            "Near a hospital", "By a beach", "Wearing a vest", "Driving before 7am", "0"
                        },
                        new List <string> {
                            "Leopard print", "A tie", "Camouflage clothing", "More than one hat", "2"
                        }
                    };

                    for (int i = 0; i < qstList1.Count; i++)
                    {
                        Question qst = new Question()
                        {
                            QuestionSelf = qstList1[i],
                            QuizId       = quizMade.Id,
                            Type         = 0,
                        };

                        // create Question
                        var resultqst = await _questionRepo.AddQuestionToQuiz(qst);

                        for (int a = 0; a < 4; a++)
                        {
                            if (a == int.Parse(ansList[i][4]))
                            {
                                Answer ans = new Answer()
                                {
                                    IsCorrect   = true,
                                    Answer_Text = ansList[i][a],
                                    QuestionId  = qst.Id
                                };
                                var resultans = await _answerRepo.AddAnswerToQuestion(ans);
                            }

                            else
                            {
                                Answer ans = new Answer()
                                {
                                    IsCorrect   = false,
                                    Answer_Text = ansList[i][a],
                                    QuestionId  = qst.Id
                                };
                                var resultans = await _answerRepo.AddAnswerToQuestion(ans);
                            }
                        }
                    }
                }
            }
        }