public IActionResult UpdateFeedbackComment(int surveyId, SurveyFeedbackViewModel surveyFeedbackViewModel) { UserFeedbackResponse userFeedbackResponse = new UserFeedbackResponse(); string userId = Request.Headers[Constants.UserToken]; User user; _memoryCache.TryGetValue(userId, out user); if (user == null) { return(Unauthorized(Messages.UserNotFoundError)); } Survey survey = _dBContext.Survey.Where(x => x.CreatedBy == user.Userid && x.Surveyid == surveyId).FirstOrDefault(); if (survey == null) { return(BadRequest(Messages.SurveyNotFoundError)); } SurveyFeedback surveyFeedback = _dBContext.SurveyFeedback.Where(x => x.SurveyId == surveyId && x.SurveyFeedbackId == surveyFeedbackViewModel.FeedbackId).FirstOrDefault(); if (surveyFeedback == null) { return(BadRequest(Messages.FeedbackNotFound)); } surveyFeedback.ReviewComment = surveyFeedbackViewModel.Comment; surveyFeedback.ReviewCompleted = Convert.ToBoolean(surveyFeedbackViewModel.reviewComplete) ? 1 : 0; surveyFeedback.ReviewDatetime = DateTime.UtcNow; _dBContext.SurveyFeedback.Update(surveyFeedback); _dBContext.SaveChanges(); return(Ok(surveyFeedback)); }
public async Task <IActionResult> Survey(IFormCollection form) { var feedback = new SurveyFeedback { Id = Guid.NewGuid(), Url = form["currentUrl"], Rating = int.Parse(form["rating"]), UserId = Guid.NewGuid(), SubmittedAtUtc = DateTime.UtcNow }; await _dbContext.AddAsync(feedback); await _dbContext.SaveChangesAsync(); return(View()); }
public IActionResult BeginSurvey(string guid, string emailId) { Survey sur = _dBContext.Survey.Where(x => x.SurveyGuid == guid).FirstOrDefault(); emailId = Convert.ToString(emailId).ToLower(); if (sur == null) { return(BadRequest(Messages.SurveyNotFoundError)); } if (sur.Enddate < DateTime.UtcNow) { return(BadRequest(Messages.SurveyEnded)); } var surveyRestart = _dBContext.SurveyFeedback.Where(x => x.SurveyId == sur.Surveyid && x.SurveyUserEmail.ToLower().Equals(emailId) && x.CompletedDatetime == null).FirstOrDefault(); if (surveyRestart != null) { return(Ok(surveyRestart)); } bool checkSurveyEmail = _dBContext.SurveyFeedback.Any(x => x.SurveyId == sur.Surveyid && x.SurveyUserEmail.ToLower().Equals(emailId) && x.CompletedDatetime != null); if (checkSurveyEmail && Convert.ToBoolean(sur.Emailidrequired) && !string.IsNullOrEmpty(emailId)) { return(BadRequest(Messages.SurveyAlreadyTaken)); } SurveyFeedback surveyUser = new SurveyFeedback(); surveyUser.SurveyId = sur.Surveyid; surveyUser.SurveyUserEmail = emailId; surveyUser.SurveyUserGuid = Guid.NewGuid().ToString(); surveyUser.InsertedDatetime = DateTime.UtcNow; _dBContext.SurveyFeedback.Add(surveyUser); _dBContext.SaveChanges(); return(Ok(surveyUser)); }
public IActionResult GetSurveyUserFeedback(string surveyUserGuid) { SurveyUserFeedbackViewModel surveyUserFeedbackViewModel = new SurveyUserFeedbackViewModel(); _memoryCache.TryGetValue($"survey_feedback_{surveyUserGuid}", out surveyUserFeedbackViewModel); if (surveyUserFeedbackViewModel != null) { return(Ok(surveyUserFeedbackViewModel)); } SurveyViewModel surview = new SurveyViewModel(); string userId = Request.Headers[Constants.UserToken]; User user; _memoryCache.TryGetValue(userId, out user); if (user == null) { return(Unauthorized(Messages.UserNotFoundError)); } SurveyFeedback surveyFeedback = _dBContext.SurveyFeedback.Where(x => x.SurveyUserGuid == surveyUserGuid).FirstOrDefault(); if (surveyFeedback == null) { return(BadRequest(Messages.SurveyUserNotFoundError)); } Survey survey = _dBContext.Survey.Where(x => x.CreatedBy == user.Userid && x.Surveyid == surveyFeedback.SurveyId).FirstOrDefault(); if (survey == null) { return(BadRequest(Messages.SurveyNotFoundError)); } surview = _mapper.Map <SurveyViewModel>(survey); List <SurveyQuestions> surveyQuestions = _dBContext.SurveyQuestions.Where(x => x.StatusId != (int)EnumStatus.Deleted && x.SurveyId == survey.Surveyid).ToList(); List <QuestionType> questiontypes = _dBContext.QuestionType.ToList(); List <SurveyQuestionsViewModel> viewquestions = new List <SurveyQuestionsViewModel>(); foreach (var item in surveyQuestions) { SurveyQuestionsViewModel viewquestion = _mapper.Map <SurveyQuestionsViewModel>(item); List <SurveyFeedbackQuestionOptions> surveyFeedbackquestionoptions = new List <SurveyFeedbackQuestionOptions>(); List <string> selectedoptions = new List <string>(); string optiontypevalue = null; List <SurveyQuestionOptions> options = new List <SurveyQuestionOptions>(); options = _dBContext.SurveyQuestionOptions.Where(x => x.SurveyQuestionId == item.SurveyQuestionId).OrderBy(x => x.OptionKey).ToList(); surveyFeedbackquestionoptions = _dBContext.SurveyFeedbackQuestionOptions.Where(x => x.SurveyQuestionId == item.SurveyQuestionId && x.SurveyFeedbackId == surveyFeedback.SurveyFeedbackId).ToList(); if (questiontypes != null) { optiontypevalue = questiontypes.FirstOrDefault(x => x.TypeId == item.TypeId).TypeValue; } if (surveyFeedbackquestionoptions != null) { foreach (var itemq in surveyFeedbackquestionoptions) { string option = null; option = itemq.SurveyQuestionOptionId; selectedoptions.Add(option); } } Dictionary <string, object> dict = new Dictionary <string, object>(); foreach (var opt in options) { dict.Add(opt.OptionKey, opt.OptionValue); } viewquestion.Options = dict; viewquestion.ObjectOptions = options; viewquestion.questiontype = optiontypevalue; viewquestion.selectedValues = selectedoptions; viewquestions.Add(viewquestion); } surview.SurveyQuestions = viewquestions; surveyUserFeedbackViewModel = _mapper.Map <SurveyUserFeedbackViewModel>(surview); surveyUserFeedbackViewModel.SurveyFeedbacks = new List <SurveyFeedback>() { surveyFeedback }; _memoryCache.Set($"survey_feedback_{surveyUserGuid}", surveyUserFeedbackViewModel); return(Ok(surveyUserFeedbackViewModel)); }