public async Task <IActionResult> Create() { var qqListOperation = await _qqbo.ListAsync(); if (!qqListOperation.Success) { return(OperationErrorBackToIndex(qqListOperation.Exception)); } var qqList = new List <QuizQuestionViewModel>(); foreach (var qq in qqListOperation.Result) { if (!qq.IsDeleted) { var qqvm = QuizQuestionViewModel.Parse(qq); qqList.Add(qqvm); } ViewBag.QuizQuestions = qqList.Select(qq => new SelectListItem() { Text = qq.Question, Value = qq.Id.ToString() }); } ViewData["Title"] = "New Answer"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "New", Controller = "QuizAnswers", Icon = "fa-plus", Text = "New" }); ViewData["BreadCrumbs"] = crumbs; return(View()); }
public ActionResult Update([FromBody] QuizQuestionViewModel c) { var currentResult = _bo.Read(c.Id); if (!currentResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Question == c.Question && current.QuizId == c.QuizId) { return(new ObjectResult(HttpStatusCode.NotModified)); } if (current.Question != c.Question) { current.Question = c.Question; } if (current.QuizId != c.QuizId) { current.QuizId = c.QuizId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } return(Ok()); }
public async Task <IActionResult> QuizStart(/*IEnumerable<QuizAnswerViewModel> vm*/) { var listOperation = await _bo.ListAsync(); var qqListOperation = await _qqbo.ListAsync(); var list = new List <QuizAnswerViewModel>(); foreach (var item in listOperation.Result) { if (!item.IsDeleted) { list.Add(QuizAnswerViewModel.Parse(item)); } } var qqList = new List <QuizQuestionViewModel>(); foreach (var item in qqListOperation.Result) { if (!item.IsDeleted) { qqList.Add(QuizQuestionViewModel.Parse(item)); } } ViewBag.QuizQuestions = qqList; return(View(list)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id, Question, QuizId")] QuizQuestionViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var result = getOperation.Result; result.Question = vm.Question; result.QuizId = vm.QuizId; var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { return(OperationErrorBackToIndex(updateOperation.Exception)); } else { return(OperationSuccess("The record was successfuly updated")); } } return(RedirectToAction(nameof(Index))); }
public ActionResult Create([FromBody] QuizQuestionViewModel vm) { var c = new QuizQuestion(vm.Question, vm.QuizId); var res = _bo.Create(c); var code = res.Success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError; return(new ObjectResult(code)); }
public async Task <ActionResult> PostAnswer(QuizQuestionViewModel model) { if (!ModelState.IsValid) { return(View("Index", model)); } await apiClient.SaveAnswer(model.GameId, model.QuestionNr, model.SelectedAnswer); return(RedirectToAction("Index", new { category = model.Category, questionNr = model.QuestionNr + 1, gameId = model.GameId })); }
// POST: api/QuizQuestion public HttpResponseMessage Post([FromBody] QuizQuestionViewModel quizQuestion) { if (this.Service.AddNewQuizQuestion(quizQuestion)) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, GetErrors())); } }
public IActionResult QuizQuestion(QuizQuestionViewModel model) { bool isCorrectAnswer = false; int score = model.CurrentScore; if (model.SelectedAnswerId != null) { isCorrectAnswer = _answerService.Get(x => x.Id == model.SelectedAnswerId).IsTrue; if (isCorrectAnswer) { score += model.CurrentQuestionScore; } } _quizHistoryService.Add(new QuizHistory { AnswerId = model.SelectedAnswerId, CreateDateTime = DateTime.Now, IsCorrectAnswer = isCorrectAnswer, QuestionId = model.QuestionId, SessionId = model.SessionId, UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value, QuizCategoryId = model.CategoryId }); if (model.IsLastQuestion) { var isPass = (int)Math.Round((double)(100 * score) / model.TotalScore) >= int.Parse(_configuration["PassingPercentageForQuiz"]); _quizSummaryService.Add(new QuizSummary { IsPass = isPass, ObtainedScore = score, QuizCategoryId = model.CategoryId, SessionId = model.SessionId, TotalQuestions = model.TotalQuestions, TotalScore = model.TotalScore, UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value, CreateDateTime = DateTime.Now }); return(RedirectToAction("QuizResult", new ResultViewModel { IsPass = isPass, ObtainedScore = score, TotalScore = model.TotalScore })); } var currentSessionId = model.SessionId; var totalScore = model.TotalScore; model = SetQuizQuestionModel(model.CategoryId, model.QuestionNumber); model.CurrentScore = score; model.SessionId = currentSessionId; model.TotalScore = totalScore + model.CurrentQuestionScore; return(View(model)); }
public void ValidateQuizQuestion(QuizQuestionViewModel quizQuestionViewModel) { if (String.IsNullOrWhiteSpace(quizQuestionViewModel.Question)) { this.ValidationDictionary.AddError("Question", "Question is required"); } if (String.IsNullOrWhiteSpace(quizQuestionViewModel.Answer)) { this.ValidationDictionary.AddError("Answer", "Answer is required"); } }
public async Task <IActionResult> Create([Bind("Question", "QuizId")] QuizQuestionViewModel vm) { if (ModelState.IsValid) { var quizAnswer = vm.ToQuizQuestion(); var createOperation = await _bo.CreateAsync(quizAnswer); if (!createOperation.Success) { return(OperationErrorBackToIndex(createOperation.Exception)); } return(OperationSuccess("The record was successfuly created")); } return(View(vm)); }
public ActionResult <List <QuizQuestionViewModel> > List() { var res = _bo.List(); if (!res.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } var list = new List <QuizQuestionViewModel>(); foreach (var item in res.Result) { list.Add(QuizQuestionViewModel.Parse(item)); } return(list); }
public ActionResult AddQuestion(QuizQuestionViewModel model, int id) { if (!ModelState.IsValid) { return(View(model)); } _quizQuestionRepository.Insert(new DataLayer.Entities.QuizQuestion { ForQuizId = id, QuestionText = model.QuestionText }); return(RedirectToAction("AddQuestion")); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var qqListOperation = await _qqbo.ListAsync(); if (!qqListOperation.Success) { return(OperationErrorBackToIndex(qqListOperation.Exception)); } var qListOperation = await _qbo.ListAsync(); if (!qListOperation.Success) { return(OperationErrorBackToIndex(qListOperation.Exception)); } var list = new List <QuizAnswerViewModel>(); foreach (var item in listOperation.Result) { if (!item.IsDeleted) { list.Add(QuizAnswerViewModel.Parse(item)); } } var qqList = new List <QuizQuestionViewModel>(); foreach (var item in qqListOperation.Result) { if (!item.IsDeleted) { qqList.Add(QuizQuestionViewModel.Parse(item)); } } ViewData["Title"] = "Quiz Answer"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); ViewBag.QuizQuestions = qqList; return(View(list)); }
public ActionResult <QuizQuestionViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var cvm = QuizQuestionViewModel.Parse(res.Result); return(cvm); } else { return(new ObjectResult(HttpStatusCode.InternalServerError)); } }
public PartialViewResult PreviousQuestion(Guid questionId, Guid userId, Guid?answerId) { var service = new QuestionService(); var question = service.GetQuestion(questionId); var user = service.GetUser(userId); if (question == null || user == null) { return(PartialView("Error")); } // Antwort Ermitteln var answer = answerId != null?service.GetAnswer(answerId.Value) : null; // Service übernimmt den Update service.WriteLog(question, answer, user); // Frage davor ermitteln var model = new QuizQuestionViewModel(); var prevQuestion = service.GetPreviousQuestion(question); if (prevQuestion != null) { var category = prevQuestion.Category; model.User = user; model.Question = prevQuestion; model.NumQuestions = category.Questions.Count; model.Answer = service.GetAnswer(prevQuestion, user); // ist das die erste Frage? if (prevQuestion.Category.Reihenfolge == 1 && prevQuestion.Reihenfolge == 1) { model.IsFirstQuestion = true; } return(PartialView("_Question", model)); } return(PartialView("Error")); }
public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(RecordNotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var getQQOperation = await _qqbo.ReadAsync(getOperation.Result.QuizQuestionId); if (!getQQOperation.Success) { return(OperationErrorBackToIndex(getQQOperation.Exception)); } if (getQQOperation.Result == null) { return(RecordNotFound()); } var vm = QuizAnswerViewModel.Parse(getOperation.Result); ViewData["Title"] = "Quiz Answer"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "New", Controller = "QuizAnswers", Icon = "fa-search", Text = "Detail" }); ViewData["QuizQuestion"] = QuizQuestionViewModel.Parse(getQQOperation.Result); ViewData["BreadCrumbs"] = crumbs; return(View(vm)); }
public PartialViewResult NextQuestion(Guid questionId, Guid userId, Guid?answerId) { var service = new QuestionService(); var question = service.GetQuestion(questionId); var user = service.GetUser(userId); if (question == null || user == null) { return(PartialView("Error")); } // den Logeintrag erstellen var answer = answerId != null?service.GetAnswer(answerId.Value) : null; // Ergebnis wird nicht weiter verarbeitet service.WriteLog(question, answer, user); // Nächste Frage in jedem Fall anzeigen var model = new QuizQuestionViewModel(); var nextQuestion = service.GetNextQuestion(question); if (nextQuestion != null) { var category = nextQuestion.Category; model.User = user; model.Question = nextQuestion; model.NumQuestions = category.Questions.Count; model.Answer = service.GetAnswer(nextQuestion, user); return(PartialView("_Question", model)); } // es gibt keine Frage mehr return(PartialView("_EndOfQuiz", user)); }
public ActionResult Index(string category, int gameId = 0, int questionNr = 1) { if (questionNr == 1) { var game = apiClient.StartGame(category, 5).Result; gameId = game.Id; } var q = apiClient.GetQuestion(gameId, questionNr).Result; if (q != null) { var questionModel = new QuizQuestionViewModel() { Id = q.Id, Category = q.Category, Question = q.Question, QuestionNr = q.QuestionNr, QuestionsTotalNr = q.TotalNrQuestions, GameId = gameId }; questionModel.Answers = new List <QuizAnswerModel>(); foreach (var a in q.Choices) { questionModel.Answers.Add( new QuizAnswerModel() { Id = a.Id, AnswerText = a.Text }); } return(View(questionModel)); } var result = this.apiClient.FinishGame(gameId).Result; return(View("Finished", new QuizResultModel(result))); }
// GET: Quest/Quiz public ActionResult Index(Guid id) { var service = new QuestionService(); var user = service.GetUser(id); var model = new QuizQuestionViewModel(); var firstQuestion = service.GetFirstQuestion(); if (firstQuestion != null) { var category = firstQuestion.Category; model.User = user; model.Question = firstQuestion; model.NumQuestions = category.Questions.Count; model.IsFirstQuestion = true; model.Answer = service.GetAnswer(firstQuestion, user); } return(View(model)); }
public bool AddNewQuizQuestion(QuizQuestionViewModel quizQuestionViewModel) { ValidateQuizQuestion(quizQuestionViewModel); if (this.ValidationDictionary.IsValid) { var quizQuestion = new QuizQuestion { QuizQuestionId = Guid.NewGuid(), Question = quizQuestionViewModel.Question, Answer = quizQuestionViewModel.Answer }; this.QuizQuestionRepository.AddQuestion(quizQuestion); this.QuizQuestionRepository.SaveChanges(); return(true); } else { return(false); } }
private QuizQuestionViewModel SetQuizQuestionModel(int category, int skip = 0) { QuizQuestionViewModel model = new QuizQuestionViewModel(); var questions = _questionService.List(x => x.QuizCategoryId == category).OrderBy(x => x.Id).ToList(); if (questions != null) { int totalQuestions = questions.Count; if (totalQuestions > 0) { var nextQuestion = questions.Skip(skip).FirstOrDefault(); if (nextQuestion != null) { var answers = _answerService.List(x => x.QuestionId == nextQuestion.Id).ToList(); int questionNumber = 1 + skip; model = new QuizQuestionViewModel { CategoryId = category, Question = nextQuestion, Answers = answers, QuestionNumber = questionNumber, CurrentScore = 0, TotalQuestions = totalQuestions, SessionId = HttpContext.Session.Id, QuestionId = nextQuestion.Id, CurrentQuestionScore = nextQuestion.ScoreToWin, TotalScore = nextQuestion.ScoreToWin }; } } } return(model); }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(RecordNotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var vm = QuizQuestionViewModel.Parse(getOperation.Result); var listIpOperation = await _qbo.ListAsync(); if (!listIpOperation.Success) { return(OperationErrorBackToIndex(listIpOperation.Exception)); } var qList = new List <SelectListItem>(); foreach (var item in listIpOperation.Result) { if (!item.IsDeleted) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Title }; if (item.Id == vm.QuizId) { listItem.Selected = true; } qList.Add(listItem); } } ViewBag.Quizzes = qList; ViewData["Title"] = "Edit Quiz Question"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "Edit", Controller = "QuizQuestion", Icon = "fa-edit", Text = "Edit" }); ViewData["BreadCrumbs"] = crumbs; return(View(vm)); //var vm = QuizQuestionViewModel.Parse(getOperation.Result); //ViewData["Title"] = "Edit Question"; //var crumbs = GetCrumbs(); //crumbs.Add(new BreadCrumb() { Action = "Edit", Controller = "QuizQuestions", Icon = "fa-edit", Text = "Edit" }); //ViewData["BreadCrumbs"] = crumbs; //return View(vm); }