public async Task <IActionResult> Put(Guid id, [FromForm] Quiz_DTO quiz_DTO) { var confirmedModel = new Quiz(); //te returnen DTO try { //1. Validatie if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //2.Entity (model) via de mapper ophalen var model = new Quiz() { }; quiz_DTO.Id = id; QuizMapper.ConvertQuizTo_Entity(quiz_DTO, ref model); //3. Entity (model) toevoegen via het repo confirmedModel = await quizRepo.UpdateQuiz(model); //4. Een bevestiging v foutieve actie teruggeven if (confirmedModel == null) { return(NotFound(model.Subject + " did not get saved. ")); } } catch (Exception exc) { return(BadRequest("Update quiz failed")); } //5. DTO terugsturen als bevestiging return(CreatedAtAction("Get", new { id = confirmedModel.Id }, quiz_DTO)); }
public async Task <ActionResult> EditQuiz(IFormCollection collection, Quiz quiz) { try { await _quizRepo.UpdateQuiz(quiz); return(RedirectToAction("MyQuizzes")); } catch { return(View()); } }
public async Task <IActionResult> EditQuiz(Guid id, IFormCollection collection, Quiz quiz) { try { // TODO: Add update logic here var result = await quizRepo.UpdateQuiz(quiz); if (result == null) { return(RedirectToAction(nameof(Quizzes), new { exc = "Update quiz failed..." })); } return(RedirectToAction(nameof(Quizzes))); } catch (Exception exc) { return(RedirectToAction(nameof(Quizzes), new { exc = exc.Message })); } }