Exemple #1
0
 public ActionResult GetPosts([FromQuery] int offset, [FromQuery] int count)
 {
     try
     {
         var posts = postsRepository.GetPosts(offset, count)
                     .Select(p => new PostDto(p, albumsRepository.GetAlbumAttachment(p.AlbumId))).ToArray();
         var response = new PostsResponse(posts, postsRepository.PostsCount);
         return(new JsonResult(response));
     }
     catch (Exception x)
     {
         return(new ContentResult
         {
             Content = x.ToString(),
             StatusCode = (int)HttpStatusCode.InternalServerError,
             ContentType = "text/plain"
         });
     }
 }
Exemple #2
0
        /// <summary>
        /// 帖子内容阅读
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult Read(string id)
        {
            int postsId = Framework.Core.Transform.GetInt(id, 0);

            ViewModels.PostsReadViewModel model = new ViewModels.PostsReadViewModel();
            if (postsId != 0)
            {
                PostsRepository repository = new PostsRepository();
                model.PostsData = repository.GetPosts(postsId)[0];
                int pageSize  = 10;
                int pageIndex = Framework.Core.Transform.GetInt(Request.Query["p"], 1);

                var query = repository.GetAnswerPageList();
                model.AnswerListData = query.Where(m => m.PostsId == postsId).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
                model.TotalCount     = query.Where(m => m.PostsId == postsId).Count();
                //加载帖子频道
                Common.PostsChannel postsProperty = new Common.PostsChannel();
                model.PostsChannelData = postsProperty.GetListByCache();
                //加载热门帖子
                model.HotListData = repository.GetPostsListByHot().OrderByDescending(m => m.PlusCount).Where(m => m.PostDate >= DateTime.Now.AddDays(-7)).Skip(0).Take(10).ToList();
            }
            return(View(model));
        }
        public IActionResult Index()
        {
            var repo = new PostsRepository(_connectionString);

            return(View(repo.GetPosts()));
        }
        // GET: Posts
        public ActionResult Index()
        {
            var posts = postRepository.GetPosts();

            return(View(posts));
        }