Пример #1
0
        public void PrepareDetailPostData(PostGeneralViewModel p, string curUserId)
        {
            var _postService        = this.Service <IPostService>();
            var _likeService        = this.Service <ILikeService>();
            var _postCommentService = this.Service <IPostCommentService>();
            var _postSportService   = this.Service <IPostSportService>();
            var _userService        = this.Service <IAspNetUserService>();

            //like
            List <Like> likeList = _likeService.GetLikeListByPostId(p.Id).ToList();

            p.LikeCount = likeList.Count();
            foreach (var item in likeList)
            {
                if (item.UserId == curUserId)
                {
                    p.Liked = true;
                }
                else
                {
                    p.Liked = false;
                }
            }

            //comment
            List <PostComment> postCmtList = _postCommentService.GetCommentListByPostId(p.Id, 0, 3).ToList();

            p.PostAge      = _postService.CalculatePostAge(p.EditDate == null ? p.CreateDate : p.EditDate.Value);
            p.PostComments = Mapper.Map <List <PostCommentDetailViewModel> >(postCmtList);
            p.CommentCount = _postCommentService.GetActive(c => c.PostId == p.Id).ToList().Count();
            foreach (var item in p.PostComments)
            {
                //DateTime dt = DateTime.ParseExact(item.CreateDateString, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                item.CommentAge = _postCommentService.CalculateCommentAge(item.CreateDate);
            }

            //sport
            List <PostSport> postSportList = _postSportService.GetActive(s => s.PostId == p.Id).ToList();

            p.PostSports = Mapper.Map <List <PostSportDetailViewModel> >(postSportList);

            //profile
            if (p.ProfileId != null)
            {
                var tmpUser = _userService.FirstOrDefaultActive(o => o.Id == p.ProfileId);
                p.Profile = Mapper.Map <AspNetUserSimpleModel>(tmpUser);
            }
        }
        public ActionResult LoadSavedPost(String postId)
        {
            int  id           = Int32.Parse(postId);
            var  result       = new AjaxOperationResult <PostGeneralViewModel>();
            var  _postService = this.Service <IPostService>();
            Post tmp          = _postService.FirstOrDefaultActive(p => p.Id == id);

            if (tmp != null)
            {
                var _userService = this.Service <IAspNetUserService>();
                PostGeneralViewModel postGeneral = Mapper.Map <PostGeneralViewModel>(tmp);
                var user = Mapper.Map <AspNetUserSimpleModel>(_userService.Get <string>(postGeneral.UserId));
                postGeneral.AspNetUser = user;
                PrepareDetailPostData(postGeneral, User.Identity.GetUserId());
                result.AdditionalData = postGeneral;
                result.Succeed        = true;
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }