public SurveyQuestionViewModel GettSurveyQuestions(int surveyId) { SurveyQuestionViewModel vm = null; var mcQuestionTypes = new[] { 1, 4 }; var surQuestion = db.tSurveyQuestions.Where(a => a.SurveyID == surveyId).OrderBy(q => q.ID).FirstOrDefault(); var totalCount = db.tSurveyQuestions.Where(a => a.SurveyID == surveyId).Count(); if (surQuestion != null) { Mapper.Initialize(cfg => cfg.CreateMap <tSurveyQuestion, SurveyQuestionViewModel>()); vm = Mapper.Map <SurveyQuestionViewModel>(surQuestion); if (mcQuestionTypes.Contains(surQuestion.QuestionTypeID)) { var ansList = db.tSurveyQuestionMCAnswers.Where(a => a.QuestionID == surQuestion.ID).OrderBy(a1 => a1.SequenceOrder).ToList(); if (ansList.Any()) { Mapper.Initialize(cfg => cfg.CreateMap <tSurveyQuestionMCAnswer, SurveyQuestionMCAnswersViewModel>()); vm.tMCAnswers = ansList.Select(a => Mapper.Map <SurveyQuestionMCAnswersViewModel>(a)).ToList(); } } vm.IsLast = totalCount == 1; } return(vm); }
// GET - CREATE QUESTIONS public async Task <ActionResult> AddQuestion(int?surveyId) { if (surveyId == null) { return(HttpNotFound()); } var survey = await _db.Survey.Include(m => m.Questions).SingleOrDefaultAsync(m => m.Id == surveyId); if (survey == null) { return(HttpNotFound()); } var viewModel = new SurveyQuestionViewModel() { Survey = survey, Question = new Question() { SurveyId = survey.Id } }; return(View(viewModel)); }
public async Task <IActionResult> Question(string qIndex) { //keep the index within real parameters if (int.Parse(qIndex) < 1) { return(RedirectToAction("Question", new { qIndex = "1" })); } //retrieve question model SurveyQuestion question = await _surveyAccess.GetQuestionForIndex(qIndex); SurveyQuestionViewModel toRet = new SurveyQuestionViewModel() { QIndex = question.QIndex, QuestionText = question.Question, QType = question.QType, Answers = question.Answers, }; //if this question has the "complete" type, swap to a new action //temporary measures to end the survey without exceeding the database; would be changed in later dev if (toRet.QType == "Complete") { return(RedirectToAction("EndSurvey")); } //parse the answers string into discrete questions toRet.AnswersArray = new List <string>(); if (toRet.Answers != null) { string[] splitter = question.Answers.Split(','); foreach (string phrase in splitter) { toRet.AnswersArray.Add(phrase); } } else { toRet.Answers = "enter your answer..."; toRet.AnswersArray.Add("enter your answer..."); } //return the given question return(View(toRet.QType, toRet)); }
public async Task <ActionResult> AddQuestion(Question question) { if (ModelState.IsValid == false) { var viewModel = new SurveyQuestionViewModel() { Survey = await _db.Survey.Include(m => m.Questions).SingleOrDefaultAsync(m => m.Id == question.SurveyId), Question = question }; return(View(viewModel)); } _db.Question.Add(question); await _db.SaveChangesAsync(); TempData["StatusMessage"] = "Question created successfully"; return(RedirectToAction("AddQuestion", new { surveyId = question.SurveyId })); }
public static SurveyQuestionViewModel ToSurveyQuestionViewModel(SurveyQuestion question) { var viewModel = new SurveyQuestionViewModel() { Id = question.SurveyQuestionID, Text = question.QuestionText.StripLineBreaks(), InputType = Enum.GetName(typeof(InputType), question.InputType), AnswerType = Enum.GetName(typeof(AnswerType), question.AnswerType), Layout = Enum.GetName(typeof(LayoutType), question.Layout), IsRequired = question.IsRequired, IsDisabled = question.IsDisabled, IsVisible = question.IsVisible, HasTrigger = question.HasTrigger, Answer = question.Answer ?? string.Empty, PossibleAnswers = new List <SurveyAnswerViewModel>() }; if (question.InputType == InputType.MultiText) { viewModel.Answers = question.Answers.Select(s => new JsonMultiTextAnswer() { Text = s, Value = s }).ToList(); } foreach (var answer in question.PossibleAnswers.OrderBy(a => a.SortOrder)) { viewModel.PossibleAnswers.Add(new SurveyAnswerViewModel() { Id = answer.SurveyQuestionAnswerID, QuestionId = answer.SurveyQuestionID, Text = answer.AnswerText, ReviewText = !string.IsNullOrEmpty(answer.ReviewAnswerText) ? answer.ReviewAnswerText : answer.AnswerText, IsSelected = answer.IsSelected, IsTrigger = answer.IsTrigger }); } return(viewModel); }
private SocialResponse(bool success, string message, SurveyQuestionViewModel user) : base(success, message) { SurveyQuestionView = user; }
public SocialResponse(SurveyQuestionViewModel user) : this(true, string.Empty, user) { }
public ActionResult SurveyQuestions_Destroy([DataSourceRequest] DataSourceRequest request, SurveyQuestionViewModel vm) { db.DeleteSurveyQuestion(vm.QuestionId); return(Json(new[] { vm }.ToDataSourceResult(request, ModelState))); }
public ActionResult SurveyQuestions_Update([DataSourceRequest] DataSourceRequest request, SurveyQuestionViewModel vm) { if (ModelState.IsValid) { if (vm.QuestionType.QuestionTypeId == 12) { if (string.IsNullOrEmpty(vm.OptionImage)) { ModelState.AddModelError("OptionImage", "Option Image is required"); } } if (vm.QuestionType.QuestionTypeId == 14) { if (string.IsNullOrEmpty(vm.Body)) { ModelState.AddModelError("Body", "Body is required"); } } else { if (string.IsNullOrEmpty(vm.QuestionText)) { ModelState.AddModelError("QuestionText", "Question is required"); } } if (ModelState.IsValid) { db.AddUpdateSurveyQuestion(vm.QuestionId, vm.SurveyId, vm.QuestionType.QuestionTypeId, vm.Name, vm.QuestionText, vm.QuestionImage, vm.OptionImage, vm.Body, vm.Required); } } return(Json(new[] { vm }.ToDataSourceResult(request, ModelState))); }
public async Task <IHttpActionResult> PosttUserSurveyResult(string questionsPassed, tUserSurveyResult tUserSurveyResult) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } /* Saving the Survey Result one by one */ db.tUserSurveyResults.Add(tUserSurveyResult); var result = await db.SaveChangesAsync(); /*Check if Result saved successfully*/ if (result > 0) { var surveyId = tUserSurveyResult.SurveyID; SurveyQuestionViewModel vm = null; var mcQuestionTypes = new[] { 1, 4 }; /* Get the total count of the questions */ var totalCount = webDb.tSurveyQuestions.Where(a => a.SurveyID == surveyId).Count(); var slist = !string.IsNullOrEmpty(questionsPassed) ? questionsPassed.Split(',').Select(a => int.Parse(a)).ToList() : new List <int>(); /* Check if Saved Question is not the last question. * If it is, then don't need to request for next question */ var isLast = (totalCount == slist.Count) && totalCount > 0; if (!isLast) { var surQuestion = webDb.tSurveyQuestions.Where(a => a.SurveyID == surveyId && !slist.Contains(a.ID)).OrderBy(q => q.ID).FirstOrDefault(); if (surQuestion != null) { //if (mcQuestionTypes.Contains(surQuestion.QuestionTypeID)) // surQuestion.tSurveyQuestionMCAnswers = webDb.tSurveyQuestionMCAnswers.Where(a => a.QuestionID == surQuestion.ID).OrderBy(a1 => a1.SequenceOrder).ToList(); //Mapper.Initialize(cfg => cfg.CreateMap<tSurveyQuestion, SurveyQuestionViewModel>()); //vm = Mapper.Map<SurveyQuestionViewModel>(surQuestion); //var passedQuesArray = !string.IsNullOrEmpty(questionsPassed) ? questionsPassed.Split(',').Select(a => int.Parse(a)).ToList() : new List<int>(); Mapper.Initialize(cfg => cfg.CreateMap <tSurveyQuestion, SurveyQuestionViewModel>()); vm = Mapper.Map <SurveyQuestionViewModel>(surQuestion); if (mcQuestionTypes.Contains(surQuestion.QuestionTypeID)) { var ansList = webDb.tSurveyQuestionMCAnswers.Where(a => a.QuestionID == surQuestion.ID).OrderBy(a1 => a1.SequenceOrder).ToList(); if (ansList.Any()) { Mapper.Initialize(cfg => cfg.CreateMap <tSurveyQuestionMCAnswer, SurveyQuestionMCAnswersViewModel>()); vm.tMCAnswers = ansList.Select(a => Mapper.Map <SurveyQuestionMCAnswersViewModel>(a)).ToList(); } } vm.IsLast = totalCount > 0 && ((totalCount - slist.Count) == 1); } } else { vm = new SurveyQuestionViewModel { IsLast = true }; } return(Ok(vm)); } else { return(BadRequest(ModelState)); } //return CreatedAtRoute("DefaultApi", new { id = tUserSurveyResult.ID }, tUserSurveyResult); }