public async Task <IActionResult> AddQuizToUser([FromBody] QuizImDto newQuiz) { if (ModelState.IsValid) { return(BadRequest(ModelState)); } var quiz = _mapper.Map <Quiz>(newQuiz); var result = _userDAO.AddQuizToUser(newQuiz.UserId, quiz); return(Ok(result)); }
public async Task <IActionResult> CreateQuiz([FromBody] QuizImDto quizIm) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var quiz = _mapper.Map <Quiz>(quizIm); quiz.TimeCreated = DateTime.Now; quiz.TimeChanged = DateTime.Now; var result = _quizDao.AddQuiz(quiz); return(NoContent()); } catch (Exception e) { return(StatusCode(500, "Error in creating Qui: " + e.Message)); } }
public IActionResult UpdateQuiz([FromRoute] QuizImDto quizIm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var oldQuiz = _quizDao.GetQuiz(quizIm.Id); var updatedQuiz = _mapper.Map <Quiz>(quizIm); updatedQuiz.TimeCreated = oldQuiz.TimeCreated; updatedQuiz.TimeChanged = DateTime.Now; var quiz = _quizDao.UpdateQuiz(quizIm.Id, updatedQuiz); if (quiz == null) { return(NotFound()); } return(Ok(quiz)); }