Example #1
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))));
        }
Example #2
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));
        }
Example #3
0
 private IQueryable <TestQuestion> GetQuestions(List <int> testIds)
 {
     TestQuestionService.LoadWith(x => x.TestAnswers);
     return(TestQuestionService.GetAll(
                x => testIds.Contains(x.TestId)));
 }