public async Task <ActionResult> CatchRating(IFormCollection lijst)
        {
            Guid quizid = Guid.Parse(lijst["QuizID"]);
            Quiz quiz   = await quizrepo.GetQuizForID(quizid);

            var rating = Convert.ToString(lijst["Rating"]);

            quiz.Rating = rating;
            // await quizrepo.Delete(quizid);
            await quizrepo.Update(quiz);

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <ActionResult <QuizClass> > PutQuiz([FromBody] QuizClass quiz, Guid?id)
        {
            if (id == null)
            {
                return(BadRequest("This enpoind requires a valid QuizId"));
            }
            quiz.QuizId = id ?? Guid.Empty;
            var confirmedModel = new QuizClass(); //te returnen

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (!await quizRepo.QuizExists(id ?? Guid.Empty))
                {
                    return(BadRequest($"{id} bestaat niet"));
                }
                confirmedModel = await quizRepo.Update(quiz);
            }
            catch (DbUpdateException)
            {
                if (await quizRepo.QuizExists(id ?? Guid.Empty))
                {
                    return(Conflict());
                }
                else
                {
                    return(BadRequest("Something went wrong, try again later"));
                }
            }
            return(Ok(confirmedModel));
        }
Esempio n. 3
0
        public async Task <ActionResult> EditAsync(Guid id, IFormCollection collection, Quiz quiz)
        {
            try
            {
                // TODO: Add update logic here
                if (id == null)
                {
                    return(BadRequest());
                }

                var result = await quizRepo.Update(quiz);

                if (result == null)
                {
                    return(Redirect("/Error/400"));
                }


                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Update actie mislukt." + ex.InnerException.Message);
                return(View(quiz));
            }
        }
Esempio n. 4
0
        public int Update(UpdateQuizRequestModel model)
        {
            var quiz = _quizRepo.GetById(model.Id);

            quiz.Name      = model.Name;
            quiz.Questions = _mapper.Map <List <Question> >(model.Questions);
            return(_quizRepo.Update(quiz));
        }
Esempio n. 5
0
        public async Task <ActionResult> EditQuizAsync(Guid Id, IFormCollection collection, AddQuiz_VM vm)
        {
            try
            {
                // TODO: Add update logic here
                if (Id == null)
                {
                    return(RedirectToAction("Quizzes"));
                }

                //default image
                if (vm.ImgUrl == null)
                {
                    vm.ImgUrl = "https://wallpaperaccess.com/full/2384075.jpg";
                }

                Quiz quiz = new Quiz()
                {
                    SubjectId   = vm.SubjectId,
                    Description = vm.Description,
                    Difficulty  = vm.Difficulty,
                    ImgUrl      = vm.ImgUrl,
                    QuizID      = vm.QuizID,
                    QuizName    = vm.QuizName
                };

                var result = await quizRepo.Update(quiz);

                if (result == null)
                {
                    return(Redirect("/Error/400"));
                }


                return(RedirectToAction(nameof(Quizzes)));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"update error. {ex.Message}");
                ModelState.AddModelError("", "Update actie mislukt." + ex.InnerException.Message);
                return(View(vm));
            }
        }
        public async Task <ActionResult> EditQuiz(Guid?id, IFormCollection collection, QuizClass quiz)
        {
            try
            {
                if (id == null)
                {
                    return(Redirect("/Error/400"));
                }
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                quiz.QuizId = id ?? Guid.Empty;
                QuizClass checkdouble = await quizRepo.GetQuizByNameAsync(quiz.Name);

                if (checkdouble != null && checkdouble.QuizId != id)
                {
                    ModelState.AddModelError("", "This name is already in use");
                    return(View());
                }
                //eerst controleren of er een aanpassing gebeurt is
                QuizClass original = await quizRepo.GetQuizByIdAsync(quiz.QuizId);

                if (original.Name == quiz.Name && original.Description == quiz.Description && original.Difficulty == quiz.Difficulty)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                if (await quizRepo.Update(quiz) == null)
                {
                    throw new Exception("Couldn't create the quiz");
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception exc)
            {
                Console.WriteLine("Create is giving an error: " + exc.Message);
                ModelState.AddModelError("", "Create actie is failed try again");
                return(View());
            }
        }