Exemple #1
0
        public object Transform(bool includeComments, User currentUser)
        {
            var comments = this.Comments ?? new List<Comment>();

            return new {
                Id = Id,
                Title = Title,
                Url = Url,
                Submitter = new {
                    UserName = Author.UserName,
                    Id = AuthorId
                },
                VoteTally = VoteTally,
                CommentCount = comments.Count,
                CommentsIncluded = includeComments,
                Comments = !includeComments ? null : comments.Select(c => new {
                    Id = c.Id,
                    Author = new {
                        Id = c.AuthorId,
                        UserName = c.Author.UserName,
                    },
                    Text = c.Text
                }),
                UpvoteCurrentUser = HasUpvoteFromUser(currentUser),
                DownvoteCurrentUser = HasDownvoteFromUser(currentUser)
            };
        }
Exemple #2
0
 private void AddToSession(User user)
 {
     HttpContext.Current.User = new NottitPrincipal(user.UserName);
 }
Exemple #3
0
 private bool HasUpvoteFromUser(User user)
 {
     return user != null
         && Votes.Any(v => v.VoterId == user.Id && v.Value == 1);
 }