public async Task <DefaultResult> Handle(AddQuestionsAndAnswerProductCommand command,
                                                 CancellationToken cancellationToken)
        {
            var result = new DefaultResult();

            var product = await _productRepository.FindAsync(x => x.Id == command.Id);

            if (product == null)
            {
                Notifications.Handle("Não foi possivel encontrar Produto");
                return(null);
            }

            var questionsAnswers = new List <ProductQA>();

            foreach (var questionAnswer in command.QuestionsAndAnswers)
            {
                questionsAnswers.Add(ProductQA.New(command.Id, questionAnswer));
            }

            await _productQuestionAnswerRepository.AddRangeAsync(questionsAnswers);

            if (!await CommitAsync())
            {
                return(result);
            }

            return(result);
        }
예제 #2
0
 public static ProductQAVm ToVm(this ProductQA productQA)
 {
     return(new ProductQAVm
     {
         Id = productQA.Id,
         QuestionAndAnswer = productQA.QuestionAndAnswer
     });
 }