示例#1
0
        private CommentViewModel GetCommentViewModel(CommentEntity commentEntity, ApplicationUserEntity applicationUserCurrent)
        {
            var commentViewModel                = mapper.Map <CommentEntity, CommentViewModel>(commentEntity);
            var applicationUserForComment       = repositoryOfUserProfile.Read(a => a.Id == commentEntity.UserProfileId, a => a.ApplicationUser).ApplicationUser;
            UserMiniViewModel userMiniViewModel = mapper.Map <ApplicationUserEntity, UserMiniViewModel>(applicationUserForComment);

            commentViewModel.BelongsToUser           = (applicationUserCurrent == null) ? false : applicationUserCurrent.UserProfileId == commentEntity.UserProfileId;
            commentViewModel.AuthorUserMiniViewModel = serviceOfUser.GetUserMiniViewModel(applicationUserForComment);
            commentViewModel.IsUserLiked             = (applicationUserCurrent == null) ? false : IsCommentLike(commentEntity, applicationUserCurrent.UserProfileId.Value);
            return(commentViewModel);
        }
示例#2
0
        private PostCompactViewModel GetPostCompactViewModel(PostEntity postEntity, ApplicationUserEntity applicationUserCurrent)
        {
            var postViewModel       = mapper.Map <PostEntity, PostCompactViewModel>(postEntity);
            var applicationUserPost = repositoryOfApplicationUser.Read(a => a.UserProfileId == postEntity.UserProfileId);

            postViewModel.AuthorUserMiniViewModel = serviceOfUser.GetUserMiniViewModel(applicationUserPost);
            postViewModel.BelongsToUser           = (applicationUserCurrent == null)
                ? false
                : applicationUserCurrent.UserProfileId == postEntity.UserProfileId;
            postViewModel.FirstImage = (postEntity.Images == null)
                ? repositoryOfImage.ReadMany(new Expression <Func <ImageEntity, bool> >[] { a => a.PostId == postEntity.Id }, null).FirstOrDefault()?.Path
                : postEntity.Images.FirstOrDefault().Path;
            return(postViewModel);
        }