/// <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); }
public BlogViewModels getBlogDetails(int id) { BlogArticle blogArticle = iblog.QueryWhere(p => p.bID == id).FirstOrDefault(); BlogArticle preBlog = iblog.QueryWhere(p => p.bID == id - 1).FirstOrDefault(); BlogArticle nextBolg = iblog.QueryWhere(p => p.bID == id + 1).FirstOrDefault(); blogArticle.btraffic++; iblog.Edit(blogArticle, new string[] { "btraffic" }); iblog.SaveChanges(); //AutoMapper自动映射 Mapper.Initialize(p => p.CreateMap <BlogArticle, BlogViewModels>()); BlogViewModels models = Mapper.Map <BlogArticle, BlogViewModels>(blogArticle); if (nextBolg != null) { models.next = nextBolg.btitle; models.nextID = nextBolg.bID; } if (preBlog != null) { models.previous = preBlog.btitle; models.previousID = preBlog.bID; } models.digest = blogArticle.bcontent.Length > 100 ? blogArticle.bcontent.Substring(0, 100) : blogArticle.bcontent; 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); }