コード例 #1
0
        // GET: Main
        public ActionResult Index()
        {
            var posts          = postService.GetPublishedPosts();
            var postsViewModel = mapper.Map <List <MainPostViewModel> >(posts);

            foreach (var item in postsViewModel)
            {
                var fullname = profileService.FindFullName(item.UserId);

                item.FullName = new FullNameViewModel {
                    FirstName = fullname.FirstName, LastName = fullname.LastName
                };

                item.CommentsCount = commentService.GetCommentsCount(item.Id);
            }
            return(View(postsViewModel));
        }
コード例 #2
0
        public IViewComponentResult Invoke(int id, string userId)
        {
            var comments = commentService.GetComments(id);

            if (comments != null)
            {
                var commentsViewModel = mapper.Map <List <CommentViewModel> >(comments);

                if (userId != null)
                {
                    foreach (var item in commentsViewModel)
                    {
                        var fullname = profileService.FindFullName(item.UserId);

                        item.FullName = new FullNameViewModel {
                            FirstName = fullname.FirstName, LastName = fullname.LastName
                        };

                        item.UserLike = likeService.UserLike(item.Id, userId);

                        item.Count = likeService.GetCountLikes(item.Id);
                    }
                }
                else
                {
                    foreach (var item in commentsViewModel)
                    {
                        var fullname = profileService.FindFullName(item.UserId);

                        item.FullName = new FullNameViewModel {
                            FirstName = fullname.FirstName, LastName = fullname.LastName
                        };

                        item.Count = likeService.GetCountLikes(item.Id);
                    }
                }
                return(View(commentsViewModel));
            }
            else
            {
                return(null);
            }
        }