public async Task <IActionResult> Post([FromBody] Quiz newQuiz)
        {
            try
            {
                await _quizRepo.AddQuiz(newQuiz);

                return(Created($"api/QuizGame/{newQuiz.QuizId}", newQuiz));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to post a quiz: {ex}");
                return(BadRequest("Failed to post a quiz"));
            }
        }
Example #2
0
        public IActionResult Create(Quiz newQuiz, IFormCollection collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _quizRepo.AddQuiz(newQuiz);
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to create a quiz: {ex}");
                return(View(newQuiz));
            }
        }
Example #3
0
        public IActionResult CreateQuiz(string submit, string quizname, string category,
                                        string type_question, string q,
                                        string qa1, string qa2, string qa3, string qa4,
                                        string qa5, string qa6, string qa7, string qa8, string [] qbool)
        {
            //System.Diagnostics.Debug.WriteLine(type);

            Quiz quiz = new Quiz();

            quiz.QuizName = quizname;
            quiz.Category = category;

            quiz.UsernameFK = DataStorage.CurrentlyLoggedInUsername;
            _quiz.AddQuiz(quiz);


            List <Quiz> usersQuizes  = _quiz.GetUsersQuizes(DataStorage.CurrentlyLoggedInUsername);
            uint        actualIdQuiz = usersQuizes[usersQuizes.Count - 1].IdQuiz;


            Question question = new Question();

            question.TextQuestion = q;
            question.QuestionType = type_question;
            question.IdQuizFK     = actualIdQuiz;

            question.Answer1 = qa1;
            question.Answer2 = qa2;

            if (qa3 != null)
            {
                question.Answer3 = qa3;
            }
            if (qa4 != null)
            {
                question.Answer4 = qa4;
            }
            if (qa5 != null)
            {
                question.Answer5 = qa5;
            }
            if (qa6 != null)
            {
                question.Answer6 = qa6;
            }
            if (qa7 != null)
            {
                question.Answer7 = qa7;
            }
            if (qa8 != null)
            {
                question.Answer8 = qa8;
            }


            for (int i = 0; i < qbool.Length; i++)
            {
                if (qbool[i].ElementAt(1) == '1')
                {
                    question.Answer1Bool = true;
                }

                else if (qbool[i].ElementAt(1) == '2')
                {
                    question.Answer2Bool = true;
                }

                else if (qbool[i].ElementAt(1) == '3')
                {
                    question.Answer3Bool = true;
                }

                else if (qbool[i].ElementAt(1) == '4')
                {
                    question.Answer4Bool = true;
                }

                else if (qbool[i].ElementAt(1) == '5')
                {
                    question.Answer5Bool = true;
                }

                else if (qbool[i].ElementAt(1) == '6')
                {
                    question.Answer6Bool = true;
                }

                else if (qbool[i].ElementAt(1) == '7')
                {
                    question.Answer7Bool = true;
                }

                else if (qbool[i].ElementAt(1) == '8')
                {
                    question.Answer8Bool = true;
                }
            }



            _question.AddQuestion(question);

            if (submit.Equals("Dodaj następne pytanie"))
            {
                return(RedirectToAction("AddQuestion", new { @id = actualIdQuiz }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }