public Statistic GetStatistic(Survey survey)
        {
            CheckContext();
            var personsDb =  _context.Persons.ToList();
            if (personsDb.Any())
            {
                var surveyContext = getSurveyFromContext(_context);
                survey.Questions = surveyContext.Questions;
                var personsWhoIsFemale = personsDb.Where(p => p.IsFemale).ToList();

                var statPersonFemale = new StatisticPerson();
                statPersonFemale.Phones = getStatPhoneFromAnswers(survey.Questions[1].Answers, personsWhoIsFemale);
                statPersonFemale.IsFemale = true;
                statPersonFemale.Count = personsWhoIsFemale.Count;
                statPersonFemale.Percent = getPercentFromInt(personsDb.Count, personsWhoIsFemale.Count);

                var personWhoIsMale = personsDb.Where(p => !p.IsFemale).ToList();

                var statPersonMale = new StatisticPerson();
                statPersonMale.Phones = getStatPhoneFromAnswers(survey.Questions[1].Answers, personWhoIsMale);
                statPersonMale.Count = personWhoIsMale.Count;
                statPersonMale.Percent = getPercentFromInt(personsDb.Count, statPersonMale.Count);

                var stat = new Statistic() { Total = personsDb.Count, Females = statPersonFemale, Males = statPersonMale };
                return stat;
            }
            return null;
        }
 public ActionResult SubmitForm(Survey survey)
 {
     CheckContext();
     if (ModelState.IsValid)
     {
         _context.Persons.Add(toPersonDb(survey.Persons.First()));
         _context.SaveChanges();
         var stat = GetStatistic(survey);
         return PartialView("~/Views/Partials/ShowStatisticsForm.cshtml", stat);
     }
     return PartialView("~/Views/Partials/ValidationView.cshtml", survey);
 }
 private Survey getSurveyFromContext(SurveyContext context)
 {
     var survey = new Survey();
     survey.Persons = getPersons(context.Persons);
     survey.Questions = getQuestions(context.Questions);
     return survey;
 }