예제 #1
0
        /// <summary>
        /// 获取视图博客详情信息(一般版本)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BlogViewModels> getBlogDetails(int id)
        {
            var bloglist = await dal.Query(a => a.Id > 0, a => a.Id);

            var            blogArticle = (await dal.Query(a => a.Id == id)).FirstOrDefault();
            BlogViewModels models      = null;

            if (blogArticle != null)
            {
                BlogArticle prevblog;
                BlogArticle nextblog;
                int         blogIndex = bloglist.FindIndex(item => item.Id == id);
                if (blogIndex >= 0)
                {
                    try
                    {
                        // 上一篇
                        prevblog = blogIndex > 0 ? (((BlogArticle)(bloglist[blogIndex - 1]))) : null;
                        // 下一篇
                        nextblog = blogIndex + 1 < bloglist.Count() ? (BlogArticle)(bloglist[blogIndex + 1]) : null;

                        // 注意就是这里,mapper
                        models = IMapper.Map <BlogViewModels>(blogArticle);

                        #region 旧代码
                        //models = new BlogViewModels()
                        //{
                        //    Submitter = blogArticle.Submitter,
                        //    Title = blogArticle.Title,
                        //    Category = blogArticle.Category,
                        //    Content = blogArticle.Content,
                        //    Traffic = blogArticle.Traffic,
                        //    CommentNum = blogArticle.CommentNum,
                        //    ModifyTime = blogArticle.ModifyTime,
                        //    CreateTime = blogArticle.CreateTime,
                        //    Remark = blogArticle.Remark,
                        //};
                        #endregion

                        if (nextblog != null)
                        {
                            models.Next   = nextblog.Title;
                            models.NextId = nextblog.Id;
                        }
                        if (prevblog != null)
                        {
                            models.Previous   = prevblog.Title;
                            models.PreviousId = prevblog.Id;
                        }
                    }
                    catch (Exception) { }
                }
                blogArticle.Traffic += 1;
                await dal.Update(blogArticle, new List <string> {
                    "Traffic"
                });
            }

            return(models);
        }
예제 #2
0
        /// <summary>
        /// 获取视图博客详情信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BlogViewModels> getBlogDetails(int id)
        {
            var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);

            var blogArticle = (await dal.Query(a => a.bID == id)).FirstOrDefault();

            BlogViewModels models = null;

            if (blogArticle != null)
            {
                BlogArticle prevblog;
                BlogArticle nextblog;


                int blogIndex = bloglist.FindIndex(item => item.bID == id);
                if (blogIndex >= 0)
                {
                    try
                    {
                        prevblog = blogIndex > 0 ? (((BlogArticle)(bloglist[blogIndex - 1]))) : null;
                        nextblog = blogIndex + 1 < bloglist.Count() ? (BlogArticle)(bloglist[blogIndex + 1]) : null;


                        // 注意就是这里,mapper
                        models = IMapper.Map <BlogViewModels>(blogArticle);

                        if (nextblog != null)
                        {
                            models.next   = nextblog.btitle;
                            models.nextID = nextblog.bID;
                        }

                        if (prevblog != null)
                        {
                            models.previous   = prevblog.btitle;
                            models.previousID = prevblog.bID;
                        }
                    }
                    catch (Exception) { }
                }


                blogArticle.btraffic += 1;
                await dal.Update(blogArticle, new List <string> {
                    "btraffic"
                });
            }

            return(models);
        }
        public async Task <IActionResult> GetHateoas()
        {
            var blogList = await _blogArticleRepository.Query();

            var blogViewModels = _mapper.Map <IEnumerable <BlogArticle>, IEnumerable <BlogArticleViewModel> >(blogList);



            return(Ok(blogViewModels));
        }
예제 #4
0
        /// <summary>
        /// 获取视图博客详情信息(一般版本)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BlogViewModels> GetBlogDetails(int id)
        {
            // 此处想获取上一条下一条数据,因此将全部数据list出来,有好的想法请提出
            var bloglist = await base.Query(a => a.bID > 0, a => a.bID);

            var            blogArticle = (await _dal.Query(a => a.bID == id)).FirstOrDefault();
            BlogViewModels models      = null;

            if (blogArticle != null)
            {
                BlogArticle prevblog;
                BlogArticle nextblog;
                int         blogIndex = bloglist.FindIndex(item => item.bID == id);
                if (blogIndex >= 0)
                {
                    try
                    {
                        //上一篇
                        prevblog = blogIndex > 0 ? bloglist[blogIndex - 1] : null;
                        //下一篇
                        nextblog = blogIndex + 1 < bloglist.Count() ? bloglist[blogIndex + 1] : null;
                        models   = _mapper.Map <BlogViewModels>(blogArticle);
                        if (nextblog != null)
                        {
                            models.next   = nextblog.btitle;
                            models.nextID = nextblog.bID;
                        }
                        if (prevblog != null)
                        {
                            models.previous   = prevblog.btitle;
                            models.previousID = prevblog.bID;
                        }
                    }
                    catch (Exception) { }
                }
                blogArticle.btraffic += 1;
                await _dal.Update(blogArticle, new List <string> {
                    "btraffic"
                });
            }
            return(models);
        }
예제 #5
0
        [Caching(AbsoluteExpiration = 10)]//增加特性
        public async Task <List <BlogArticle> > GetBlogs()
        {
            var blogList = await dal.Query(s => s.bID > 0, s => s.bID);

            return(blogList);
        }
예제 #6
0
        public async void Get_Blogs_Test()
        {
            var data = await baseRepository.Query();

            Assert.NotNull(data);
        }
        public async Task <List <BlogArticle> > getBlogs()
        {
            var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);

            return(bloglist);
        }
        /// <summary>
        /// 获取视图博客详情信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BlogViewModels> getBlogDetails(int id)
        {
            var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);

            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 = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();

            BlogArticle prevblog = new BlogArticle();


            while (idminshow > idmin)
            {
                idminshow--;
                prevblog = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();
                if (prevblog != null)
                {
                    break;
                }
            }

            BlogArticle nextblog = new BlogArticle();

            while (idmaxshow < idmax)
            {
                idmaxshow++;
                nextblog = (await dal.Query(a => a.bID == idmaxshow)).FirstOrDefault();
                if (nextblog != null)
                {
                    break;
                }
            }


            blogArticle.btraffic += 1;
            await dal.Update(blogArticle, new List <string> {
                "btraffic"
            });

            //注意就是这里
            BlogViewModels models = IMapper.Map <BlogViewModels>(blogArticle);

            if (nextblog != null)
            {
                models.next   = nextblog.btitle;
                models.nextID = nextblog.bID;
            }

            if (prevblog != null)
            {
                models.previous   = prevblog.btitle;
                models.previousID = prevblog.bID;
            }
            return(models);
        }
        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BlogViewModel> getBlogDetails(int id)
        {
            var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);

            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 = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();

            BlogArticle prevblog = new BlogArticle();


            while (idminshow > idmin)
            {
                idminshow--;
                prevblog = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();
                if (prevblog != null)
                {
                    break;
                }
            }

            BlogArticle nextblog = new BlogArticle();

            while (idmaxshow < idmax)
            {
                idmaxshow++;
                nextblog = (await dal.Query(a => a.bID == idmaxshow)).FirstOrDefault();
                if (nextblog != null)
                {
                    break;
                }
            }


            blogArticle.btraffic += 1;
            await dal.Update(blogArticle, new List <string> {
                "btraffic"
            });

            BlogViewModel models = _mapper.Map <BlogViewModel>(blogArticle);

            //BlogViewModel models = new BlogViewModel()
            //{
            //    bsubmitter = blogArticle.bsubmitter,
            //    btitle = blogArticle.btitle,
            //    bcategory = blogArticle.bcategory,
            //    bcontent = blogArticle.bcontent,
            //    btraffic = blogArticle.btraffic,
            //    bcommentNum = blogArticle.bcommentNum,
            //    bUpdateTime = blogArticle.bUpdateTime,
            //    bCreateTime = blogArticle.bCreateTime,
            //    bRemark = blogArticle.bRemark,
            //};

            if (nextblog != null)
            {
                models.next   = nextblog.btitle;
                models.nextID = nextblog.bID;
            }

            if (prevblog != null)
            {
                models.previous   = prevblog.btitle;
                models.previousID = prevblog.bID;
            }
            return(models);
        }
예제 #10
0
        /// <summary>
        /// 获取视图博客详情信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BlogViewModels> getBlogDetails(int id)
        {
            //不用automapper的写法
            //var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);
            //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 = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();

            //BlogArticle prevblog = new BlogArticle();


            //while (idminshow > idmin)
            //{
            //    idminshow--;
            //    prevblog = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();
            //    if (prevblog != null)
            //    {
            //        break;
            //    }
            //}

            //BlogArticle nextblog = new BlogArticle();
            //while (idmaxshow < idmax)
            //{
            //    idmaxshow++;
            //    nextblog = (await dal.Query(a => a.bID == idmaxshow)).FirstOrDefault();
            //    if (nextblog != null)
            //    {
            //        break;
            //    }
            //}


            //blogArticle.btraffic += 1;
            //await dal.Update(blogArticle, new List<string> { "btraffic" });

            //BlogViewModels models = new BlogViewModels()
            //{
            //    bsubmitter = blogArticle.bsubmitter,
            //    btitle = blogArticle.btitle,
            //    bcategory = blogArticle.bcategory,
            //    bcontent = blogArticle.bcontent,
            //    btraffic = blogArticle.btraffic,
            //    bcommentNum = blogArticle.bcommentNum,
            //    bUpdateTime = blogArticle.bUpdateTime,
            //    bCreateTime = blogArticle.bCreateTime,
            //    bRemark = blogArticle.bRemark,
            //};

            //if (nextblog != null)
            //{
            //    models.next = nextblog.btitle;
            //    models.nextID = nextblog.bID;
            //}

            //if (prevblog != null)
            //{
            //    models.previous = prevblog.btitle;
            //    models.previousID = prevblog.bID;
            //}
            //return models;

            //使用automapper的写法
            var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);

            var            blogArticle = (await dal.Query(a => a.bID == id)).FirstOrDefault();
            BlogViewModels models      = null;

            if (blogArticle != null)
            {
                BlogArticle prevblog;
                BlogArticle nextblog;
                int         blogIndex = bloglist.FindIndex(item => item.bID == id);
                if (blogIndex >= 0)
                {
                    try
                    {
                        // 上一篇
                        prevblog = blogIndex > 0 ? (((BlogArticle)(bloglist[blogIndex - 1]))) : null;
                        // 下一篇
                        nextblog = blogIndex + 1 < bloglist.Count() ? (BlogArticle)(bloglist[blogIndex + 1]) : null;

                        // 注意就是这里,mapper
                        models = _mapper.Map <BlogViewModels>(blogArticle);

                        if (nextblog != null)
                        {
                            models.next   = nextblog.btitle;
                            models.nextID = nextblog.bID;
                        }
                        if (prevblog != null)
                        {
                            models.previous   = prevblog.btitle;
                            models.previousID = prevblog.bID;
                        }
                    }
                    catch (Exception) { }
                }
                blogArticle.btraffic += 1;
                await dal.Update(blogArticle, new List <string> {
                    "btraffic"
                });
            }

            return(models);
        }
예제 #11
0
        /// <summary>
        /// 获取博客列表
        /// </summary>
        /// <returns></returns>
        public async Task <List <BlogArticle> > GetBlogs()
        {
            var blogList = await _blogArticleRepository.Query(a => a.BId > 0, a => a.BId);

            return(blogList);
        }
예제 #12
0
        /// <summary>
        /// 获取视图博客详情信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BlogViewModels> GetBlogDetailsAsync(int id)
        {
            var bloglist = await _blogArticleRepository.Query(a => a.bID > 0, a => a.bID);

            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 = (await _blogArticleRepository.Query(a => a.bID == idminshow)).FirstOrDefault();

            BlogArticle prevblog = new BlogArticle();


            while (idminshow > idmin)
            {
                idminshow--;
                prevblog = (await _blogArticleRepository.Query(a => a.bID == idminshow)).FirstOrDefault();
                if (prevblog != null)
                {
                    break;
                }
            }

            BlogArticle nextblog = new BlogArticle();

            while (idmaxshow < idmax)
            {
                idmaxshow++;
                nextblog = (await _blogArticleRepository.Query(a => a.bID == idmaxshow)).FirstOrDefault();
                if (nextblog != null)
                {
                    break;
                }
            }


            blogArticle.btraffic += 1;
            await _blogArticleRepository.Update(blogArticle, new List <string> {
                "btraffic"
            }, null, " bID == " + blogArticle.bID.ToString());

            BlogViewModels models = new BlogViewModels()
            {
                bsubmitter  = blogArticle.bsubmitter,
                btitle      = blogArticle.btitle,
                bcategory   = blogArticle.bcategory,
                bcontent    = blogArticle.bcontent,
                btraffic    = blogArticle.btraffic,
                bcommentNum = blogArticle.bcommentNum,
                bUpdateTime = blogArticle.bUpdateTime,
                bCreateTime = blogArticle.bCreateTime,
                bRemark     = blogArticle.bRemark,
            };

            if (nextblog != null)
            {
                models.next   = nextblog.btitle;
                models.nextID = nextblog.bID;
            }

            if (prevblog != null)
            {
                models.previous   = prevblog.btitle;
                models.previousID = prevblog.bID;
            }
            return(models);
        }