コード例 #1
0
        public async Task CreateQuestionAsync(ViewModel.QuestionInputModel question)
        {
            var questionToAdd = new Infrastructure.Database.Question
            {
                CategoryId = question.CategoryId,
                Content    = question.Content,
                Answer     = question.Answer
            };
            await _dbContext.Question.AddAsync(questionToAdd);

            await _dbContext.SaveChangesAsync();
        }
コード例 #2
0
        public async Task UpdateQuestionAsync(ViewModel.QuestionInputModel question)
        {
            var questionToUpdate = await _dbContext.Question.FindAsync(question.Id);

            if (questionToUpdate is null)
            {
                questionToUpdate = new Infrastructure.Database.Question();
                await _dbContext.Question.AddAsync(questionToUpdate);

                await _dbContext.SaveChangesAsync();
            }
            questionToUpdate.CategoryId = question.CategoryId;
            questionToUpdate.Content    = question.Content;
            questionToUpdate.Answer     = question.Answer;
            await _dbContext.SaveChangesAsync();
        }