Esempio n. 1
0
        public async Task <Result <BlogPostViewModel> > Handle(GetBlogPostQuery message, CancellationToken cancellationToken)
        {
            var viewModel = await _cacheService.GetOrAddAsync(() => CreateViewModelAsync(message.Id), message.Id);

            if (viewModel == null)
            {
                return(new NotFoundResult <BlogPostViewModel>());
            }

            return(viewModel.ToSuccessResult());
        }
Esempio n. 2
0
        public async Task <ActionResult <BlogPostViewModel> > Get(int id)
        {
            var query = new GetBlogPostQuery()
            {
                Id = id
            };
            var blogPost = await _mediator.Send(query);

            if (!blogPost)
            {
                return(NotFound());
            }

            return(blogPost.Payload);
        }