Example #1
0
        public Comment RowToComment(CommentRow row)
        {
            if (row == null)
            {
                return(default(Comment));
            }
            var commentID        = new CommentID(row.G_CommentVolume, row.GDID);
            var parentID         = row.G_Parent.HasValue ? new CommentID(row.G_CommentVolume, row.G_Parent.Value) : (CommentID?)null;
            var authorNode       = m_GraphSystemService.GetNode(row.G_AuthorNode);
            var targetNode       = m_GraphSystemService.GetNode(row.G_TargetNode);
            var editableTimespan = GraphHost.EditCommentSpan(targetNode, row.Dimension);
            var lifeTime         = App.TimeSource.UTCNow - row.Create_Date;

            return(new Comment(commentID,
                               parentID,
                               authorNode,
                               targetNode,
                               row.Create_Date,
                               row.Dimension,
                               GSPublicationState.ToPublicationState(row.PublicationState),
                               row.IsRoot ? (RatingValue)row.Rating : RatingValue.Undefined,
                               row.Message,
                               row.Data,
                               row.Like,
                               row.Dislike,
                               row.ComplaintCount,
                               row.ResponseCount,
                               row.In_Use,
                               editableTimespan > lifeTime));
        }
Example #2
0
        /// <summary>
        /// Updates existing rating by ID
        /// </summary>
        public GraphChangeStatus Update(CommentID commentId, RatingValue value, string content, byte[] data)
        {
            if (commentId.IsZero)
            {
                return(GraphChangeStatus.NotFound);
            }

            try
            {
                // Taking comment row
                var currentDateTime = App.TimeSource.UTCNow;
                var ctxComment      = ForComment(commentId.G_Volume); // CRUD context for comment
                var comment         = getCommentRow(commentId, ctxComment);
                if (comment == null)
                {
                    return(GraphChangeStatus.NotFound);
                }

                var targetNode = DoGetNode(comment.G_TargetNode);
                if ((currentDateTime - comment.Create_Date) > GraphHost.EditCommentSpan(targetNode, comment.Dimension))
                {
                    return(GraphChangeStatus.NotFound);
                }

                var ctxNode = ForNode(comment.G_TargetNode); // CRUD context for target node

                // Updating fields
                var filter = "Message,Data";
                comment.Message = content;
                comment.Data    = data;

                // if comment is root and rating value is not RatingValue.Undefined
                // Update rating
                if (comment.IsRoot && value != RatingValue.Undefined)
                {
                    // Update NodeRating
                    var nodeRating = getNodeRating(comment.G_TargetNode, comment.Dimension, ctxNode);
                    nodeRating.UpdateRating((RatingValue)comment.Rating, -1);
                    nodeRating.UpdateRating(value, 1);
                    ctxNode.Update(nodeRating, filter: "Last_Change_Date,Cnt,Rating1,Rating2,Rating3,Rating4,Rating5".OnlyTheseFields());

                    // Update rating value of comment
                    comment.Rating = (byte)value;
                    filter         = "Rating," + filter;
                }
                var resComment = ctxComment.Update(comment, filter: filter.OnlyTheseFields());
                return(resComment == 0 ? GraphChangeStatus.NotFound : GraphChangeStatus.Updated);
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "GraphCommentSystem.Update", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_UPDATE_RATING_ERROR.Args(commentId.G_Comment), ex);
            }
        }