/// <inheritdoc/> public async Task <string> AddAsync(Stream imageStream) { var code = _barcodeService.ParseBarcodePhoto(imageStream); if (string.IsNullOrEmpty(code)) { throw new ValidationException("Barcode wasn't read from the uploaded photo"); } var barcodeDB = await _barcodeService.GetBarcodeFromDBAsync(code); if (barcodeDB != null && IsProductsInDB(p => p.Barcode != null && string.Equals(p.Barcode.Code, barcodeDB.Code, StringComparison.CurrentCultureIgnoreCase), out var products)) { return(products.First().Id); } else { var barcode = await _barcodeService.GetBarcodeFromCatalogAsync(code); var newProduct = new Product { Barcode = barcode, Name = barcode.ProductName, Composition = barcode.Composition, Brand = barcode.Brand, Country = barcode.Country, Weight = barcode.Weight, PicturePath = barcode.PicturePath, }; return(await _productRepository.AddAsync(_mapper.Map <ProductDB>(newProduct))); } }