public ActionResult Create([Bind(Include = "QuestionID,QuestionText,QuizID")] Question question)
        {
            if (ModelState.IsValid)
            {
                db.Questions.Add(question);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.QuizID = new SelectList(db.Quizs, "QuizID", "QuizName", question.QuizID);
            return(View(question));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "ChoiceID,ChoiceText,QuestionID")] Choice choice)
        {
            if (ModelState.IsValid)
            {
                db.Choices.Add(choice);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.QuestionID = new SelectList(db.Questions, "QuestionID", "QuestionText", choice.QuestionID);
            return(View(choice));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "QuizID,QuizName,Category,Author")] Quiz quiz)
        {
            quiz.Author = User.Identity.Name;

            if (ModelState.IsValid)
            {
                db.Quizs.Add(quiz);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(quiz));
        }
Esempio n. 4
0
        public ActionResult RegisterUser(
            string FullName,
            string ProfileImage
            )
        {
            string message = "";

            using (var db = new DBQuizEntities())
            {
                var users = db.Set <User>();
                users.Add(new User {
                    FullName = FullName, ProfilImage = ProfileImage
                });
                int status = db.SaveChanges();
                if (status > 0)
                {
                    message = "Save data successfully";
                }
                else
                {
                    message = "Save data failed.";
                }
            }
            return(Json(message, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public ActionResult Create([Bind(Include = "AnswerID,AnswerText,QuestionID")] Answer answer)
        {
            if (ModelState.IsValid)
            {
                int check_no_answers = db.Answers.Where(y => y.QuestionID == answer.QuestionID).Count();

                if (check_no_answers >= 1)
                {
                    ModelState.AddModelError("", "Error añadiendo la respuesta. ¡Una pregunta no puede tener más de una respuesta!");
                }

                else
                {
                    db.Answers.Add(answer);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.QuestionID = new SelectList(db.Questions, "QuestionID", "QuestionText", answer.QuestionID);
            return(View(answer));
        }
Esempio n. 6
0
        public ActionResult QuizTest(List <QuizAnswersVM> resultQuiz)
        {
            List <QuizAnswersVM> finalResultQuiz = new List <QuizAnswersVM>();

            foreach (QuizAnswersVM answser in resultQuiz)
            {
                QuizAnswersVM result = dbContext.Answers.Where(a => a.QuestionID == answser.QuestionID).Select(a => new QuizAnswersVM
                {
                    QuestionID = a.QuestionID.Value,
                    AnswerQ    = a.AnswerText,
                    isCorrect  = (answser.AnswerQ.ToLower().Equals(a.AnswerText.ToLower()))
                }).FirstOrDefault();

                finalResultQuiz.Add(result);

                try
                {
                    bool chech_answer = dbContext.Answers.Select(x => x.AnswerText).ToList().Contains(answser.AnswerQ);

                    var update_resultados = resultQuiz.Where(x => x.AnswerQ == answser.AnswerQ).Select(y => new UserAnswer
                    {
                        QuestionID     = y.QuestionID,
                        UserAnswerText = y.AnswerQ,
                        Is_Answer      = chech_answer
                    }).FirstOrDefault();

                    dbContext.UserAnswers.Add(update_resultados);

                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return(Json(new { result = finalResultQuiz }, JsonRequestBehavior.AllowGet));
        }