public async Task <ProductDto> Handle(FindProductByCodeQuery request, CancellationToken cancellationToken)
        {
            var result = await productRepository.FindOne(request.ProductCode);

            return(result != null ? new ProductDto
            {
                Code = result.Code,
                Name = result.Name,
                Description = result.Description,
                Image = result.Image,
                MaxNumberOfInsured = result.MaxNumberOfInsured,
                Questions = result.Questions != null?ProductMapper.ToQuestionDtoList(result.Questions) : null,
                                Covers = result.Covers != null?ProductMapper.ToCoverDtoList(result.Covers) : null
            } : null);
        }
示例#2
0
        public async Task <IEnumerable <ProductDto> > Handle(FindAllProductsQuery request, CancellationToken cancellationToken)
        {
            var result = await productRepository.FindAllActive();

            return(result.Select(p => new ProductDto
            {
                Code = p.Code,
                Name = p.Name,
                Description = p.Description,
                Image = p.Image,
                MaxNumberOfInsured = p.MaxNumberOfInsured,
                Questions = p.Questions != null ? ProductMapper.ToQuestionDtoList(p.Questions) : null,
                Covers = p.Covers.Any() ? ProductMapper.ToCoverDtoList(p.Covers) : null
            }).ToList());
        }