示例#1
0
 public void LogicDelete(int id)
 {
     using (var unitOfWork = _unitOfWorkFactory.GetCurrentUnitOfWork())
     {
         var info = _articleRepository.Get(id);
         info.Status   = Enums.Status.Delete;
         info.EditUser = LoginUserSection.CurrentUser.LoginName;
         info.EditDate = _currentTimeProvider.CurrentTime();
         _articleRepository.Update(info);
         unitOfWork.Commit();
     }
 }
        /// <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);
        }
示例#3
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 void Update_Blog_Test()
        {
            var IsUpd       = false;
            var updateModel = (await baseRepository.Query(d => d.btitle == "xuint test title")).FirstOrDefault();

            Assert.NotNull(updateModel);

            updateModel.bcontent    = "xuint: test repositoryBase content update";
            updateModel.bCreateTime = DateTime.Now;
            updateModel.bUpdateTime = DateTime.Now;

            IsUpd = await baseRepository.Update(updateModel);

            Assert.True(IsUpd);
        }
示例#5
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);
        }
示例#6
0
        public async Task <BlogViewModels> GetBlogDetails(int id)
        {
            var bloglist = await dal.Query(s => s.bID > 0, s => s.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;

            var blogArticle = new BlogArticle();

            blogArticle = (await dal.Query(s => s.bID == idMinShow)).FirstOrDefault();

            var preBlog = new BlogArticle();

            while (idMinShow > idMin)
            {
                idMinShow--;
                preBlog = (await dal.Query(s => s.bID == idMinShow)).FirstOrDefault();

                if (preBlog != null)
                {
                    break;
                }
            }

            var nextBlog = new BlogArticle();

            while (idMaxShow < idMax)
            {
                idMaxShow++;
                nextBlog = (await dal.Query(s => s.bID == idMaxShow)).FirstOrDefault();

                if (nextBlog != null)
                {
                    break;
                }
            }

            blogArticle.btraffic += 1;

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

            var models = IMapper.Map <BlogViewModels>(blogArticle);

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

            if (preBlog != null)
            {
                models.previous   = preBlog.btitle;
                models.previousID = preBlog.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);
        }
示例#8
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);
        }
示例#9
0
        public async Task <BlogViewModel> GetBlogDetails(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"
            });

            //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,
            //};

            BlogViewModel models = _mapper.Map <BlogViewModel>(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);
        }
示例#10
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);
        }