コード例 #1
0
ファイル: APIModelDataMapper.cs プロジェクト: dashluu/Blog
        public List <APICommentModel> MapCommentDTOsToModels(List <CommentDTO> commentDTOs)
        {
            if (commentDTOs == null)
            {
                return(null);
            }

            List <APICommentModel> commentModels = new List <APICommentModel>();

            foreach (CommentDTO commentDTO in commentDTOs)
            {
                APICommentModel commentModel = MapCommentDTOToModel(commentDTO);
                commentModels.Add(commentModel);
                List <CommentDTO> childCommentDTOs = commentDTO.ChildCommentDTOs;

                if (childCommentDTOs == null)
                {
                    continue;
                }

                List <APICommentModel> childCommentModels = new List <APICommentModel>();

                foreach (CommentDTO childCommentDTO in childCommentDTOs)
                {
                    APICommentModel childAPICommentModel = MapCommentDTOToModel(childCommentDTO);
                    childCommentModels.Add(childAPICommentModel);
                }

                commentModel.ChildCommentModels = childCommentModels;
            }

            return(commentModels);
        }
コード例 #2
0
ファイル: APIModelDataMapper.cs プロジェクト: dashluu/Blog
        public APICommentModel MapCommentDTOToModel(CommentDTO commentDTO)
        {
            if (commentDTO == null)
            {
                return(null);
            }

            APICommentModel commentModel = new APICommentModel()
            {
                CommentId   = commentDTO.CommentId,
                Username    = commentDTO.Username,
                Content     = commentDTO.Content,
                CreatedDate = FormatTime(commentDTO.CreatedDate)
            };

            return(commentModel);
        }