public ActionResult GetQuizResult(MultipleChoiceAnswer _answer)
        {
            if (string.IsNullOrEmpty(_answer.Answer))
            {
                ModelState.AddModelError("", "You need to choose answer");
                ViewBag.Radiobutton = GetRandomRadiobutton();
                return(PartialView("StatisticPartialView", new StatisticViewModel()));
            }

            var sm = new StatisticManager();

            repository.AddAnswer(_answer);
            StatisticViewModel statisticView = sm.GetQuestionStatistic(repository.GetMultipleQuestion(_answer.QuestionId));

            return(PartialView("StatisticPartialView", statisticView));
        }
Example #2
0
        public ViewResult AlgorithmView(Algorithms alg)
        {
            if (ModelState.IsValid)
            {
                var rep = Repository.Responses;

                if (rep.Count == 0)
                {
                    Algorithms.message = String.Format("Немає доступних задач. Згенеруйте задачу на початковій сторінці");
                    return(View(alg));
                }
                else if (alg.number_task > rep.Count)
                {
                    Algorithms.message = String.Format("Виберіть номер задачі в діапазоні в 1 до {0}", rep.Count);
                    return(View(alg));
                }

                else if (alg.start == alg.finish)
                {
                    Algorithms.message = "Початкова і термінальна вершина не можуть бути однаковими";
                    return(View(alg));
                }
                else if (alg.start < rep[alg.number_task - 1].number_of_nodes && alg.finish < rep[alg.number_task - 1].number_of_nodes)
                {
                    Algorithms.message = "";
                    alg.number_task--;

                    try
                    {
                        if (alg.check_henry_laboder_weight)
                        {
                            alg.Henry_Laboder_Weiht(alg);
                        }
                        else
                        {
                            alg.list_henry_laboder_weight = null;
                        }
                        //throw new NullReferenceException("rez is null");
                    }
                    catch
                    {
                        alg.list_henry_laboder_weight = null;
                    }
                    try
                    {
                        if (alg.check_exact)
                        {
                            alg.ExactAlg(alg);
                        }
                        else
                        {
                            alg.list_exact_alg = null;
                        }
                        //throw new NullReferenceException("rez is null");
                    }
                    catch
                    {
                        alg.list_exact_alg = null;
                    }


                    try
                    {
                        if (alg.check_exact_non_weights)
                        {
                            alg.ExactAlgNonWeights(alg);
                        }
                        else
                        {
                            alg.list_exact_alg_non_weights = null;
                        }
                        //throw new NullReferenceException("rez is null");
                    }
                    catch
                    {
                        alg.list_exact_alg_non_weights = null;
                    }

                    try
                    {
                        if (alg.check_greedy)
                        {
                            alg.GreedyAlg(alg);
                        }
                        else
                        {
                            alg.list_greedy_alg = null;
                        }
                    }
                    catch
                    {
                        alg.list_greedy_alg = null;
                    }

                    try
                    {
                        if (alg.cheeck_henre_laboder_non_weignt)
                        {
                            alg.Henry_Laboder_Non_Weiht(alg);
                        }
                        else
                        {
                            alg.list_henry_laboder_non_weight = null;
                        }
                    }
                    catch
                    {
                        alg.list_henry_laboder_non_weight = null;
                    }



                    alg.number_task++;
                    Repository.AddAnswer(alg);

                    return(View("AnswersView", alg));
                }

                else
                {
                    Algorithms.message = String.Format("Недоступна вершина. Виберіть вершину в діапазоні від 0 до {0}", rep[alg.number_task - 1].number_of_nodes - 1);
                    return(View(alg));
                }
            }
            else
            {
                return(View());
            }
        }
 public IActionResult AddAnswer(Answer answer)
 {
     _repository.AddAnswer(answer);
     return(Json(true));
 }