public string ResetSurvey(int userId, int surveyId) { var survey = surveyRepository.GetByIdAsNoTracking(surveyId); //if user is unauthorized if (survey.UserId != userId) { return("401"); } var users = survey.Users; var author = userRepository.GetById(userId); //notification Notification notification = new Notification(author.FirstName + " " + author.LastName + " je resetovao anketu. Molimo Vas da je ponovo popunite.", DateTime.Now, Operation.RESET, NotificationType.PERSONAL); notification.SurveyId = survey.Id; notification.UserId = author.Id; List <UserNotification> notifications = new List <UserNotification>(); foreach (var u in users) { notifications.Add(new UserNotification(u.UserId, notification, false)); } // delete all answers userSurveyRepository.Delete(us => us.SurveyId == surveyId); userNotificationRepository.AddUserNotifications(notifications); var questionIdList = survey.Questions.Select(q => q.Id); repository.Delete(ua => questionIdList.Contains(ua.QuestionId)); return(""); }
public async Task <JsonResult> RemoveSurvey(string id) { var survey = surveyRepository.GetItems().Include(x => x.SurveyQuestion).ThenInclude(y => y.Options).ThenInclude(z => z.OptionsForAnswers).Include(x => x.SurveyQuestion).ThenInclude(a => a.UserAnswers).FirstOrDefault(x => x.Id == id); if (survey == null) { return(Json(null)); } foreach (var question in survey.SurveyQuestion.ToList()) { foreach (var option in question.Options.ToList()) { foreach (var optionsforanswer in option.OptionsForAnswers.ToList()) { await optionsForAnswerRepository.Delete(optionsforanswer); } await optionRepository.Delete(option); } foreach (var useranswers in question.UserAnswers.ToList()) { await userAnswerRepository.Delete(useranswers); } await surveyQuestionRepository.Delete(question); } await surveyRepository.Delete(survey); return(new JsonResult(id)); }
public async Task <bool> DeleteUserAnswer(int id) { UserAnswer answerToDelete = _userAnswerRepository.Get(id); if (answerToDelete == null) { return(false); } _userAnswerRepository.Delete(answerToDelete); _userAnswerRepository.Save(); return(true); }
void ISurveyService.DeleteUserAnswer(UserAnswer ua) { userAnswerRepository.Delete(ua); }