示例#1
0
 public async Task <IActionResult> Create(IFormCollection collection, Quiz quiz)
 {
     try {
         if (ModelState.IsValid)
         {
             quizRepo.Create(quiz);
             await quizRepo.SaveChangesAsync();
         }
         return(RedirectToAction(nameof(Index)));
     } catch {
         return(View());
     }
 }
        public async Task <QuizGebruiker> SaveQuizGebruikerAsync(List <Guid> antwoorden, Guid id, string gebruikerId)
        {
            var quizGebruikerAntwoorden = new List <QuizGebruikerAntwoord>();

            foreach (var antwoord in antwoorden)
            {
                quizGebruikerAntwoorden.Add(new QuizGebruikerAntwoord()
                {
                    AntwoordId = antwoord
                });
            }

            var juisteAntwoordenVanQuiz = await antwoordRepo.GetJuisteAntwoord(id) as List <Antwoord>;

            var juisteAntwoorden = juisteAntwoordenVanQuiz.Where(a => antwoorden.Any(an => an == a.Id));
            var totaalScore      = juisteAntwoorden.Sum(a => a.Vraag.Score);
            var quizGebruiker    = new QuizGebruiker()
            {
                QuizId                  = id,
                GebruikerId             = gebruikerId,
                QuizGebruikerAntwoorden = quizGebruikerAntwoorden,
                StartDatum              = DateTime.Now,
                TotaalScore             = totaalScore
            };

            quizRepo.AddQuizToGebruiker(quizGebruiker);
            await quizRepo.SaveChangesAsync();

            return(quizGebruiker);
        }
示例#3
0
        public async Task <IActionResult> Post([FromBody] SaveQuizDTO saveQuizDTO)
        {
            try
            {
                var quiz = mapper.Map <Quiz>(saveQuizDTO);
                quizRepo.Add(quiz);
                await quizRepo.SaveChangesAsync();

                var quizDTO = mapper.Map <QuizDTO>(quiz);
                return(CreatedAtAction(nameof(GetById), new { id = quiz.Id }, quizDTO));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(BadRequest("Toevoegen mislukt"));
            }
        }
        public async Task <IActionResult> NieuweQuiz([Bind("Onderwerp, MoeilijkheidsgraadId, Beschrijving, Vragen")] Quiz quiz)
        {
            try
            {
                quizRepo.Add(quiz);
                await quizRepo.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(View("Error", new ErrorViewModel()
                {
                    RequestId = HttpContext.TraceIdentifier
                }));
            }
        }
示例#5
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());
            }
        }