public async Task <IActionResult> Update(long id, [FromBody] QuizFormModel model) { if (!await Quizzes.CheckIfQuizExists(id)) { return(NotFound()); } await Quizzes.Update(id, model); return(Ok()); }
public async Task <long> Add(QuizFormModel model) { var entity = Mapper.Map <Quiz>(model); await Unit.Quizzes.Add(entity); await Unit.Complete(); await AddQuestions(entity.Id, model.Questions); await Unit.Complete(); return(entity.Id); }
public async Task Update(long id, QuizFormModel model) { var entity = await Unit.Quizzes.Get(id); Mapper.Map(model, entity); var(questionsToAdd, questionsToUpdate, questionsToDelete) = await SortQuestionsToUpdate(id, model.Questions); await AddQuestions(id, questionsToAdd); await UpdateQuestions(id, questionsToUpdate); DeleteQuestions(questionsToDelete); await Unit.Complete(); }
public async Task <IActionResult> Add([FromBody] QuizFormModel model) { return(Ok(await Quizzes.Add(model))); }