예제 #1
0
        public IHttpActionResult GetGroupWall([FromUri] int groupId)
        {
            var group = this.Data.Groups.Find(groupId);

            if (group == null)
            {
                return(this.NotFound());
            }

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

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

            var posts = group.Posts
                        .OrderByDescending(p => p.PostedOn)
                        .AsQueryable();

            var postsPreview = posts
                               .Select(p => PostViewModel.CreateGroupPostPreview(currentUser, p))
                               .ToList();

            return(this.Ok(postsPreview));
        }
        public async Task <HttpResponseMessage> GetPostById([FromUri] int id)
        {
            var post = this.Data.GroupPosts.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.CreateGroupPostPreview(currentUser, post);

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