public static CommentDetailModel MapToDetailModel(Comment comment)
 {
     return(new CommentDetailModel
     {
         Id = comment.Id,
         Author = UserMapper.MapToListModel(comment.Author),
         BelongsTo = PostMapper.MapToListModel(comment.BelongsTo),
         CreationTime = comment.CreationTime,
         Content = comment.Content
     });
 }
 public static Comment MapToEntity(CommentDetailModel commentDetailModel)
 {
     return(new Comment
     {
         Id = commentDetailModel.Id,
         Author = UserMapper.MapListModelToEntity(commentDetailModel.Author),
         BelongsTo = PostMapper.MapListModelToEntity(commentDetailModel.BelongsTo),
         CreationTime = commentDetailModel.CreationTime,
         Content = commentDetailModel.Content
     });
 }
Exemple #3
0
        internal static ActivityDetailModel MapToDetailModel(Activity activity)
        {
            if (activity.GetType() == typeof(Comment))
            {
                return(CommentMapper.MapToDetailModel((Comment)activity));
            }

            if (activity.GetType() == typeof(Post))
            {
                return(PostMapper.MapToListModel((Post)activity));
            }

            throw new Exception("Invalid activity entity to map!");
        }
Exemple #4
0
        public UserDetailModel EntityToDetailModel(UserEntity userEntity)
        {
            if (userEntity == null)
            {
                return(null);
            }

            var userModel = new UserDetailModel
            {
                Email    = userEntity.Email,
                Id       = userEntity.Id,
                Name     = userEntity.Name,
                Password = userEntity.Password,
                Comments = new Collection <CommentModel>(),
                Posts    = new Collection <PostModel>()
            };

            if (userEntity.Comments == null)
            {
                userEntity.Comments = new Collection <CommentEntity>();
            }
            else
            {
                var commentMapper = new CommentMapper();
                foreach (var comment in userEntity.Comments)
                {
                    userModel.Comments.Add(commentMapper.EntityToModel(comment));
                }
            }

            if (userEntity.Posts == null)
            {
                userEntity.Posts = new Collection <PostEntity>();
            }
            else
            {
                foreach (var post in userEntity.Posts)
                {
                    var postMapper = new PostMapper();
                    userModel.Posts.Add(postMapper.EntityToModel(post));
                }
            }

            return(userModel);
        }
Exemple #5
0
        public static Activity MapToEntity(ActivityDetailModel activityDetailModel)
        {
            if (activityDetailModel.GetType() == typeof(CommentDetailModel))
            {
                return(CommentMapper.MapToEntity((CommentDetailModel)activityDetailModel));
            }

            if (activityDetailModel.GetType() == typeof(PostListModel))
            {
                return(PostMapper.MapListModelToEntity((PostListModel)activityDetailModel));
            }
            if (activityDetailModel.GetType() == typeof(PostDetailModel))
            {
                return(PostMapper.MapDetailModelToEntity((PostDetailModel)activityDetailModel));
            }

            throw new Exception("Invalid activity model to map!");
        }