public IActionResult Delete(QuestionAnswersStatus status, int id) { if (id != 0) { QuestionAnswersViewModel model = new QuestionAnswersViewModel(); model.QuestionAnswer = _db.QuestionAnswers.FirstOrDefault(v => v.Id == id); model.Status = status; if (model.QuestionAnswer != null) { return(View(model)); } } return(NotFound()); }
public IActionResult Create(QuestionAnswersStatus status, int id, int?postId) { QuestionAnswersViewModel model = new QuestionAnswersViewModel(); if (id != 0) { model.QuestionAnswer = _db.QuestionAnswers.FirstOrDefault(q => q.Id == id); } else { model.QuestionAnswer = new QuestionAnswer(); } model.Status = status; model.StepId = postId; return(View(model)); }
public IActionResult Create(QuestionAnswersViewModel model) { if (ModelState.IsValid) { QuestionAnswer questionAnswer = new QuestionAnswer(); questionAnswer.Question = model.QuestionAnswer.Question; questionAnswer.Answer = model.QuestionAnswer.Answer; questionAnswer.StepId = model.StepId; questionAnswer.AskingId = _userManager.GetUserId(User); questionAnswer.State = model.QuestionAnswer.State; _db.QuestionAnswers.Add(questionAnswer); _db.SaveChanges(); } return(RedirectToAction("Index", "QuestionAnswers")); }
public IActionResult Answers(QuestionAnswersViewModel qm) { if (!ModelState.IsValid) { return(DisplayQuestionAndAnswersView(qm.Question.Id)); } User user = _dataService.GetUser(this.User.Identity.Name); Answer answer = new Answer { QuestionId = qm.Question.Id, UserId = user.Id, DateCreated = DateTime.Now, Text = qm.Answer }; _dataService.AddAnswer(answer); return(RedirectToAction("Answers", new { id = qm.Question.Id })); }
public IActionResult ConfirmDelete(QuestionAnswersViewModel model) { if (model.QuestionAnswer.Id != 0) { QuestionAnswer questionAnswer = _db.QuestionAnswers.FirstOrDefault(v => v.Id == model.QuestionAnswer.Id); if (questionAnswer != null) { _db.QuestionAnswers.Remove(questionAnswer); _db.SaveChanges(); } if (model.Status == QuestionAnswersStatus.Edit) { return(RedirectToAction("Index", "FaqManage")); } return(RedirectToAction("IndexQuestions", "FaqManage")); } return(NotFound()); }
private IActionResult DisplayQuestionAndAnswersView(int id) { Question q = _dataService.GetQuestionWithAnswers(id); QuestionAnswersViewModel qm = new QuestionAnswersViewModel { Question = new QuestionAnswerViewModel { Id = q.Id, DateCreated = q.DateCreated, Text = q.Text, Title = q.Title, UserName = q.User.UserName }, Answers = q.Answers.Select(a => new QuestionAnswerViewModel { Text = a.Text, UserName = a.User.UserName, DateCreated = a.DateCreated }).ToList(), }; return(View(qm)); }
public IActionResult Create(QuestionAnswersViewModel model) { if (ModelState.IsValid) { QuestionAnswer questionAnswer = new QuestionAnswer(); if (model.Status == QuestionAnswersStatus.Edit || model.Status == QuestionAnswersStatus.ToAnswer) { questionAnswer = _db.QuestionAnswers.FirstOrDefault(q => q.Id == model.QuestionAnswer.Id); questionAnswer.Question = model.QuestionAnswer.Question; questionAnswer.Answer = model.QuestionAnswer.Answer; questionAnswer.StepId = model.StepId; questionAnswer.ResponderId = _userManager.GetUserId(User); _db.QuestionAnswers.Update(questionAnswer); } else { model.QuestionAnswer.State = State.Ответили; questionAnswer.Question = model.QuestionAnswer.Question; questionAnswer.Answer = model.QuestionAnswer.Answer; questionAnswer.StepId = model.StepId; questionAnswer.ResponderId = _userManager.GetUserId(User); questionAnswer.State = model.QuestionAnswer.State; _db.QuestionAnswers.Add(questionAnswer); } _db.SaveChanges(); } if (model.Status == QuestionAnswersStatus.ToAnswer) { return(RedirectToAction("IndexQuestions", "FaqManage")); } return(RedirectToAction("Index", "FaqManage")); }
public IActionResult SubmitSurvey(string guid, string session, QuestionAnswersRequestViewModel data) { List <QuestionAnswersViewModel> jObject = data.data; Survey sur = _dBContext.Survey.Where(x => x.SurveyGuid == guid).FirstOrDefault(); if (sur == null) { return(BadRequest(Messages.SurveyNotFoundError)); } if (sur.Enddate < DateTime.UtcNow) { return(BadRequest(Messages.SurveyEnded)); } var surveyUsers = _dBContext.SurveyUser.Where(x => x.SurveyId == sur.Surveyid && x.SurveyUserGuid.Equals(session)).FirstOrDefault(); if (surveyUsers == null) { return(BadRequest(Messages.SurveyWasNotStartedByUser)); } if (surveyUsers.CompletedDatetime != null) { return(BadRequest(Messages.SurveyWasAlreadySubmitted)); } List <SurveyQuestions> questions = _dBContext.SurveyQuestions.Where(x => x.SurveyId == sur.Surveyid && x.StatusId != (int)EnumStatus.Deleted).ToList(); List <QuestionType> lstQuestionTypes = _dBContext.QuestionType.ToList(); List <SurveyUserQuestionOptions> lstSurveyUserQuestionOptions = new List <SurveyUserQuestionOptions>(); for (int i = 0; i < questions.Count; i++) { SurveyUserQuestionOptions surveyUserQuestionOption = new SurveyUserQuestionOptions(); surveyUserQuestionOption.SurveyUserId = surveyUsers.SurveyUserId; surveyUserQuestionOption.SurveyQuestionId = questions[i].SurveyQuestionId; surveyUserQuestionOption.InsertedDatetime = DateTime.UtcNow; QuestionAnswersViewModel requestViewModel = jObject.Where(x => x.key == questions[i].SurveyQuestionId.ToString()).FirstOrDefault(); List <SurveyQuestionOptions> surveyQuestionOptions = _dBContext.SurveyQuestionOptions.Where(x => x.SurveyQuestionId == surveyUserQuestionOption.SurveyQuestionId).OrderBy(x => x.OptionKey).ToList(); var questionTypeCode = lstQuestionTypes.Where(x => x.TypeId == questions[i].TypeId).FirstOrDefault().TypeCode; bool addToList = true; int tempNumber = 0; switch (questionTypeCode) { case "essay": surveyUserQuestionOption.CustomAnswer = requestViewModel.text; break; case "radiobuttons": surveyUserQuestionOption.SurveyQuestionOptionId = requestViewModel.number.ToString(); break; case "imageradiobuttons": surveyUserQuestionOption.SurveyQuestionOptionId = requestViewModel.number.ToString(); break; case "multiple": foreach (var item in requestViewModel.selected) { SurveyUserQuestionOptions tempSurveyUserQuestionOption = new SurveyUserQuestionOptions(); tempSurveyUserQuestionOption.SurveyUserId = surveyUsers.SurveyUserId; tempSurveyUserQuestionOption.SurveyQuestionId = questions[i].SurveyQuestionId; tempSurveyUserQuestionOption.InsertedDatetime = DateTime.UtcNow; tempSurveyUserQuestionOption.SurveyQuestionOptionId = item; lstSurveyUserQuestionOptions.Add(tempSurveyUserQuestionOption); } addToList = false; break; case "imagemultiple": foreach (var item in requestViewModel.selected) { SurveyUserQuestionOptions tempSurveyUserQuestionOption = new SurveyUserQuestionOptions(); tempSurveyUserQuestionOption.SurveyUserId = surveyUsers.SurveyUserId; tempSurveyUserQuestionOption.SurveyQuestionId = questions[i].SurveyQuestionId; tempSurveyUserQuestionOption.InsertedDatetime = DateTime.UtcNow; tempSurveyUserQuestionOption.SurveyQuestionOptionId = item; lstSurveyUserQuestionOptions.Add(tempSurveyUserQuestionOption); } addToList = false; break; case "slider": surveyUserQuestionOption.SurveyQuestionOptionId = requestViewModel.number.ToString(); break; case "rangeslider": int j = 0; foreach (var item in requestViewModel.selected) { SurveyUserQuestionOptions tempSurveyUserQuestionOption = new SurveyUserQuestionOptions(); tempSurveyUserQuestionOption.SurveyUserId = surveyUsers.SurveyUserId; tempSurveyUserQuestionOption.SurveyQuestionId = questions[i].SurveyQuestionId; tempSurveyUserQuestionOption.InsertedDatetime = DateTime.UtcNow; tempSurveyUserQuestionOption.SurveyQuestionOptionId = item; tempSurveyUserQuestionOption.CustomAnswer = j == 0 ? "min" : "max"; lstSurveyUserQuestionOptions.Add(tempSurveyUserQuestionOption); j++; } addToList = false; break; case "starrating": surveyUserQuestionOption.SurveyQuestionOptionId = requestViewModel.number.ToString(); break; case "multiplerating": foreach (var item in requestViewModel.selected) { SurveyUserQuestionOptions tempSurveyUserQuestionOption = new SurveyUserQuestionOptions(); tempSurveyUserQuestionOption.SurveyUserId = surveyUsers.SurveyUserId; tempSurveyUserQuestionOption.SurveyQuestionId = questions[i].SurveyQuestionId; tempSurveyUserQuestionOption.InsertedDatetime = DateTime.UtcNow; tempSurveyUserQuestionOption.SurveyQuestionOptionId = surveyQuestionOptions[tempNumber].SurveyQuestionOptionId.ToString(); tempSurveyUserQuestionOption.CustomAnswer = item; lstSurveyUserQuestionOptions.Add(tempSurveyUserQuestionOption); tempNumber++; } addToList = false; break; case "customrating": var surveyQuestionOptionsValues = surveyQuestionOptions.Where(x => x.OptionKey.StartsWith("value")).OrderBy(x => x.OptionKey).ToList(); foreach (var item in requestViewModel.selected) { SurveyUserQuestionOptions tempSurveyUserQuestionOption = new SurveyUserQuestionOptions(); tempSurveyUserQuestionOption.SurveyUserId = surveyUsers.SurveyUserId; tempSurveyUserQuestionOption.SurveyQuestionId = questions[i].SurveyQuestionId; tempSurveyUserQuestionOption.InsertedDatetime = DateTime.UtcNow; tempSurveyUserQuestionOption.SurveyQuestionOptionId = surveyQuestionOptionsValues[tempNumber].SurveyQuestionOptionId.ToString(); tempSurveyUserQuestionOption.CustomAnswer = item; lstSurveyUserQuestionOptions.Add(tempSurveyUserQuestionOption); tempNumber++; } addToList = false; break; default: surveyUserQuestionOption.CustomAnswer = requestViewModel.text; break; } if (addToList) { lstSurveyUserQuestionOptions.Add(surveyUserQuestionOption); } } _dBContext.SurveyUserQuestionOptions.AddRange(lstSurveyUserQuestionOptions); surveyUsers.CompletedDatetime = DateTime.UtcNow; _dBContext.Update(surveyUsers); _dBContext.SaveChanges(); return(Ok()); }