/// <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); }
/// <summary> /// 获取视图博客详情信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public BlogViewModels getBlogDetails(int id) { var bloglist = dal.QueryWhere(a => a.bID > 0).OrderBy(d => d.bID).ToList(); var idmin = bloglist.FirstOrDefault() != null?bloglist.FirstOrDefault().bID : 0; var idmax = bloglist.LastOrDefault() != null?bloglist.LastOrDefault().bID : 1; var idminshow = id; var idmaxshow = id; BlogArticle blogArticle = new BlogArticle(); blogArticle = dal.QueryWhere(a => a.bID == idminshow).FirstOrDefault(); BlogArticle prevblog = new BlogArticle(); while (idminshow > idmin) { idminshow--; prevblog = dal.QueryWhere(a => a.bID == idminshow).FirstOrDefault(); if (prevblog != null) { break; } } BlogArticle nextblog = new BlogArticle(); while (idmaxshow < idmax) { idmaxshow++; nextblog = dal.QueryWhere(a => a.bID == idmaxshow).FirstOrDefault(); if (nextblog != null) { break; } } blogArticle.btraffic += 1; dal.Edit(blogArticle, new string[] { "btraffic" }); dal.SaverChanges(); //AutoMapper自动映射 Mapper.Initialize(cfg => cfg.CreateMap <BlogArticle, BlogViewModels>()); BlogViewModels models = Mapper.Map <BlogArticle, BlogViewModels>(blogArticle); if (nextblog != null) { models.next = nextblog.btitle; models.nextID = nextblog.bID; } if (prevblog != null) { models.previous = prevblog.btitle; models.previousID = prevblog.bID; } models.digest = Tools.ReplaceHtmlTag(blogArticle.bcontent).Length > 100 ? Tools.ReplaceHtmlTag(blogArticle.bcontent).Substring(0, 200) : Tools.ReplaceHtmlTag(blogArticle.bcontent); return(models); }