// Create/Update/Delete methods public async Task <Question> CreateQuestionAsync(Question question, string userId) { var access = await _quizzesRepository.HaveWriteAccessToQuiz(userId, question.QuizId); if (!access) { return(null); } var creationTime = CurrentTime; question.CreationTime = creationTime; var questionVersion = new QuestionVersion { CreationTime = creationTime, Value = question.Value }; question.Versions.Add(questionVersion); question.FlatVersionProps(); await _questionsRepository.Create(question); return(await Context.SaveChangesAsync() > 0 ? question : null); }
public async Task <Question> UpdateQuestionAsync(long questionId, string value, string userId) { var question = await _questionsRepository .GetAll() .Where(a => a.Id == questionId) .Where(a => !a.IsDeleted) .SingleOrDefaultAsync(); if (question == null) { return(null); } var access = await _quizzesRepository.HaveWriteAccessToQuiz(userId, question.QuizId); if (!access) { return(null); } var questionVersion = new QuestionVersion { CreationTime = CurrentTime, Value = value }; question.Versions.Add(questionVersion); _questionsRepository.Update(question); var result = await Context.SaveChangesAsync() > 0; if (!result) { return(null); } question.FlatVersionProps(); return(question); }