// GET: BackOffice/QuizCategory
        public IActionResult Index(int id)
        {
            var quizCategory = _quizCategoryService.Get(x => x.GameId == id);

            if (quizCategory == null)
            {
                return(View(new QuizCategory {
                    GameId = id
                }));
            }
            return(View(quizCategory));
        }
        public Quiz ToQuizModel(EditQuizViewModel vm)
        {
            var model = _quizService.Get(vm.Quiz.QuizId);

            if (!String.IsNullOrEmpty(vm.NewCategory))
            {
                model.Category    = _quizCategoryService.InsertByName(vm.NewCategory);
                model.Category.Id = model.Category.Id;
            }
            else
            {
                model.Category    = _quizCategoryService.Get(vm.SelectedCategory);
                model.Category.Id = vm.SelectedCategory;
            }

            model.Summary     = vm.Quiz.Summary;
            model.Name        = vm.Quiz.Name;
            model.IsTimeable  = vm.Quiz.IsTimeable;
            model.Locked      = vm.Quiz.Locked;
            model.AllowPoints = vm.Quiz.AllowPoints;

            return(model);
        }
Esempio n. 3
0
        public static QuizzesViewModel ToQuizzesViewModel(this IQueryable <Quiz> quizzes,
                                                          IQuestionService questions,
                                                          IQuizService quizService,
                                                          IQuizCategoryService categories,
                                                          int?catId)
        {
            var vm = new QuizzesViewModel();

            vm.QuizCategories = categories.GetAll().ToQuizCategoriesViewModel(quizService.GetPublicQuizzes(), catId);

            vm.Filter = QuizFilter.Newest;


            vm.TopQuizzes = quizService.GetBy(QuizFilter.Rating, descending: true, count: 10).Select(x => new TopListItem()
            {
                Id   = x.Id,
                Name = x.Name
            }).ToList();

            vm.SelectedCategoryId = catId.HasValue ?  catId.Value:  -1;

            vm.SearchPlaceHolder = vm.SelectedCategoryId > -1
                ? "Search in " + categories.Get(vm.SelectedCategoryId).Name
                : "Search here";

            const int pageSize  = 10;
            var       quizCount = quizzes.Count();

            if (quizCount <= pageSize)
            {
                vm.PageCount = 1;
            }
            else
            {
                vm.PageCount = (int)Math.Ceiling((double)quizCount / pageSize);
            }

            vm.Quizzes = quizzes.Take(pageSize).ToQuizViewModels();



            return(vm);
        }
Esempio n. 4
0
        public static Quiz ToModel(this CreateQuizViewModel vm, IQuizCategoryService categories)
        {
            var model = new Quiz();

            if (!String.IsNullOrEmpty(vm.NewCategory))
            {
                model.Category = categories.InsertByName(vm.NewCategory);
            }
            else
            {
                model.Category = categories.Get(vm.SelectedCategory);
            }

            model.IsTimeable  = vm.Quiz.IsTimeable;
            model.Locked      = vm.Quiz.Locked;
            model.Summary     = vm.Quiz.Summary;
            model.Name        = vm.Quiz.Name;
            model.Created     = DateTime.Now;
            model.AllowPoints = vm.Quiz.AllowPoints;


            return(model);
        }
 public IHttpActionResult Get()
 {
     return(Ok(_quizCategoryService.Get()));
 }