Esempio n. 1
0
        public async Task <JsonResult> Upload(int questionId, HttpPostedFileBase blob)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //  Запускаем разпозавание в новом потоке
                    Task <int> task1 = new Task <int>(() => _recognizeService.Recognize(blob.InputStream));
                    task1.Start();
                    int selectedOption = await task1;

                    //  если текст распознался, то сохраняем ответ
                    if (selectedOption > 0)
                    {
                        //  находим вопрос
                        Question question = await _questionService.Get(questionId);

                        if (question != null)
                        {
                            //  выбираем опцию по порядковому номеру
                            Option op = question.Options.ElementAtOrDefault(selectedOption - 1);
                            if (op != null)
                            {
                                //  переводим каретку на начало потока и приводим поток в массив байтов
                                blob.InputStream.Seek(0, SeekOrigin.Begin);
                                MemoryStream ms = new MemoryStream();
                                blob.InputStream.CopyTo(ms);

                                Result result = new Result()
                                {
                                    Voice    = ms.ToArray(),
                                    OptionId = op.Id
                                };
                                await _resultService.Create(result);

                                return(Json(new { success = true, selectedOption = selectedOption, isLastQuestion = await isLastQuestion(questionId) }));
                            }
                        }
                    }
                }
                catch (Exception e) {
                    return(Json(new { success = false, message = e.Message + " " + e.InnerException?.Message }));
                }
            }
            return(Json(new { success = false }));
        }
Esempio n. 2
0
 public async Task <ActionResult> Create(Result result)
 {
     if (!ModelState.IsValid)
     {
         return(new InvalidObjectHttpException().ToJson());
     }
     return(await _resultService.Create(result));
 }
        public async Task <IActionResult> PostStudentTerm([FromBody] StudentTermDto studentTermDto)
        {
            var studentTerm = mapper.Map <StudentTerm>(studentTermDto);

            try
            {
                resultService.Create(studentTerm);

                await unitOfWork.CompleteAsync();

                return(Ok(studentTerm));
            }
            catch (AppException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 4
0
        public JsonResult Result(List <string> values, int testId)
        {
            int countIsRightAnswer = 0;

            var questions = _questionService.GetAll().Where(x => x.TestId == testId).ToList();

            var totalScore = 0;

            for (int i = 0; i < questions.Count(); i++)
            {
                var answers = _answerService.GetAll().Where(x => x.QuestionId == questions[i].QuestionId && x.IsRight).ToList();

                for (int j = 0; j < answers.Count(); j++)
                {
                    for (int k = 0; k < values.Count; k++)
                    {
                        if (values[k] == answers[j].Text)
                        {
                            countIsRightAnswer++;
                            totalScore += questions[i].Score;
                            break;
                        }
                    }
                }
            }

            AccountVM account = _accountService.GetByName(User.Identity.Name);

            ResultVM result = new ResultVM {
                TimeStart = DateTime.Now, AccountId = account.AccountId, TestId = testId, TotalScore = totalScore
            };

            _resultService.Create(result);

            return(Json(totalScore));
        }
Esempio n. 5
0
        public ActionResult AnswerQuestion(AnswerModel answerModel, string[] results)
        {
            answerModel.questions = (List <QuestionDTO>)TempData["questions"];
            answerModel.results   = (List <AnswerDTO>)TempData["answers"];

            if (answerModel.Type.Equals("Тест"))
            {
                if (answerModel.questions[0].EntryType.Equals("Множественный"))
                {
                    if (results != null)
                    {
                        if (checkResults(results, answerModel.questions[0]))
                        {
                            answerModel.results.Add(new AnswerDTO
                            {
                                Text_of_answer = string.Join("", results),
                                isTrue         = true,
                                QuestionId     = answerModel.questions[0].Id
                            });
                        }
                        else
                        {
                            answerModel.results.Add(new AnswerDTO
                            {
                                Text_of_answer = string.Join("", results),
                                isTrue         = false,
                                QuestionId     = answerModel.questions[0].Id
                            });
                        }
                    }
                }
                else
                {
                    if (answerModel.questions[0].Answers.FirstOrDefault(x => x.Text_of_answer.Equals(answerModel.result)) != null)
                    {
                        answerModel.results.Add(answerModel.questions[0].Answers.FirstOrDefault(x => x.Text_of_answer.Equals(answerModel.result)));
                    }
                    else
                    {
                        if (answerModel.questions[0].Answers.Where(x => x.isTrue == false).Count() > 0)
                        {
                            answerModel.results.Add(answerModel.questions[0].Answers.FirstOrDefault(x => x.isTrue == false));
                        }
                        else
                        {
                            if (answerModel.result != null)
                            {
                                answerModel.results.Add(new AnswerDTO
                                {
                                    Text_of_answer = answerModel.result.ToString(),
                                    isTrue         = false,
                                    QuestionId     = answerModel.questions[0].Id
                                });
                            }
                            else
                            {
                                answerModel.results.Add(new AnswerDTO
                                {
                                    Text_of_answer = "не отвечено",
                                    isTrue         = false,
                                    QuestionId     = answerModel.questions[0].Id
                                });
                            }
                        }
                    }
                }
            }

            if (answerModel.Type.Equals("Опрос"))
            {
                if (answerModel.questions[0].EntryType.Equals("Множественный"))
                {
                    if (results != null)
                    {
                        answerModel.results.Add(new AnswerDTO
                        {
                            Text_of_answer = string.Join("", results),
                            isTrue         = true,
                            QuestionId     = answerModel.questions[0].Id
                        });
                    }
                    else
                    {
                        answerModel.results.Add(new AnswerDTO
                        {
                            isTrue     = false,
                            QuestionId = answerModel.questions[0].Id
                        });
                    }
                }
                else
                {
                    if (answerModel.questions[0].EntryType.Equals("Ввод"))
                    {
                        if (null == answerModel.result)
                        {
                            answerModel.results.Add(new AnswerDTO {
                                isTrue = false, QuestionId = answerModel.questions[0].Id
                            });
                        }
                        else
                        {
                            answerModel.results.Add(new AnswerDTO
                            {
                                isTrue         = true,
                                Text_of_answer = answerModel.result,
                                QuestionId     = answerModel.questions[0].Id
                            });
                        }
                    }
                    else
                    {
                        if (answerModel.questions[0].Answers.FirstOrDefault(x => x.Text_of_answer.Equals(answerModel.result)) != null)
                        {
                            answerModel.results.Add(answerModel.questions[0].Answers.FirstOrDefault(x => x.Text_of_answer.Equals(answerModel.result)));
                        }
                        else
                        {
                            answerModel.results.Add(new AnswerDTO
                            {
                                isTrue     = false,
                                QuestionId = answerModel.questions[0].Id
                            });
                        }
                    }
                }
            }

            answerModel.questions.RemoveAt(0);
            answerModel.result = "";

            if (answerModel.questions.Count > 0 && questService.GetById(answerModel.idQuest).Active)
            {
                if (answerModel.questions[0].ImageId != null)
                {
                    ViewBag.Image = imageService.GetById(answerModel.questions[0].ImageId).Data;
                }
                return(View("AnswerQuestion", answerModel));
            }
            else
            {
                if (!questService.GetById(answerModel.idQuest).Active)
                {
                    if (questService.GetById(answerModel.idQuest).Type.Equals("Опрос"))
                    {
                        foreach (var item in answerModel.questions)
                        {
                            answerModel.results.Add(new AnswerDTO
                            {
                                isTrue     = false,
                                QuestionId = item.Id
                            });
                        }
                    }
                    else
                    {
                        foreach (var item in answerModel.questions)
                        {
                            answerModel.results.Add(new AnswerDTO
                            {
                                Text_of_answer = "не отвечено",
                                isTrue         = false,
                                QuestionId     = item.Id
                            });
                        }
                    }
                }
            }
            resultService.Create(CreateResult(answerModel));

            var result = Mapper.Map <ResultDTO, ViewResultModel>(CreateResult(answerModel));

            Debug.WriteLine("RESULT " + result.Id + " " + result.Mark + " " + result.Percente + " " + " " + result.QuestId);

            if (answerModel.Type.Equals("Тест"))
            {
                return(View("Result", result));
            }
            else
            {
                return(View("AskingResult", result));
            }
        }