public async Task AddAsync(IFormFile file, int productId, bool isMain) { var product = await productRepository.GetAndEnsureExistAsync(productId); var uniqueFileName = file.FileName.GetUniqueFileName(); var imagePath = Path.Combine(product.ImagesPath, uniqueFileName); var imagePathForGet = imagePath.Substring(8); // to remove wwwroot var image = new Image(imagePathForGet, isMain); product.AddImage(image); await productRepository.SaveChangesAsync(); var imagesPhysicalPath = pathManager.GetPhysicalPath(product.ImagesPath); await fileManager.MoveFileAsync(file, imagesPhysicalPath, uniqueFileName); }