public async Task GetAllPerPageAsyncShouldReturnCorrectModelCollectionIfCreatorIdIsPassed()
        {
            var creatorId = Guid.NewGuid().ToString();

            await this.CreateQuizAsync("First quiz");

            var secondQuizId = await this.CreateQuizAsync("Second quiz", creatorId);

            var secondModel = new QuizListViewModel()
            {
                Id             = secondQuizId,
                Name           = "Second quiz",
                QuestionsCount = 0,
                Color          = ModelCostants.ColorEnded,
            };

            var resultModelCollection = await this.Service.GetAllPerPageAsync <QuizListViewModel>(1, 2, creatorId);

            Assert.Single(resultModelCollection);
            Assert.IsAssignableFrom <IList <QuizListViewModel> >(resultModelCollection);

            Assert.Equal(secondModel.Id, resultModelCollection.First().Id);
            Assert.Equal(secondModel.Name, resultModelCollection.First().Name);
            Assert.Equal(secondModel.QuestionsCount, resultModelCollection.First().QuestionsCount);
            Assert.Equal(secondModel.Color, resultModelCollection.First().Color);
        }
        public async Task GetPerPageByStudentIdFilteredByStatusAsyncShouldSkipCorrectly()
        {
            var firstQuizId = await this.CreateQuizAsync("First quiz");

            await this.AssignEventToQuizAsync(firstQuizId, Guid.NewGuid().ToString());

            await this.CreateQuizAsync("Second quiz");

            var firstModel = new QuizListViewModel()
            {
                Id             = firstQuizId,
                Name           = "First quiz",
                QuestionsCount = 0,
                Color          = ModelCostants.ColorActive,
            };

            var resultModelCollection = await this.Service.GetAllPerPageAsync <QuizListViewModel>(2, 1);

            Assert.Single(resultModelCollection);
            Assert.IsAssignableFrom <IList <QuizListViewModel> >(resultModelCollection);

            Assert.Equal(firstModel.Id, resultModelCollection.First().Id);
            Assert.Equal(firstModel.Name, resultModelCollection.First().Name);
            Assert.Equal(firstModel.QuestionsCount, resultModelCollection.First().QuestionsCount);
            Assert.Equal(firstModel.Color, resultModelCollection.First().Color);
        }
        public ViewResult MyQuizes(int p = 1)
        {
            QuizListViewModel model = GetMyQuizesModel(p);

            x++;
            return(View(model));
        }
        public ViewResult Favourite(int p = 1)
        {
            var quizesCollection    = quizService.GetUserFavouriteQuizes(userId);
            QuizListViewModel model = CreateQuizViewModelWithPagination(p, quizesCollection);

            return(View(model));
        }
        private QuizListViewModel GetMyQuizesModel(int p)
        {
            var myQuizesCollection  = quizService.GetAllUserQuizes(userId);
            QuizListViewModel model = CreateQuizViewModelWithPagination(p, myQuizesCollection);

            x++;
            return(model);
        }
Exemple #6
0
        public ActionResult DeleteQuiz(QuizListViewModel info)
        {
            var quiz = _context.TQuizz.Find(info.QuizId);

            quiz.Active = false;
            _context.SaveChanges();
            return(RedirectToAction("ListQuizes"));
        }
        /// <summary>
        /// Full version of action will require passing quiz data, to which user is assigned
        /// </summary>
        /// <returns></returns>
        public ViewResult Assigned(int p = 1)
        {
            // This is a placeholder code, all of it will be replaced
            //TO DO
            /*var myQuizesCollection = quizService.GetAllUserAssignedQuizes(userId);*/
            var myAssignedQuizesCollection = quizService.GetUserAssignedToPrivateQuizes(userId);
            QuizListViewModel model        = CreateQuizViewModelWithPagination(p, myAssignedQuizesCollection);

            return(View(model));
        }
        private QuizListViewModel CreateQuizViewModelWithPagination(int p, IEnumerable <QuizDTO> quizesCollection)
        {
            QuizListViewModel model = new QuizListViewModel
            {
                Quizes = quizesCollection.
                         OrderBy(q => q.Title).
                         Skip((p - 1) * PageSize).
                         Take(PageSize),
                PagingInfo = pagingInfoService.GetMetaData(quizesCollection.Count(),
                                                           p, PageSize)
            };

            return(model);
        }
Exemple #9
0
        public ActionResult QuizListView(QuizListViewModel quiz)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in quiz.QuizList)
                {
                    db.Entry(item).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View(quiz));
        }
Exemple #10
0
        public async Task <QuizListViewModel> GetAllQuizes()
        {
            try
            {
                var model = new QuizListViewModel()
                {
                    Quizes = _mapper.Map <List <QuizViewModel> >(_context.Quiz)
                };

                return(model);
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
Exemple #11
0
        public async Task <IActionResult> List(int botId)
        {
            if (botId > 0)
            {
                var quizzes = await _context.Quizzes.Where(x => x.BotId == botId).ToListAsync();

                var model = new QuizListViewModel
                {
                    BotId   = botId,
                    Quizzes = quizzes
                };

                return(View(model));
            }
            return(Redirect(Url.Action("List", "Bot")));
        }
Exemple #12
0
        public IActionResult _Quiz()
        {
            QuizListViewModel quizViewModel = null;

            try
            {
                quizViewModel = new QuizListViewModel()
                {
                    QuizViews = quizService.GetAllQuizzes()
                };
            }
            catch (Exception e)
            {
            }

            return(PartialView("_Quiz", quizViewModel));
        }
Exemple #13
0
        public ActionResult Index(string search, int?page, int?items)
        {
            QuizListViewModel model = new QuizListViewModel();

            model.PageInfo = new PageInfo()
            {
                PageTitle       = "Quizzes",
                PageDescription = "List of Quizzes."
            };

            model.searchTerm = search;
            model.pageNo     = page ?? 1;
            model.pageSize   = items ?? 10;

            if (string.IsNullOrEmpty(model.searchTerm))
            {
                model.Quizzes = db.Quizzes
                                .Where(q => q.IsActive)
                                .OrderByDescending(x => x.ModifiedOn)
                                .Skip((model.pageNo - 1) * model.pageSize)
                                .Take(model.pageSize)
                                .ToList();

                model.TotalCount = db.Quizzes.Where(q => q.IsActive).Count();
            }
            else
            {
                model.Quizzes = db.Quizzes
                                .Where(q => q.IsActive)
                                .Where(x => x.Name.ToLower().StartsWith(model.searchTerm))
                                .OrderByDescending(x => x.ModifiedOn)
                                .Skip((model.pageNo - 1) * model.pageSize)
                                .Take(model.pageSize)
                                .ToList();

                model.TotalCount = db.Quizzes
                                   .Where(q => q.IsActive)
                                   .Where(x => x.Name.ToLower().StartsWith(model.searchTerm))
                                   .Count();
            }

            model.Pager = new Pager(model.TotalCount, model.pageNo, model.pageSize);

            return(View(model));
        }
        public ActionResult Index(string Category = null)
        {
            List <Models.Quiz>  quizs;
            List <QuizCategory> quizCategories = db.QuizCategories.ToList();

            if (Category == null)
            {
                quizs = db.Quizs.ToList();
            }
            else
            {
                quizs = db.Quizs.Where(q => q.Category == Category).ToList();
            }
            QuizListViewModel quizListView = new QuizListViewModel();

            quizListView.Quizs          = quizs;
            quizListView.QuizCategories = quizCategories;
            return(View(quizListView));
        }
Exemple #15
0
        // GET
        public ActionResult QuizListView()
        {
            QuizListViewModel quizList = new QuizListViewModel();

            quizList.QuizList = new List <Quiz>();
            var quiz = db.Quiz.ToList();

            for (int i = 0; i < quiz.Count; i++)
            {
                quizList.QuizList.Add(new Quiz()
                {
                    Id       = quiz[i].Id,
                    Name     = quiz[i].Name,
                    Archived = quiz[i].Archived
                });
            }

            return(View(quizList));
        }
        public async Task GetAllPerPageAsyncShouldReturnCorrectModelCollection()
        {
            var firstQuizId = await this.CreateQuizAsync("First quiz");

            await this.AssignEventToQuizAsync(firstQuizId, Guid.NewGuid().ToString());

            var secondQuizId = await this.CreateQuizAsync("Second quiz");

            var firstModel = new QuizListViewModel()
            {
                Id             = firstQuizId,
                Name           = "First quiz",
                QuestionsCount = 0,
                Color          = ModelCostants.ColorActive,
            };

            var secondModel = new QuizListViewModel()
            {
                Id             = secondQuizId,
                Name           = "Second quiz",
                QuestionsCount = 0,
                Color          = ModelCostants.ColorEnded,
            };

            var resultModelCollection = await this.Service.GetAllPerPageAsync <QuizListViewModel>(1, 2);

            Assert.Equal(2, resultModelCollection.Count());
            Assert.IsAssignableFrom <IList <QuizListViewModel> >(resultModelCollection);

            Assert.Equal(firstModel.Id, resultModelCollection.Last().Id);
            Assert.Equal(firstModel.Name, resultModelCollection.Last().Name);
            Assert.Equal(firstModel.QuestionsCount, resultModelCollection.Last().QuestionsCount);
            Assert.Equal(firstModel.Color, resultModelCollection.Last().Color);

            Assert.Equal(secondModel.Id, resultModelCollection.First().Id);
            Assert.Equal(secondModel.Name, resultModelCollection.First().Name);
            Assert.Equal(secondModel.QuestionsCount, resultModelCollection.First().QuestionsCount);
            Assert.Equal(secondModel.Color, resultModelCollection.First().Color);
        }
Exemple #17
0
        public ActionResult CandidateRegistraion(string search, int?page, int?items)
        {
            QuizListViewModel model = new QuizListViewModel();

            model.PageInfo = new PageInfo()
            {
                PageTitle       = "Quizzes",
                PageDescription = "List of Quizzes."
            };

            model.searchTerm = search;
            model.pageNo     = page ?? 1;
            model.pageSize   = items ?? 10;

            var quizzesSearch = QuizzesService.Instance.GetQuizzes(model.searchTerm, model.pageNo, model.pageSize);

            model.Quizzes    = quizzesSearch.Quizzes;
            model.TotalCount = quizzesSearch.TotalCount;

            model.Pager = new Pager(model.TotalCount, model.pageNo, model.pageSize);

            return(PartialView("_CandidateRegistraion", model));
        }
Exemple #18
0
        // GET: Quiz
        public ActionResult Index(string search, int?page, int?items)
        {
            QuizListViewModel model = new QuizListViewModel();

            model.PageInfo = new PageInfo()
            {
                PageTitle       = "Quizzes",
                PageDescription = "List of Quizzes."
            };

            model.searchTerm = search;
            model.pageNo     = page ?? 1;
            model.pageSize   = items ?? 10;

            var quizzesSearch = UserHasRights() ? QuizzesService.Instance.GetQuizzesForAdmin(model.searchTerm, model.pageNo, model.pageSize) : QuizzesService.Instance.GetUserQuizzes(User.Identity.GetUserId(), model.searchTerm, model.pageNo, model.pageSize);

            model.Quizzes    = quizzesSearch.Quizzes;
            model.TotalCount = quizzesSearch.TotalCount;

            model.Pager = new Pager(model.TotalCount, model.pageNo, model.pageSize);

            return(View(model));
        }
Exemple #19
0
        public ActionResult DeleteQuiz(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var infoQuiz = _context.TQuizz.Find(id);

            if (infoQuiz == null)
            {
                return(HttpNotFound());
            }

            var q = new QuizListViewModel
            {
                QuizId   = infoQuiz.QuizId,
                QuizName = infoQuiz.QuizName,
                QuizCode = infoQuiz.QuizCode,
                Active   = infoQuiz.Active
            };

            return(View(q));
        }
        public IActionResult Index(int p = 1)
        {
            QuizListViewModel model = GetMyQuizesModel(p);

            return(View("MyQuizes", model));
        }