Ejemplo n.º 1
0
 public static PostViewModel Create(Post p, ApplicationUser currentUser)
 {
     return(new PostViewModel()
     {
         Id = p.Id,
         Author = UserViewModelPreview.Create(p.Author, currentUser),
         WallOwner = UserViewModelPreview.Create(p.WallOwner, currentUser),
         PostContent = p.Content,
         Date = p.Date,
         LikesCount = p.Likes.Count,
         Liked = p.Likes
                 .Any(l => l.UserId == currentUser.Id),
         TotalCommentsCount = p.Comments.Count,
         Comments = p.Comments
                    .Reverse()
                    .Take(3)
                    .Select(c => CommentViewModel.Create(c, currentUser))
     });
 }
Ejemplo n.º 2
0
        public IHttpActionResult GetPreview(string username)
        {
            var targetUser = this.SocialNetworkData.Users.All()
                             .FirstOrDefault(u => u.UserName == username);

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

            var loggedUserId = this.User.Identity.GetUserId();

            if (loggedUserId == null)
            {
                return(this.BadRequest("Invalid session token."));
            }

            var loggedUser = this.SocialNetworkData.Users.GetById(loggedUserId);

            return(this.Ok(UserViewModelPreview.Create(targetUser, loggedUser)));
        }