public async Task <ProductStatusResponse> SaveAsync(ProductSaveRequest request, Product product)
        {
            try {
                if ((await categoryRepository.FindByIdAsync(request.CategoryId)) == null)
                {
                    return(new ProductStatusResponse("Invald Category Id."));
                }

                for (int i = 0; i < request.Images.Count; i++)
                {
                    product.Images.Add(new ImagePath {
                        Filename = await fileService.StoreImage(config.GetSection("ProductsImages").Value, request.Images[i])
                    });
                }

                Product newAddedProduct = await productsRepository.AddAsync(product);

                return(new ProductStatusResponse(newAddedProduct));
            } catch (Exception e) {
                return(new ProductStatusResponse(e.Message));
            }
        }
Esempio n. 2
0
 public async Task <Category> FindByIdAsync(Guid id)
 {
     return(await categoryRepository.FindByIdAsync(id));
 }