//[ProducesResponseType(typeof(CategoryDto), 201)] //[ProducesResponseType(typeof(CategoryDto), 400)] public async Task <IActionResult> AddProduct([FromBody] ProductDto productDto) { if (string.IsNullOrWhiteSpace(_hostingEnvironment.WebRootPath)) { _hostingEnvironment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } var filePath = _hostingEnvironment.WebRootPath + "\\images\\products"; var base64String = Regex.Replace(productDto.Image, "^data:image\\/[a-zA-Z]+;base64,", String.Empty); if (base64String.IsBase64()) { Product product = Mapper.Map <Product>(productDto); product.Image = Guid.NewGuid() + ".jpg"; _productRepository.Add(product); if (!_productRepository.Save()) { throw new Exception("something went wrong when adding a new subcategory"); } await FileHelper.AddFileAsync(filePath, base64String, product.Image); return(Ok(productDto)); } else { return(BadRequest()); } }