Esempio n. 1
0
        public async Task <IActionResult> GetById(Guid id)
        {
            try
            {
                var quiz = await quizRepo.GetAsync(id);

                var quizDTO = mapper.Map <QuizDTO>(quiz);
                return(Ok(quizDTO));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(BadRequest());
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Play(int id)
        {
            try
            {
                var quizzes = await _quizRepo.GetAsync(id);

                return(View(quizzes));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = HttpContext.TraceIdentifier
                }));
            }
        }
        public async Task <IActionResult> Get(int id)
        {
            try
            {
                var quiz = await _quizrepo.GetAsync(id);

                if (quiz == null)
                {
                    return(NotFound());
                }

                var quizDTO = _mapper.Map <QuizDTO>(quiz);

                return(Ok(quizDTO));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }
Esempio n. 4
0
        public override async Task <IActionResult> Post(QuizSaveResource saveResource)
        {
            try {
                var entity = _mapper.Map <Quiz>(saveResource);

                _repo.Create(entity);
                await _repo.SaveChangesAsync();

                entity = await _repo.GetAsync(entity.Id);

                var resoure = _mapper.Map <QuizResource>(entity);

                return(CreatedAtAction(nameof(GetAll), resoure));
            } catch (Exception ex) {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Details(Guid id)
        {
            var userid   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var UserQuiz = new UserQuiz {
                UserId = userid,
                QuizId = id
            };

            userQuizRepo.Create(UserQuiz);
            await userQuizRepo.SaveChangesAsync();

            var Quiz = await quizRepo.GetAsync(id);

            QuizQuestionAnswerVM vm = new QuizQuestionAnswerVM(answerRepo, Quiz)
            {
                UserQuizID = UserQuiz.Id, TestVM = new TestVM {
                    UserQuizId = UserQuiz.Id
                }
            };

            return(View(vm));
        }
Esempio n. 6
0
        public async Task <ActionResult> Details(Guid id)
        {
            var quiz = await quizRepo.GetAsync(id);

            return(View(quiz));
        }