Beispiel #1
0
        public async Task <bool> DoSaveProduct(ProductDto productDto, IFormFile file)
        {
            var product = _mapper.Map(productDto, new Product());

            product.CreatedAt       = DateTime.Now;
            product.Activated       = true;
            product.CategoryProduct = await _categoryProductRepository.GetById(productDto.CategoryProductId);

            product.Producer = await _producerRepository.GetById(productDto.ProducerId);

            if (file != null)
            {
                var uploadFile = await FileManipulator.Uploadfile(file, Path.Combine(_env.WebRootPath, $"Content/Products"), new List <string> {
                    "JPG", "PNG", "JPEG"
                });

                if (uploadFile.uploaded)
                {
                    product.Photo = uploadFile.fileName;
                }
            }

            _productRepository.Save(product);

            return(await _unitOfWork.CommitAsync());
        }
 public async Task<CategoryProduct> GetById(int id)
 {
     return await _categoryproductRepository.GetById(id);
 }