public async Task <IActionResult> Post([FromForm] Quiz_DTO quiz_DTO) { var confirmedModel = new Quiz(); //te returnen DTO try { var obj = new Difficulty_DTO(); quiz_DTO.Difficulty = QuizMapper.ConvertDifficultyTo_DTO(await quizRepo.GetDifficultyForIdAsync(quiz_DTO.DifficultyId), ref obj); //1. Validatie if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //2.Entity (model) via de mapper ophalen var model = new Quiz() { }; QuizMapper.ConvertQuizTo_Entity(quiz_DTO, ref model); //3. Entity (model) toevoegen via het repo confirmedModel = await quizRepo.AddQuiz(model); //4. Een bevestiging v foutieve actie teruggeven if (confirmedModel == null) { return(NotFound(model.Subject + " did not get saved. ")); } } catch (Exception exc) { return(BadRequest("Add quiz failed")); } //5. DTO terugsturen als bevestiging return(CreatedAtAction("Get", new { id = confirmedModel.Id }, quiz_DTO)); }
public async Task <ActionResult <Quiz_DTO> > Get(Guid id) { var result = await quizRepo.GetQuizForIdAsync(id); if (result == null) { return(BadRequest("Quiz not found")); } var obj = new Quiz_DTO(); var model = QuizMapper.ConvertQuizTo_DTO(result, ref obj, quizRepo); return(Ok(model)); }
public async Task <ActionResult <List <Quiz_DTO> > > Get() { var model = await quizRepo.GetAllQuizzesAsync(); List <Quiz_DTO> model_DTO = new List <Quiz_DTO>(); foreach (Quiz quiz in model) { var result = new Quiz_DTO(); model_DTO.Add(QuizMapper.ConvertQuizTo_DTO(quiz, ref result, quizRepo)); } return(Ok(model_DTO)); }
public async Task <ActionResult <IEnumerable <Quiz_DTO> > > GetQuizzes() { var model = await quizRepo.GetAllQuizesAsync(); List <Quiz_DTO> model_DTO = new List <Quiz_DTO>(); foreach (Quiz qz in model) { Quiz_DTO result = new Quiz_DTO(); model_DTO.Add(Mapper.QuizTo_DTO(qz, ref result)); } return(Ok(model_DTO)); }
public async Task <ActionResult <IEnumerable <Quiz> > > GetQuizzes() { //1. enititeiten ophaln var model = await quizRepo.GetQuizzesAsync(); //2. Mapping naar DTO List <Quiz_DTO> dTOs = new List <Quiz_DTO>(); foreach (Quiz item in model) { var result = new Quiz_DTO(); dTOs.Add(Mapper.ConvertTo_DTOAsync(item, ref result, subjectRepo)); } return(Ok(dTOs)); }
public async Task <ActionResult <Quiz_DTO> > getQuizzesByName(string name) { if (string.IsNullOrEmpty(name)) { return(BadRequest("ongeldige naam")); } var quiz = await quizRepo.GetQuizByNameAsync(name); if (quiz == null) { return(NotFound("geen quiz gevonden")); } var quiz_DTO = new Quiz_DTO(); var quiz_DTOResult = Mapper.QuizTo_DTO(quiz, ref quiz_DTO); return(Ok(quiz_DTOResult)); }
public async Task <ActionResult <Quiz_DTO> > QuizById(string guid) { try { Quiz_DTO quiz_DTO = new Quiz_DTO(); Quiz quiz = await quizRepo.GetQuizQuestionsAnswersAsync(Guid.Parse(guid)); if (quiz == null) { return(NotFound()); } quiz_DTO = Mapper.ConvertTo_DTO(quiz, ref quiz_DTO); return(Ok(quiz_DTO)); } catch (Exception) { return(BadRequest("Wrong id")); throw; } }
public async Task <IActionResult> GetAllQuizzesAsync() { var returnMessage = ""; try { Quiz_DTO quiz_DTO = new Quiz_DTO(); var quizzes = await _quizRepository.GetAllQuizzesAsync(); List <Quiz_DTO> quiz_DTOs = new List <Quiz_DTO>(); foreach (var obj in quizzes) { quiz_DTO = QuizMapper.ConvertTo_DTO(obj, ref quiz_DTO); quiz_DTOs.Add(quiz_DTO); } return(Ok(quiz_DTOs)); } catch (Exception ex) { returnMessage = $"Foutief of ongeldig request: {ex.Message}"; ModelState.AddModelError("", returnMessage); } return(BadRequest(returnMessage)); }