public async Task <ActionResult> CreateAnswer(IFormCollection collection, Answer ans)
        {
            try
            {
                // TODO: Add insert logic here
                var created = await _answerRepo.AddAnswerToQuestion(ans);

                if (created == null)
                {
                    throw new Exception("Invalid Entry.");
                }
                return(RedirectToAction("Answers", "Quiz", new { id = created.QuestionId }));
            }
            catch
            {
                return(View());
            }
        }
        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);
                            }
                        }
                    }
                }
            }
        }
Example #3
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);
                            }
                        }
                    }
                }
            }
        }