Exemplo n.º 1
0
 public static void HydrateUserData(IPrincipal user, Domain.Models.Comment comment, bool populateMissingUserState = false, IEnumerable <VotedValue> commentVotes = null, IEnumerable <BlockedItem> userBlocks = null)
 {
     if (comment != null)
     {
         string userName = user.Identity.Name;
         if (!String.IsNullOrEmpty(userName))
         {
             comment.IsOwner = comment.UserName == userName;
             comment.Vote    = 0;
             if (commentVotes != null)
             {
                 var vote = commentVotes.FirstOrDefault(x => x.ID == comment.ID);
                 comment.Vote = vote == null ? 0 : vote.Value;
             }
             else if (populateMissingUserState)
             {
                 using (var repo = new Repository())
                 {
                     //comment.Vote = VotingComments.CheckIfVotedComment(userName, comment.ID);
                     comment.Vote = repo.UserVoteStatus(userName, ContentType.Comment, comment.ID);
                 }
             }
             //collapse comment threads when user is blocked
             if (!comment.IsAnonymized && userBlocks != null && userBlocks.Any())
             {
                 comment.IsCollapsed = userBlocks.Any(x => comment.UserName.IsEqual(x.Name));
             }
             comment.IsSaved = false;
             comment.IsSaved = UserHelper.IsSaved(user, ContentType.Comment, comment.ID);
         }
         Protect(comment);
         ////Swap UserName
         //comment.UserName = (comment.IsAnonymized ? comment.ID.ToString() : comment.UserName);
     }
 }
Exemplo n.º 2
0
        public static usp_CommentTree_Result MapToTree(this Domain.Models.Comment comment)
        {
            usp_CommentTree_Result result = null;

            if (comment != null)
            {
                result = new usp_CommentTree_Result()
                {
                    ChildCount       = 0,
                    Depth            = 0,
                    Path             = "",
                    Subverse         = comment.Subverse,
                    ID               = comment.ID,
                    ParentID         = comment.ParentID,
                    Content          = comment.Content,
                    FormattedContent = comment.FormattedContent,
                    CreationDate     = comment.CreationDate,
                    LastEditDate     = comment.LastEditDate,
                    SubmissionID     = comment.SubmissionID,
                    UpCount          = comment.UpCount,
                    DownCount        = comment.DownCount,
                    IsDistinguished  = comment.IsDistinguished,
                    IsDeleted        = comment.IsDeleted,
                    IsAnonymized     = comment.IsAnonymized,
                    UserName         = comment.UserName
                };
            }
            return(result);
        }
Exemplo n.º 3
0
        public static NestedComment Map(this Domain.Models.Comment comment, IPrincipal user, bool populateMissingUserState = false)
        {
            NestedComment result = null;

            if (comment != null)
            {
                result                  = new NestedComment();
                result.ID               = comment.ID;
                result.ParentID         = comment.ParentID;
                result.ChildCount       = 0;
                result.Content          = comment.Content;
                result.FormattedContent = comment.FormattedContent;
                result.UserName         = comment.UserName;
                result.UpCount          = (int)comment.UpCount;
                result.DownCount        = (int)comment.DownCount;
                result.CreationDate     = comment.CreationDate;
                result.IsAnonymized     = comment.IsAnonymized;
                result.IsDeleted        = comment.IsDeleted;
                result.IsDistinguished  = comment.IsDistinguished;
                result.LastEditDate     = comment.LastEditDate;
                result.SubmissionID     = comment.SubmissionID;
                result.Subverse         = comment.Subverse;

                //Set User State and secure comment
                HydrateUserData(user, result, populateMissingUserState);
            }
            return(result);
        }
        public bool RespondToComment(int commentID, Domain.Models.Comment comment)
        {
            var dbComment = _context.Comments.FirstOrDefault(c => c.Id == commentID);

            if (dbComment == null)
            {
                //comment to respond to doesn't exist
                return(false);
            }

            dbComment = new Comment
            {
                Id             = comment.ID,
                CommenterId    = comment.Commenter.ID,
                EpicId         = comment.CommentEpic.ID,
                Comment1       = comment.CommentContent,
                DateCreated    = (DateTime)comment.Date,
                ReplyToComment = commentID
            };

            _context.Comments.Add(dbComment);
            _context.SaveChanges();

            return(true);
        }
Exemplo n.º 5
0
        public static void ProcessComment(Domain.Models.Comment comment, bool populateMissingUserState = false, IEnumerable <CommentVoteTracker> commentVotes = null)
        {
            if (comment != null)
            {
                string userName = Thread.CurrentPrincipal.Identity.IsAuthenticated ? Thread.CurrentPrincipal.Identity.Name : null;
                if (!String.IsNullOrEmpty(userName))
                {
                    comment.IsOwner = comment.UserName == userName;
                    comment.Vote    = 0;
                    if (commentVotes != null)
                    {
                        var vote = commentVotes.FirstOrDefault(x => x.CommentID == comment.ID);
                        if (vote != null)
                        {
                            comment.Vote = vote.VoteStatus;
                        }
                    }
                    else if (populateMissingUserState)
                    {
                        using (var repo = new Repository())
                        {
                            //comment.Vote = VotingComments.CheckIfVotedComment(userName, comment.ID);
                            comment.Vote = repo.UserVoteStatus(userName, ContentType.Comment, comment.ID);
                        }
                    }

                    comment.IsSaved = false;
                    comment.IsSaved = UserHelper.IsSaved(ContentType.Comment, comment.ID);
                }
                comment.UserName = (comment.IsAnonymized ? comment.ID.ToString() : comment.UserName);
            }
        }
Exemplo n.º 6
0
 public static Domain.Models.Comment Map(this Data.Models.Comment comment, IPrincipal user, string subverse, bool populateUserState = false)
 {
     Domain.Models.Comment result = null;
     if (comment != null)
     {
         result = MapToNestedComment(comment, user, subverse, populateUserState);
     }
     return(result);
 }
 public static CommentModel Map(Domain.Models.Comment comment)
 {
     return(new CommentModel {
         ID = comment.ID,
         CommenterName = comment.Commenter.Name,
         CommentContent = comment.CommentContent,
         DateOfComment = comment.Date
     });
 }
Exemplo n.º 8
0
 public static Comment Map(Domain.Models.Comment model)
 {
     return(new Comment
     {
         ReplyToComment = model.ReplyToComment,
         Comment1 = model.CommentContent,
         DateCreated = (DateTime)model.Date,
         Id = model.ID
     });
 }
 public Domain.Models.IComment Convert(MongoDb.Entities.Comment source, Domain.Models.IComment destination, ResolutionContext context)
 {
     destination = new Domain.Models.Comment
     {
         CreationDate = source.CreationDate,
         Id           = source.Id,
         PostId       = source.PostId,
         Score        = source.Score,
         Text         = source.Text,
         UserId       = source.UserId
     };
     return(destination);
 }
Exemplo n.º 10
0
 private static void Protect(Domain.Models.Comment comment)
 {
     if (comment != null)
     {
         //Swap UserName
         comment.UserName = (comment.IsAnonymized ? comment.ID.ToString() : comment.UserName);
         //Ensure Deleted - this isn't going to work with comment moderation log, I think
         if (comment.IsDeleted)
         {
             comment.UserName         = "";
             comment.Content          = "Deleted";
             comment.FormattedContent = "<p>Deleted</p>";
         }
     }
 }
        /// <summary>
        /// Adds Comment to epic
        /// </summary>
        /// <param name="comment">Domain Model Object</param>
        /// <returns>True if comment successfully added to epic in database</returns>
        public bool AddComment(Domain.Models.Comment comment)
        {
            var dbComment = new Comment
            {
                Id          = comment.ID,
                CommenterId = comment.Commenter.ID,
                EpicId      = comment.CommentEpic.ID,
                Comment1    = comment.CommentContent,
                DateCreated = (DateTime)comment.Date
            };

            _context.Comments.Add(dbComment);
            _context.SaveChanges();

            return(true);
        }
Exemplo n.º 12
0
 private void EnsureAnonIsProtected(Domain.Models.Comment comment)
 {
     Assert.AreEqual(true, comment.IsAnonymized, $"Expected anonymized comment on comment {comment.ID}");
     Assert.AreEqual(comment.ID.ToString(), comment.UserName, $"Expected username to be changed on comment {comment.ID}");
 }