Exemple #1
0
            public async Task <Response <int> > Handle(UpdatePostCommand command, CancellationToken cancellationToken)
            {
                var post = await _postRepository.GetByIdAsync(command.Id);

                if (post == null)
                {
                    throw new ApiException($"Post Not Found.");
                }
                else
                {
                    //post.Title = command.Title;
                    //post.Body = command.Body;
                    //post.Slug = command.Slug;
                    post.Locales     = command.Locales;
                    post.IsArchive   = command.IsArchive;
                    post.IsPublic    = command.IsPublic;
                    post.Thumbnail   = command.Thumbnail;
                    post.CategoryId  = command.CategoryId;
                    post.Description = command.Description;
                    //post.Tags = command.Tags;

                    await _postRepository.UpdateAsync(post);

                    return(new Response <int>(post.Id));
                }
            }
Exemple #2
0
            public async Task <Response <int> > Handle(DeletePostByIdCommand command, CancellationToken cancellationToken)
            {
                Post post = await _postRepository.GetByIdAsync(command.Id);

                if (post == null)
                {
                    throw new ApiException($"Log Not Found.");
                }
                await _postRepository.DeleteAsync(post);

                return(new Response <int>(post.Id));
            }
Exemple #3
0
        public async Task <Response <GetPostDto> > Handle(GetPostByIdQuery query, CancellationToken cancellationToken)
        {
            Post post = await _postRepository.GetByIdAsync(query.Id);

            if (post == null)
            {
                throw new ApiException($"Post Not Found.");
            }

            var postDto = _mapper.Map <GetPostDto>(post);
            // Raising newlly post created Event ...
            //TODO: pass Client Info(ip) for event parameter
            await _mediator.Publish(new PostRequestedEvent(DateTime.Now, postDto.Id, ""), cancellationToken);

            return(new Response <GetPostDto>(postDto));
        }