コード例 #1
0
        public async Task UpdateQuestionAsync(
            int questionId,
            QuestionRequestViewModel questionRequestViewModel)
        {
            var question = await this.questionsRepository.FirstAsync(x => x.Id == questionId);

            if (question.Author != this.currentUser)
            {
                throw new QaException(Messages.NoRightsToModifyQuestion);
            }

            question.QuestionText     = questionRequestViewModel.Question;
            question.Title            = questionRequestViewModel.Title;
            question.ShortDescription = questionRequestViewModel.ShortDescription;
            question.UpdatedAt        = DateTime.Now;

            await this.questionTagRepository.DeleteAllRelatedToAQuestion(questionId);

            await this.questionTagRepository.AddTagsToAQuestion(questionRequestViewModel.Tags, question.Id);

            this.questionsRepository.Update(question);

            await this.questionsRepository.UpdateSearchTableAsync(question.Id, question.Title);

            await this.uow.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <IActionResult> UpdateQuestion(int questionId, [FromBody] QuestionRequestViewModel qvm)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            await this.questionsService.UpdateQuestionAsync(questionId, qvm);

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> AddQuestion([FromBody] QuestionRequestViewModel qvm)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            var newQuestionId = await this.questionsService.AddQuestionAsync(qvm);

            return(Ok(newQuestionId));
        }
コード例 #4
0
        public async Task <BaseResponseViewModel> AddQuestionAsync(
            QuestionRequestViewModel questionRequestViewModel)
        {
            var question = new Question();

            question.QuestionText     = questionRequestViewModel.Question;
            question.Title            = questionRequestViewModel.Title;
            question.ShortDescription = questionRequestViewModel.ShortDescription;
            question.CreatedAt        = DateTime.Now;
            question.UpdatedAt        = DateTime.Now;
            question.Author           = this.currentUser;

            await this.questionsRepository.AddAsync(question);

            await this.questionTagRepository.AddTagsToAQuestion(questionRequestViewModel.Tags, question.Id);

            await this.uow.SaveChangesAsync();

            // Not required to catch this. Since this storing is only for search purpose now.
            // TODO Find a different way to generate and get the questionId or find it
            // before calling uow save changes. So that calling it two times can eb avoided.
            try
            {
                await this.questionsRepository.InsertIntoSearchTableAsync(question.Id, question.Title);

                await this.uow.SaveChangesAsync();
            }
            catch
            {
            }

            return(new BaseResponseViewModel()
            {
                Id = question.Id
            });
        }