示例#1
0
        /// <summary>
        /// 获取视图博客详情信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BlogViewModel getBlogDetails(string id)
        {
            BlogArticle blogArticle = dal.QueryWhere(a => a.id == id).FirstOrDefault();
            BlogArticle nextblog    = dal.QueryWhere(a => a.id == id).FirstOrDefault();
            BlogArticle prevblog    = dal.QueryWhere(a => a.id == id).FirstOrDefault();

            blogArticle.traffic += 1;
            dal.Edit(blogArticle, new string[] { "traffic" });
            dal.SaverChanges();
            //AutoMapper自动映射
            Mapper.Initialize(cfg => cfg.CreateMap <BlogArticle, BlogViewModel>());
            BlogViewModel models = Mapper.Map <BlogArticle, BlogViewModel>(blogArticle);

            if (nextblog != null)
            {
                models.next    = nextblog.title;
                models.next_id = nextblog.id;
            }

            if (prevblog != null)
            {
                models.previous    = prevblog.title;
                models.previous_id = prevblog.id;
            }
            models.digest = HtmlTool.ReplaceHtmlTag(blogArticle.content).Length > 100 ? HtmlTool.ReplaceHtmlTag(blogArticle.content).Substring(0, 200) : HtmlTool.ReplaceHtmlTag(blogArticle.content);
            return(models);
        }
示例#2
0
        /// <summary>
        /// 初始化autoMapper 映射
        /// </summary>
        public static void MapperConfigIntit()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <User, UserDto>().ForMember(dto => dto.CreateDate, opt => opt.MapFrom(src => src.CreateDate.ToString(DateTimeFormString)));

                cfg.CreateMap <Category, CategoryDto>();

                cfg.CreateMap <Blog, BlogDto>().ForMember(dto => dto.CreateDate, opt => opt.MapFrom(src => src.CreateDate.ToString(DateTimeFormString)))
                .ForMember(dto => dto.BodyAbs, opt => opt.MapFrom(src => HtmlTool.ReplaceHtmlTag(src.Body, 200)));
                cfg.CreateMap <BlogComment, BlogCommentDto>().ForMember(dto => dto.PostDate, opt => opt.MapFrom(src => src.PostDate.ToString(DateTimeFormString)));

                cfg.CreateMap <News, NewsDto>().ForMember(dto => dto.CreateDate, opt => opt.MapFrom(src => src.CreateDate.ToString(DateTimeFormString)))
                .ForMember(dto => dto.BodyAbs, opt => opt.MapFrom(src => HtmlTool.ReplaceHtmlTag(src.Body, 200)));
                cfg.CreateMap <NewsComment, NewsCommentDto>().ForMember(dto => dto.PostDate, opt => opt.MapFrom(src => src.PostDate.ToString(DateTimeFormString)));

                cfg.CreateMap <OpenSource, OpenSourceDto>().ForMember(dto => dto.CreateDate, opt => opt.MapFrom(src => src.CreateDate.ToString(DateTimeFormString)));

                cfg.CreateMap <Note, NoteDto>().ForMember(dto => dto.CreateDate, opt => opt.MapFrom(src => src.CreateDate.ToString(DateTimeFormString)));
            });
        }
示例#3
0
        public ActionResult Index(int pageindex = 1)
        {
            //获取控制器名称
            ViewBag.controllername = RouteData.Values["controller"].ToString().ToLower();

            int pagesize = 6;
            //获取发布博文信息
            var blogArticleList = BlogArticleService.QueryWhere(a => true).OrderByDescending(a => a.create_time).ToPagedList(pageindex, pagesize);

            foreach (var item in blogArticleList)
            {
                if (!string.IsNullOrEmpty(item.content))
                {
                    item.content = HtmlTool.ReplaceHtmlTag(item.content);
                    if (item.content.Length > 200)
                    {
                        item.content = item.content.Substring(0, 200);
                    }
                }
            }
            //获取轮播广告新
            ViewBag.adList = AdvertisementServices.QueryOrderBy(a => true, a => a.create_time, false).ToPagedList(1, 3);
            //发布时间排序
            ViewBag.blogtimelist = BlogArticleService.QueryOrderBy(c => true, c => c.create_time, false);
            //评论排序
            ViewBag.blogtrafficlist = BlogArticleService.QueryOrderBy(c => true, c => c.traffic, false);

            //留言排序
            string sql = @"select a.*,b.title from (select blog_id,count(1) as counts  from guest_book group by blog_id) as a
inner join blog_article as b
on
b.id=a.blog_id order by counts desc";

            ViewBag.blogguestbooklist = GuestbookService.RunProc <TopgbViewModel>(sql);


            return(View(blogArticleList));
        }