public async Task <string> Handle(CreatePostWithFileCommand request, CancellationToken cancellationToken)
        {
            Domain.Entities.Post post =
                await _postService.CreatePostWithFileAsync(request.UserId, request.CreatePostWithFileDto);

            if (!PostHelpers.IsContentFile(request.CreatePostWithFileDto.Content))
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest, "Post creation failed");
            }

            FileData data = BaseHelpers.GetContentFileData <Domain.Entities.Post>(
                request.CreatePostWithFileDto.Content, post.Id
                );

            if (post.ContentType.Equals(data.FileName.GetContentType()))
            {
                await _blobService.UploadImageBlobAsync(data.Content, data.FileName);

                request.CreatePostWithFileDto.Content     = data.FileName;
                request.CreatePostWithFileDto.ContentType = data.FileName.GetContentType();

                await _postService.UpdatePostAsync(post, new UpdatePostDto
                {
                    Content = request.CreatePostWithFileDto.Content,
                    Title   = post.Title,
                });
            }
            else
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest,
                                                  "Can not update content type of a post");
            }

            return(post.Id);
        }
예제 #2
0
        public async Task <CommunityViewModel> Handle(UpdateCommunityImageCommand request,
                                                      CancellationToken cancellationToken)
        {
            FileData data = BaseHelpers.GetContentFileData <Domain.Entities.Community>(
                request.UpdateCommunityImageDto.Image, request.Community.Id
                );
            await _blobService.UploadImageBlobAsync(data.Content, data.FileName);

            request.UpdateCommunityImageDto.Image = data.FileName;

            return(await _communityService.UpdateCommunityImageAsync(request.Community,
                                                                     request.UpdateCommunityImageDto));
        }
예제 #3
0
        public async Task <UserResponse> Handle(UpdateUserImageCommand request, CancellationToken cancellationToken)
        {
            FileData data =
                BaseHelpers.GetContentFileData <Domain.Entities.User>(request.UpdateUserImageDto.Image, request.UserId);
            await _blobService.UploadImageBlobAsync(data.Content, data.FileName);

            request.UpdateUserImageDto.Image = data.FileName;

            UserViewModel user = await _userService.UpdateUserImageAsync(request.UserId, request.UpdateUserImageDto);

            return(new UserResponse {
                User = user
            });
        }
예제 #4
0
        public async Task <PostViewModel> Handle(UpdatePostCommand request,
                                                 CancellationToken cancellationToken)
        {
            if (PostHelpers.IsContentFile(request.UpdatePostDto.Content) &&
                !request.Post.ContentType.Equals("application/text"))
            {
                FileData data = BaseHelpers.GetContentFileData <Domain.Entities.Post>(
                    request.UpdatePostDto.Content, request.Post.Id
                    );
                request.UpdatePostDto.Content = data.FileName;
                if (request.Post.ContentType.Equals(request.UpdatePostDto.Content.GetContentType()))
                {
                    await _blobService.UploadImageBlobAsync(data.Content, data.FileName);
                }
            }

            return(await _postService.UpdatePostAsync(request.Post, request.UpdatePostDto));
        }