Exemple #1
0
        public async Task <UploadImagesForVideoResponseMessage> Handle(UploadImagesForVideoRequestMessage request, CancellationToken cancellationToken)
        {
            var validationResult = _validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(new UploadImagesForVideoResponseMessage(validationResult));
            }

            var video = await _repository.GetByIdAsync <Video>(request.VideoId);

            if (video == null)
            {
                //remove that after testing
                validationResult.Errors.Add(new FluentValidation.Results.ValidationFailure("video", "not found 404"));
                return(new UploadImagesForVideoResponseMessage(validationResult));
            }

            List <string> imageUris = new List <string>();

            foreach (var data in request.FilesData)
            {
                var uri = await _imageStorage.Upload(data);

                var image = new VideoImage(Guid.NewGuid().ToString(), uri);

                imageUris.Add(uri);

                video.RegisterImage(image);
                await _repository.UpdateAsync <Video>(video);
            }

            return(new UploadImagesForVideoResponseMessage(validationResult, imageUris));
        }