コード例 #1
0
        //public IActionResult KeyNote(long postId)
        //{
        //    var result = _postDetialView.Execute(new PostDetailDataBind { PostId = postId });

        //    if (result == null)
        //    {
        //        RedirectToAction("Error", "Home");
        //    }
        //    TagCloudDataBind tagCloudDataBind = new TagCloudDataBind();
        //    var tagResult = _tagCloudView.Execute(tagCloudDataBind);
        //    Tuple<PostDetialViewModel, List<TagCloudViewModel>> tuple = new Tuple<PostDetialViewModel, List<TagCloudViewModel>>(result, tagResult);
        //    return View(tuple);

        //}

        public IActionResult Index(int page = 1, int pageSize = 10)
        {
            PostListDataBind postListDataBind = new PostListDataBind();

            postListDataBind.PageIndex = page;
            postListDataBind.PageSize  = pageSize;
            TagCloudDataBind tagCloudDataBind = new TagCloudDataBind();
            var tagResult   = _tagCloudView.Execute(tagCloudDataBind);
            var resultModel = _postListView.Execute(postListDataBind);
            //var ipAddr = _netWorkTool.GetRemoteIp();
            Tuple <PageInfo <PostListViewModel>, List <TagCloudViewModel> > tuple = new Tuple <PageInfo <PostListViewModel>, List <TagCloudViewModel> >(resultModel, tagResult);

            return(View(tuple));
        }
コード例 #2
0
        public PageInfo <PostListViewModel> Execute(PostListDataBind command)
        {
            try
            {
                const string countSql = "select count(1) from post p ";
                const string sql      = "select p.post_id,p.post_content_preview,p.post_date,p.post_title,p.layout_type from post p ORDER BY p.post_date DESC LIMIT @startIndex,@pagesize ";
                using (var conn = _dapperConnection.GetDataBaseConnection())
                {
                    var count  = conn.QueryFirstOrDefault <int>(countSql);
                    var result = conn.Query <Post>(sql, new { startIndex = (command.PageIndex - 1) * command.PageSize, pagesize = command.PageSize });
                    PageInfo <PostListViewModel> resultViewModel = new PageInfo <PostListViewModel>();
                    resultViewModel.CurrentPage     = command.PageIndex;
                    resultViewModel.CurrentPageSize = command.PageSize;
                    resultViewModel.TotalPage       = (int)Math.Ceiling((double)count / command.PageSize);
                    resultViewModel.TotalRecord     = count;

                    if (result != null)
                    {
                        List <PostListViewModel> modelList = new List <PostListViewModel>();
                        foreach (var item in result)
                        {
                            PostListViewModel model = new PostListViewModel();
                            model.PostContentPreview = item.PostContentPreview;
                            model.PostCreateTime     = item.PostDate.ToString("yyyy-MM-dd HH:mm:ss");
                            model.PostId             = item.PostId;
                            model.PostTitle          = item.PostTitle;
                            model.PostLayout         = item.LayoutType;
                            modelList.Add(model);
                        }
                        resultViewModel.Value = modelList;
                    }
                    return(resultViewModel);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("请求博客列表出现异常,异常信息为{0}", ex));
                return(null);
            }
        }