Esempio n. 1
0
        public async Task <ProductDetailsResponse> Handle(GetProductQuery query)
        {
            if (query.ProductId != default(int))
            {
                DomainCore.Models.Product product = await _readOnlyProductRepository.GetProductAsync(query.ProductId);

                if (product != null)
                {
                    return(CreateProductResponse(product));
                }

                throw new NotFoundException(new Fault {
                    Reason = "NotFoundResource", Message = $"Product with id:{query.ProductId} not found."
                });
            }

            if (!string.IsNullOrEmpty(query.Code))
            {
                DomainCore.Models.Product product = await _readOnlyProductRepository.GetProductByCodeAsync(query.Code);

                if (product != null)
                {
                    return(CreateProductResponse(product));
                }

                throw new NotFoundException(new Fault {
                    Reason = "NotFoundResource", Message = $"Product with code:{query.ProductId} not found."
                });
            }

            throw new ValidationException(new Fault {
                Reason = "NotValid", Message = $"Request is not valid."
            });
        }
Esempio n. 2
0
        private ProductDetailsResponse CreateProductResponse(DomainCore.Models.Product product)
        {
            ViewProduct result = _mapper.Map <ViewProduct>(product);

            if (product.Image != null)
            {
                result.Photo = _mapper.Map <ImageFile>(product.Image);
            }
            return(new ProductDetailsResponse {
                Product = result
            });
        }
Esempio n. 3
0
 public async Task DeleteAsync(DomainCore.Models.Product product)
 {
     _productContext.Remove(product);
     await _productContext.SaveChangesAsync();
 }
Esempio n. 4
0
        public async Task SaveProductAsync(DomainCore.Models.Product product)
        {
            await _productContext.AddAsync(product);

            await _productContext.SaveChangesAsync();
        }