Пример #1
0
        public async Task <HttpResponseMessage> GetPostById([FromUri] int id)
        {
            var post = this.Data.Posts.FirstOrDefault(p => p.Id == id);

            if (post == null)
            {
                return(await this.NotFound().ExecuteAsync(new CancellationToken()));
            }

            var currentUserId = User.Identity.GetUserId();
            var currentUser   = this.Data.Users.FirstOrDefault(x => x.Id == currentUserId);

            if (currentUser == null)
            {
                return(await this.BadRequest("Invalid user token! Please login again!").ExecuteAsync(new CancellationToken()));
            }

            var postPreview = PostViewModel.CreatePostPreview(currentUser, post);

            return(await this.Ok(postPreview).ExecuteAsync(new CancellationToken()));
        }