public async Task RegisterNewProductAsync(Domain.Entities.Product product, List <RequestFile> photos, RequestFile profile) { const string profilePhotoName = nameof(product.ProfilePhoto); const string photosName = nameof(product.Photos); const string bucketName = nameof(profile.Bucket); const string nameOfPhotosName = nameof(RequestFile.Name); var productValidation = product.Validate(profilePhotoName, photosName); var profileValidation = profile.Validate(bucketName, nameOfPhotosName); var photosValidation = photos?.SelectMany(p => p.Validate(bucketName, nameOfPhotosName)); if (productValidation.IsValid() && profileValidation.IsValid() && photosValidation.IsValid()) { await _repository.CreateProductAsync(product); _uploader.FileUploaded += OnPhotoUploaded; profile.Name = $"{ProductName}-{product.Key}-{ProfileTypeName}-{profile.Key}".ToLower(); profile.Bucket = "store-lab-product-profile"; profile.Metadata = new Dictionary <string, string> { { ProductKeyName, product.Key }, { FileTypeName, ProfileTypeName } }; photos?.ForEach(p => { p.Name = $"{ProductName}-{product.Key}-{PhotoTypeName}-{p.Key}".ToLower(); p.Bucket = "store-lab-product-photos"; p.Metadata = new Dictionary <string, string> { { ProductKeyName, product.Key }, { FileTypeName, PhotoTypeName } }; }); await _uploader.UploadAsync(profile); await _uploader.UploadAllAsync(photos); var args = new RegisterNewProductEventArgs { Product = product }; ProductRegisted?.Invoke(this, args); } else { throw new EntityException(productValidation.Aggregate(profileValidation).Aggregate(photosValidation)); } }