public async Task <int> Handle(CreateFolderCommand request, CancellationToken cancellationToken)
        {
            if (request.ParentId.HasValue && !await foldersRepository.Exists(request.ParentId.Value))
            {
                throw new ParentFolderDoesNotExistRequestException();
            }
            if (!await foldersRepository.IsUniqueInParent(request.Name, request.ParentId))
            {
                throw new FolderNameMustBeUniqueInParentRequestException();
            }

            var folder   = new Folder(request.Name, request.ParentId);
            var folderId = await foldersRepository.AddAsync(folder);

            return(folderId);
        }
コード例 #2
0
        public async Task <int> Handle(CreateImageAssetCommand request, CancellationToken cancellationToken)
        {
            if (!await foldersRepository.Exists(request.ParentFolderId))
            {
                throw new ParentFolderDoesNotExistRequestException();
            }
            if (!await imageAssetsRepository.IsUniqueInFolder(request.FileName, request.ParentFolderId))
            {
                throw new FileNameMustBeUniqueInFolderRequestException();
            }

            var assetGlobalUniqueIdentifier = Guid.NewGuid();

            var blobClient = blobContainerClient.GetBlobClient(assetGlobalUniqueIdentifier.ToString());
            await blobClient.UploadAsync(request.ImageReadStream, true);

            request.ImageReadStream.Close();

            var imageAsset = new ImageAsset(request.FileName, request.ContentType, assetGlobalUniqueIdentifier, request.ParentFolderId);
            var imageId    = await imageAssetsRepository.AddAsync(imageAsset);

            return(imageId);
        }