public ActionResult Show(Guid key)
        {
            var commentsPerTopic = _topicDriver.GetTopicWithComments(key, PageConstants.FirstPageNumber, DefaultSetting.CommentsPerPage);

            if (commentsPerTopic == null)
            {
                return(HttpNotFound());
            }

            ScriptRegister.AddJson("commentsPerTopic", _topicDriver.ToTopicWithCommentsClient(commentsPerTopic));

            var newComment = _commentDriver.Create();

            newComment.TopicId = commentsPerTopic.Topic.Id;
            newComment.Topic   = commentsPerTopic.Topic;
            ScriptRegister.AddJson("newComment", _commentDriver.ToClient(newComment));

            ViewBag.CurrentThread = _threadDriver.Get(commentsPerTopic.Topic.ThreadId);

            return(View());
        }
Beispiel #2
0
        public override TopicClient ToClient(ContentTopic entity, TopicClient c = null, string[] excludeProperties = null, bool serverStatus = true)
        {
            if (entity == null)
            {
                return(null);
            }

            TopicClient topicClient = base.ToClient(entity, c, excludeProperties, serverStatus);

            topicClient.Title          = entity.Title;
            topicClient.SubTitle       = entity.SubTitle;
            topicClient.IsSticky       = entity.IsLocked;
            topicClient.IsLocked       = entity.IsLocked || entity.IsHidden;
            topicClient.CreateTime     = entity.CreateTime;
            topicClient.LastUpdateTime = entity.LastUpdateTime;
            topicClient.Thumbnail      = entity.Thumbnail;
            topicClient.ThreadId       = entity.ThreadId;
            if (entity.Thread != null)
            {
                topicClient.ThreadKey = entity.Thread.Key;
                if (!topicClient.IsLocked && entity.Thread.IsLocked)
                {
                    entity.IsLocked = true;
                }
            }

            if (excludeProperties == null || !excludeProperties.Contains("FirstComment"))
            {
                topicClient.FirstCommentId = entity.FirstComment.Id;
                topicClient.Content        = entity.FirstComment.Content;
            }

            if (excludeProperties == null || !excludeProperties.Contains("Vote"))
            {
                if (topicClient.Vote == null)
                {
                    topicClient.Vote = new VoteClient();
                }

                topicClient.Vote.CommentId     = entity.FirstComment.Id;
                topicClient.Vote.UserName      = entity.UserName;
                topicClient.Vote.VoteUpCount   = entity.FirstComment.VoteUpCount;
                topicClient.Vote.VoteDownCount = entity.FirstComment.VoteDownCount;
            }

            if (excludeProperties == null || !excludeProperties.Contains("Comments"))
            {
                if (topicClient.Comments == null)
                {
                    topicClient.Comments = new List <CommentClient>();
                }
                if (entity.Comments != null && entity.Comments.Count > 0)
                {
                    foreach (var comment in entity.Comments)
                    {
                        topicClient.Comments.Add(_commentDriver.ToClient(comment));
                    }
                }
            }

            if (excludeProperties == null || !excludeProperties.Contains("Tags"))
            {
                if (topicClient.TagOptions == null)
                {
                    topicClient.TagOptions = new ModelListClient <TagOptionClient>();
                }
                if (entity.Tags != null && entity.Tags.Count > 0)
                {
                    topicClient.TagOptions.Clear();
                    var groupTags = entity.Tags.GroupBy(x => x.Category).ToList();
                    foreach (var tagCategory in groupTags)
                    {
                        string tagIds = string.Join(",", tagCategory.Select(x => x.Id));
                        topicClient.TagOptions.Add(new TagOptionClient()
                        {
                            CategoryName = tagCategory.Key.Name, IdStrs = tagIds
                        });
                    }
                }
            }

            if (excludeProperties == null || !excludeProperties.Contains("UploadPermission"))
            {
                topicClient.CanUploadDocument = HasPermission(EntityPermission.UploadDocument, entity) == OperationStatus.Granted;
                topicClient.CanUploadImage    = HasPermission(EntityPermission.UploadImage, entity) == OperationStatus.Granted;
            }

            return(topicClient);
        }