public ActionResult DeleteAnswer(int?id) { TestAnswerService.EnableTracking(); var answer = TestAnswerService.GetByPK(id.Value); EditAnswerPermission(id.Value); TestAnswerService.DeleteAndSubmit(answer); return(OkJson()); }
public ActionResult GetAnswersAuto(int questionId, string term) { term = term ?? string.Empty; var list = TestAnswerService.GetAll(x => x.QuestionId == questionId && x.ComparableId == null && x.Answer == null && x.Description.Contains(term)) .Select(x => Select2VM.Item(x.Id, x.Description)); return(Json(new Select2VM(list), JsonRequestBehavior.AllowGet)); }
public ActionResult EditAnswer(TestAnswer model) { EditQuestionPermission(model.QuestionId); if (!LinqToSqlValidator.Validate(ModelState, model)) { return(ErrorJson()); } TestAnswerService.EnableTracking(); if (model.Id == 0) { TestAnswerService.InsertAndSubmit(model); return(UrlJson(Url.TestEdit().Urls.EditAnswer(model.QuestionId, model.Id))); } var oldModel = TestAnswerService.GetByPK(model.Id); oldModel.Update(model, x => x.Description, x => x.IsRight, x => x.ComparableId, x => x.Sort); TestAnswerService.SubmitChanges(); return(OkJson()); }
public ActionResult EditAnswer(int questionId, int?id) { var model = new TestAnswer(); EditQuestionPermission(questionId); if (id.HasValue) { TestAnswerService.LoadWith(x => x.TestQuestion); model = TestAnswerService.GetByPK(id.Value); if (model.ComparableId.HasValue) { model.ComparableAnswer = TestAnswerService.GetByPK(model.ComparableId.Value); } } else { model.QuestionId = questionId; model.TestQuestion = TestQuestionService.GetByPK(questionId); } return(BaseView( new PagePart(new AnswerEditView().Init(model, Url)))); }
public ActionResult GetAnswers(int questionId, AjaxGridRequest model) { var question = TestQuestionService.GetByPK(questionId); Expression <Func <TestAnswer, object> > selector = null; PagedList <object> list; switch (question.Type) { case TestQuestionType.OneAnswer: case TestQuestionType.ManyAnswers: var l1 = TestAnswerService.GetAll(x => x.QuestionId == questionId) .Select(x => new { x.Id, x.Description, IsRight = x.IsRight.GetValueOrDefault() ? "Да" : "Нет" }).ToPagedList(model.Page - 1, model.Rows); list = l1.Select(x => new { x.Id, Description = StringUtils.ReplaceGLT(x.Description), x.IsRight }).Cast <object>().ToPagedList(l1); break; case TestQuestionType.Comparison: var l2 = TestAnswerService.GetAll(x => x.QuestionId == questionId) .Select(x => new { x.Id, x.Description, ComparableId = x.ComparableAnswer.Description }).ToPagedList(model.Page - 1, model.Rows); list = l2.Select(x => new { x.Id, Description = StringUtils.ReplaceGLT(x.Description), x.ComparableId }).Cast <object>().ToPagedList(l2); break; case TestQuestionType.Sort: var l3 = TestAnswerService.GetAll(x => x.QuestionId == questionId) .Select(x => new { x.Id, x.Description, x.Sort }).ToPagedList(model.Page - 1, model.Rows); list = l3.Select(x => new { x.Id, Description = StringUtils.ReplaceGLT(x.Description), x.Sort }).Cast <object>().ToPagedList(l3); break; default: throw new Exception("TestQuestionType out of range"); } return(Json(new GridData(list.PageCount, model.Page, list.Count, list), JsonRequestBehavior.AllowGet)); }
public void EditAnswerPermission(int answerId) { EditQuestionPermission(TestAnswerService.GetValues(answerId, x => x.QuestionId)); }