Пример #1
0
        public GetCommentsResponse GetCommentTree(CommentModel item, int currentNodeId, int topCommentId)
        {
            if (item.Id != currentNodeId)
            {
                if (item.Children != null)
                {
                    GetCommentsResponse foundresult = null;
                    foreach (var inner in item.Children)
                    {
                        foundresult = GetCommentTree(inner, currentNodeId, topCommentId);
                        if (foundresult != null)
                        {
                            break;
                        }
                    }

                    return(foundresult);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(new GetCommentsResponse
                {
                    Comment = item,
                    TopCommentId = topCommentId
                });
            }
        }
Пример #2
0
        public async Task <GetCommentsResponse> GetPostCommentsAsync(int postId)
        {
            var commentEntities = await _postRepository.GetPostCommentsAsync(postId);

            var response = new GetCommentsResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Comments   = commentEntities.Select(c => _postCommentMapper.ToModel(c)).ToList()
            };

            return(response);
        }
Пример #3
0
        public async void GetMoreComments(int parentId)
        {
            CurrentParentId = parentId;
            var result = await EndPoint.GetComments(parentId, "comment");

            //var parent = this.Where(z => z.Id == parentId).FirstOrDefault();

            GetCommentsResponse commentResponse = null;

            foreach (var item in this)
            {
                commentResponse = GetCommentTree(item, parentId, item.Id);
                if (commentResponse != null)
                {
                    break;
                }
            }

            CommentModel parent       = commentResponse.Comment;
            int          TopCommentId = commentResponse.TopCommentId;

            parent.Children = new List <CommentModel>();

            foreach (var item in result)
            {
                if (item.Text != null)
                {
                    item.TimeSpan = TimeConverter.TimeSpanToString(item.Time);
                    item.Text     = HtmlParser.Parse(item.Text);
                    parent.Children.Add(item);
                }
            }

            var itemToUpdate = this.Single(r => r.Id == TopCommentId);
            var index        = this.IndexOf(itemToUpdate);

            this.InsertItem(index, itemToUpdate);
            this.RemoveAt(index + 1);
            //this.Remove(itemToRemove);
            CurrentParentId = 0;
        }
Пример #4
0
        public GetCommentsResponse GetCommentsByPost(GetCommentsByPostRequest request)
        {
            GetCommentsResponse response = new GetCommentsResponse();

            response.StatusCode = 200;
            response.Errors     = new List <string>();
            var comments           = _commentRepository.GetByPostId(request.PostId);
            List <CommentDTO> dtos = new List <CommentDTO>();

            foreach (var comment in comments)
            {
                CommentDTO dto = new CommentDTO()
                {
                    Comment     = comment,
                    Username    = _userRepository.GetUserById(comment.UserId).Username,
                    SubComments = _commentRepository.GetByParentCommentId(comment.PostId, comment.Id).Count,
                };
                dtos.Add(dto);
            }
            response.Comments = dtos;
            return(response);
        }
Пример #5
0
        private void GetCommentsFinished(object sender, get_commentsCompletedEventArgs e)
        {
            AsyncCallState<OperationFinished<GetCommentsResponse>> state =
                (AsyncCallState<OperationFinished<GetCommentsResponse>>) e.UserState;

            GetCommentsResponse response;

            if (e.Error != null)
            {
                response = new GetCommentsResponse
                           	{
                           		Error = e.Error,
                           		Status = GetCommentsStatus.Failed,
                           		UserState = state.UserState
                           	};
            }
            else
            {
                response = new GetCommentsResponse
                           	{
                                //Status = StatusMessageParser.ParseGetFileInfoStatus(e.Result),
                                //File = new File
                                //        {
                                //            Created = UnixTimeConverter.Instance.FromUnixTime(e.info.created),
                                //            Description = e.info.description,
                                //            ID = e.info.file_id,
                                //            IsShared = e.info.shared == 1,
                                //            Name = e.info.file_name,
                                //            PublicName = e.info.public_name,
                                //            SHA1Hash = e.info.sha1,
                                //            Size = e.info.size,
                                //            Updated = UnixTimeConverter.Instance.FromUnixTime(e.info.updated)
                                //        },
                           		UserState = state.UserState
                           	};

                response.Error = response.Status == GetCommentsStatus.Unknown
                                    ?
                                        new UnknownOperationStatusException(e.Result)
                                    :
                                        null;
            }

            state.CallbackDelegate(response);
        }