public static SingleAnswerSurveyResponseViewModel Create(IRepository repository, Survey survey, SurveyResponse pendingSurveyResponse)
{
Check.Require(repository != null, "Repository must be supplied");
Check.Require(survey != null);
var viewModel = new SingleAnswerSurveyResponseViewModel{Survey = survey, PendingSurveyResponse = pendingSurveyResponse, SurveyResponse = new SurveyResponse(survey)};
viewModel.Questions = viewModel.Survey.Questions
.Where(a => a.IsActive && a.Category != null && a.Category.IsActive && a.Category.IsCurrentVersion)
.OrderBy(a => a.Order).ToList();
viewModel.TotalActiveQuestions = viewModel.Questions.Count;
if (viewModel.PendingSurveyResponse != null)
{
viewModel.PendingSurveyResponseExists = true;
viewModel.AnsweredQuestions = viewModel.PendingSurveyResponse.Answers.Count;
var answeredQuestionIds = viewModel.PendingSurveyResponse.Answers.Select(a => a.Question.Id).ToList();
viewModel.CurrentQuestion = viewModel.Questions
.Where(a => !answeredQuestionIds.Contains(a.Id))
.OrderBy(a => a.Order)
.FirstOrDefault();
}
else
{
viewModel.PendingSurveyResponseExists = false;
viewModel.AnsweredQuestions = 0;
viewModel.CurrentQuestion = viewModel.Questions.FirstOrDefault();
}
viewModel.DisplayBypass = false;
return viewModel;
}