コード例 #1
0
        private WallPostWithDetailsModel MapWallPost(GetWallPost_Result postResult,
                                                     IEnumerable <GetLatestComments_Result> commentResult)
        {
            var mapped = new WallPostWithDetailsModel
            {
                Body         = postResult.Body,
                CommentCount = postResult.CommentCount.Value,
                CreatedDate  = postResult.CreatedDate,
                Id           = postResult.Id,
                LikeCount    = postResult.LikeCount.Value,
                ModifiedDate = postResult.ModifiedDate,
                PostedBy     = postResult.CreatedBy,
                PostType     = postResult.PostType
            };
            var wallModel = new WallModel();

            if (!string.IsNullOrWhiteSpace(postResult.GroupId))
            {
                wallModel.OwnerId       = postResult.GroupId;
                wallModel.WallOwnerType = WallType.group;
            }
            else
            {
                wallModel.OwnerId       = postResult.UserId;
                wallModel.WallOwnerType = WallType.user;
            }
            mapped.WallOwner = wallModel;

            var commentList = new List <CommentModel>();

            if (commentResult != null && commentResult.Any())
            {
                foreach (var comment in commentResult)
                {
                    commentList.Add(new CommentModel
                    {
                        Body         = comment.Body,
                        CreatedBy    = comment.CreatedBy,
                        CreatedDate  = comment.CreatedDate,
                        Id           = comment.Id,
                        LikeCount    = comment.LikeCount.Value,
                        ModifiedDate = comment.ModifiedDate
                    });
                }
            }
            mapped.LatestComments = commentList;
            return(mapped);
        }
コード例 #2
0
        private IEnumerable <WallPostWithDetailsModel> MapWall(IEnumerable <GetWall_Result> procedureResult, WallModel wallOwner)
        {
            var result = new List <WallPostWithDetailsModel>();

            if (procedureResult != null)
            {
                foreach (var record in procedureResult)
                {
                    var comment        = MapComment(record);
                    var existingRecord = result.FirstOrDefault(p => p.Id == record.Id);
                    if (existingRecord == null)
                    {
                        var relatedPost = new WallPostWithDetailsModel
                        {
                            Body           = record.Body,
                            CommentCount   = record.CommentCount.Value,
                            CreatedDate    = record.CreatedDate,
                            Id             = record.Id,
                            LikeCount      = record.LikeCount.Value,
                            ModifiedDate   = record.ModifiedDate,
                            PostedBy       = record.CreatedBy,
                            PostType       = record.PostType,
                            WallOwner      = wallOwner,
                            LatestComments = new List <CommentModel>()
                        };
                        existingRecord = relatedPost;
                        result.Add(relatedPost);
                    }
                    if (comment != null)
                    {
                        (existingRecord.LatestComments as List <CommentModel>).Add(comment);
                    }
                }
            }
            return(result);
        }