Пример #1
0
        public ActionResult DeleteQuestion(int?id)
        {
            TestQuestionService.EnableTracking();
            var question = TestQuestionService.GetByPK(id.Value);

            EditTestPermission(question.TestId);
            TestQuestionService.DeleteAndSubmit(question);
            return(Json("ok"));
        }
Пример #2
0
        public ActionResult GetQuestions(int testId, AjaxGridRequest model)
        {
            var list = TestQuestionService.GetAll(x => x.TestId == testId)
                       .Select(x => new { x.Id, x.Description }).ToPagedList(model.Page - 1, model.Rows);

            list = list.Select(x => new { x.Id, Description = StringUtils.ReplaceGLT(x.Description) })
                   .ToPagedList(list);

            return(Json(new GridData(list.PageCount,
                                     model.Page,
                                     list.Count,
                                     list), JsonRequestBehavior.AllowGet));
        }
Пример #3
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))));
        }
Пример #4
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"));
        }
Пример #5
0
        public ActionResult UserTestAnswers(int userTestId)
        {
            UserTestService.LoadWith(x => x.Test);
            var userTest = UserTestService.GetByPK(userTestId);

            if (!userTest.ShowAnswers ||
                userTest.UserId != User.UserID)
            {
                return(null);
            }
            var qIds = UserTestAnswerService.GetAll(x => x.UserTestId == userTestId && !x.IsRight)
                       .Select(x => x.QuestionId).ToList();

            TestQuestionService.LoadWith(x => x.TestAnswers);
            var model = new UserTestAnswerVM {
                Questions = TestQuestionService.GetAll(x => qIds.Contains(x.Id)).ToList(),
                UserTest  = userTest
            };

            return(BaseViewWithModel(new UserTestAnswersView(), model));
        }
Пример #6
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))));
        }
Пример #7
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));
        }
Пример #8
0
        public void EditQuestionPermission(int questionId)
        {
            var testId = TestQuestionService.GetValues(questionId, x => x.TestId);

            EditTestPermission(testId);
        }
Пример #9
0
 private IQueryable <TestQuestion> GetQuestions(List <int> testIds)
 {
     TestQuestionService.LoadWith(x => x.TestAnswers);
     return(TestQuestionService.GetAll(
                x => testIds.Contains(x.TestId)));
 }