Beispiel #1
0
        public ActionResult DeleteQuestion(int?id)
        {
            TestQuestionService.EnableTracking();
            var question = TestQuestionService.GetByPK(id.Value);

            EditTestPermission(question.TestId);
            TestQuestionService.DeleteAndSubmit(question);
            return(Json("ok"));
        }
Beispiel #2
0
        public ActionResult EditQuestion(int testId, int?id)
        {
            EditTestPermission(testId);
            var model = new TestQuestion();

            TestQuestionService.LoadWith(x => x.TestModule);
            AjaxGridVM answersModel = null;

            if (id.HasValue)
            {
                model        = TestQuestionService.GetByPK(id.Value);
                answersModel = new AjaxGridVM {
                    GetListUrl = Url.Action <TestEditController>(c => c.GetAnswers(id.Value, null)),
                    EditUrl    = Url.Action <TestEditController>(c => c.EditAnswer(id.Value, null)),
                    DeleteUrl  = Url.Action <TestEditController>(c => c.DeleteAnswer(null)),
                    Caption    = "Ответы"
                };
                AddColumns <TestAnswer>(answersModel, x => x.Description);
                switch (model.Type)
                {
                case TestQuestionType.OneAnswer:
                case TestQuestionType.ManyAnswers:
                    AddColumns <TestAnswer>(answersModel, x => x.IsRight);
                    break;

                case TestQuestionType.Comparison:
                    AddColumns <TestAnswer>(answersModel, x => x.ComparableId);
                    break;

                case TestQuestionType.Sort:
                    AddColumns <TestAnswer>(answersModel, x => x.Sort);
                    break;

                default:
                    throw new Exception("TestQuestionType out of range");
                }
            }
            else
            {
                model.TestId = testId;
            }
            return(BaseView(
                       new PagePart(new QuestionEditView().Init(model, Url)),
                       answersModel.IfNotNull(x => new PagePart(PartialViewNames.AjaxList, x))));
        }
Beispiel #3
0
        public ActionResult EditQuestion(TestQuestion model)
        {
            EditTestPermission(model.TestId);
            if (!LinqToSqlValidator.Validate(ModelState, model))
            {
                return(ErrorJson());
            }
            TestQuestionService.EnableTracking();
            if (model.Id == 0)
            {
                TestQuestionService.InsertAndSubmit(model);
                return(UrlJson(Url.TestEdit().Urls.EditQuestion(model.TestId, model.Id)));
            }
            var oldModel = TestQuestionService.GetByPK(model.Id);

            oldModel.Update(model, x => x.Description, x => x.ModuleId);
            TestQuestionService.SubmitChanges();
            return(Json("ok"));
        }
Beispiel #4
0
        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))));
        }
Beispiel #5
0
        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));
        }