public IActionResult Quiz(QuizModel model) { if (ModelState.IsValid) { var dogs = _repository.GetToBeAdpoted(); var result = new QuizResultModel(); if (dogs.Count == 0) { return(View("QuizResult", result)); } var dict = new Dictionary <Dog, int>(); foreach (var dog in dogs) { dict[dog] = 0; } foreach (var dog in dogs) { if (dog.Size == model.Size) { dict[dog] += 3; } else if (dog.Size == model.Size + 1 || dog.Size == model.Size - 1) { dict[dog] += 1; } if (dog.HairLenght == model.HairLenght) { dict[dog] += 3; } else if (dog.HairLenght == model.HairLenght + 1 || dog.HairLenght == model.HairLenght - 1) { dict[dog] += 1; } if (dog.Gender == model.Gender) { dict[dog] += 3; } if (dog.GetAge().Equals(model.Age)) { dict[dog] += 2; } } var max = dict.Values.Max(); foreach (var key in dict.Keys) { if (dict[key].Equals(max)) { result.Doggies.Add(new PartialDogInfoModel(key)); } } return(View("QuizResult", result)); } return(View(model)); }
/// <summary> /// Initializes a new instance of the <see cref="QuizResultDTOValidator"/> class. /// </summary> /// <param name="quizResultModel"> /// The quiz Result Model. /// </param> public QuizResultDTOValidator(QuizResultModel quizResultModel) { this.CascadeMode = CascadeMode.StopOnFirstFailure; this.RuleFor(model => model.participantName).NotEmpty().WithError(Errors.CODE_ERRORTYPE_INVALID_OBJECT, "Participant name is empty"); this.RuleFor(model => model.email) .Must((model, x) => (!model.isArchive && string.IsNullOrWhiteSpace(x)) || (model.isArchive && !string.IsNullOrWhiteSpace(x))) .WithError(Errors.CODE_ERRORTYPE_INVALID_OBJECT, "Email should be provided only in isArchive mode") .Must((model, x) => (!model.isArchive && string.IsNullOrWhiteSpace(x)) || (quizResultModel.GetOneByACSessionIdAndEmail(model.acSessionId, x).Value == null && quizResultModel.GetOneByACSessionIdAndAcEmail(model.acSessionId, x).Value == null)) .WithError(Errors.CODE_ERRORTYPE_INVALID_SESSION, "You have already passed this quiz"); }
public async Task <HttpResponseMessage> Post([FromBody] QuizResultModel results) { results.id = Guid.NewGuid(); results.user = System.Security.Claims.ClaimsPrincipal.Current.Identity.Name.ToLower(); // Add the results var photos = await DocumentDBRepository <QuizResultModel> .CreateItemAsync("Scores", results); // Return the item with id return(Request.CreateResponse <QuizResultModel>(HttpStatusCode.OK, results)); }
public async Task <ActionResult> PostScore(QuizResultModel model) { if (!ModelState.IsValid) { return(View("Index", model)); } Logger.Event("PostHighscore"); await apiClient.PostHighScore(model.GameId, model.Name, model.Age); return(RedirectToAction("Index", "Highscore")); }
public ActionResult Result(string id, string student) { var model = new QuizResultModel(); var quizResult = _quizResultService.GetQuizResult(id, student); PrepareQuizResultModel(model, quizResult); //activity log _studentActivityService.InsertActivity("Quiz.Results", "ActivityLog.Quiz.Results." + model.SystemName); return(View(model)); }
private void PrepareQuizResultModel(QuizResultModel model, QuizResult quizResult) { if (quizResult == null) { throw new ArgumentNullException("quizResult"); } if (model == null) { throw new ArgumentNullException("model"); } model.QuizId = quizResult.QuizId; model.SystemName = quizResult.Quiz.SystemName; model.StudentScore = quizResult.Score; model.PassMark = quizResult.Quiz.PassMark; model.IsSystemQuiz = quizResult.Quiz.IsSystemQuiz; model.IsLevelQuiz = quizResult.Quiz.IsLevelQuiz; model.Questions = new List <QuizQuestionModel>(); foreach (var question in quizResult.Quiz.QuizQuestions.OrderBy(q => q.Id)) { var quizQuestion = new QuizQuestionModel(); quizQuestion.Question = question.Question; quizQuestion.Image = question.Image; quizQuestion.Hint = question.Hint; quizQuestion.Answers = new List <QuizAnswerModel>(); foreach (var answer in question.QuizAnswers) { var quizAnswer = new QuizAnswerModel(); quizAnswer.Id = answer.Id; quizAnswer.QuestionId = answer.QuestionId; quizAnswer.Text = answer.Text; quizAnswer.IsCorrect = answer.IsCorrect; quizQuestion.Answers.Add(quizAnswer); } quizQuestion.SelectedAnswer = quizResult.Answers.Where(a => a.QuestionId == question.Id).Select(q => q.AnswerId).FirstOrDefault(); model.Questions.Add(quizQuestion); } }
public QuizResultDataDTO GetQuizResultByACSessionIdAcEmail(int acSessionId, int subModuleItemId, string adobeConnectEmail) { return(QuizResultModel.GetQuizResultByACSessionIdAcEmail(acSessionId, subModuleItemId, adobeConnectEmail)); }
public QuizResultDataDTO GetQuizResultByACSessionId(int acSessionId, int subModuleItemId) { return(QuizResultModel.GetQuizResultByACSessionId(acSessionId, subModuleItemId)); }
public async Task <OperationResultDto> SaveAll(QuizSummaryResultDTO quizResult) { if (quizResult == null) { Logger.Fatal("QuizResultService.SaveAll: ArgumentNullException for quizResult"); throw new ArgumentNullException(nameof(quizResult)); } if (quizResult.quizResults == null) { quizResult.quizResults = new QuizResultDTO[0]; } Logger.Info($"QuizResultService.SaveAll Start: AcSessionId {quizResult.acSessionId}, quizId : {quizResult.quizId}, companyId : {quizResult.companyId}, Count : {quizResult.quizResults.Length}"); IList <string> errorMessages = new List <string>(); try { //TRICK to get eventQuizMappingId var eventQuizMappingId = GetEventQuizMappingId(quizResult); // Quiz quiz = QuizModel.GetOneById(quizResult.quizId).Value; ACSession acSession = ACSessionModel.GetOneById(quizResult.acSessionId).Value; if (acSession == null) { throw new ArgumentException($"There are not session with acSessionId : {quizResult.acSessionId}"); } int acSessionId = acSession.Id; CompanyEventQuizMapping companyEventQuizMapping = null; if (eventQuizMappingId.HasValue && eventQuizMappingId.Value != 0) { companyEventQuizMapping = EventQuizMappingModel.GetOneById(eventQuizMappingId.Value).Value; } if (!IsValid(quizResult, out ValidationResult validationSummaryDtoResult)) { errorMessages = UpdateResultToShortString(validationSummaryDtoResult); return(OperationResultDto.Error(string.Join(";", errorMessages))); } foreach (var appletResultDTO in quizResult.quizResults) { appletResultDTO.acSessionId = quizResult.acSessionId; if (IsValid(appletResultDTO, out ValidationResult validationResult)) { var appletResult = ConvertDto(appletResultDTO, quiz, acSessionId, companyEventQuizMapping); QuizResultModel.RegisterSave(appletResult); if (appletResultDTO.results != null) { await SaveAllAsync(appletResult, appletResultDTO.results); } } else { errorMessages.AddRange(UpdateResultToShortString(validationResult)); } } } catch (ArgumentException ex) { Logger.Error("QuizResultService.SaveAll:", ex); throw; } catch (Exception ex) { Logger.Error($"QuizResultService.SaveAll json={JsonConvert.SerializeObject(quizResult)}", ex); throw; } return(errorMessages.Any() ? OperationResultDto.Error(string.Join(";", errorMessages)) : OperationResultDto.Success()); }