コード例 #1
0
        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="currentUser">the current user</param>
        /// <param name="commentService">the comment service</param>
        /// <param name="contentUrlFunction">The content URL function.</param>
        /// <param name="loadFirstComments">if set to <c>true</c> [load first comments].</param>
        /// <returns>the model</returns>
        public static CommentModel ToModel(
            this Comment entity,
            User currentUser,
            ICommentService commentService,
            Func <string, string> contentUrlFunction = null,
            bool loadFirstComments = false)
        {
            var model = new CommentModel()
            {
                Id               = entity.Id,
                Value            = entity.Value,
                CountSubcomments = entity.CountSubcomments,
                CreationDate     = entity.CreationDate,
                User             = entity.User.ToBaseModel(),
                ParentCommentId  = entity.ParentCommentId,
                CanDelete        = entity.CanUserDeleteComment(currentUser)
            };

            ////Carga los dos primeros comentarios asociados a ese comentario
            if (loadFirstComments && entity.CountSubcomments > 0)
            {
                model.FirstComments = commentService.Search(parentCommentId: entity.Id, pageSize: 10)
                                      .Result
                                      .ToModels(currentUser, commentService, contentUrlFunction);
            }

            return(model);
        }