Exemple #1
0
        /// <summary>
        /// 添加博客标签链接
        /// </summary>
        /// <param name="bl"></param>
        /// <returns></returns>
        public IActionResult AddorUpdateBlogArticle(BlogArticleDto blogArticleDto)
        {
            var resModel     = new ResponseModel();
            var handleResult = _blogArticleBLL.AddOrUpdateArticlelist(blogArticleDto, _userAccount.GetUserInfo().UserId);

            resModel.RetCode = handleResult.Result ? StatesCode.success : StatesCode.failure;
            resModel.RetMsg  = handleResult.Msg;
            resModel.Data    = handleResult.Data;
            return(Ok(resModel));
        }
Exemple #2
0
        /// <summary>
        /// 添加/修改文章
        /// </summary>
        /// <param name="blogArticleDto"></param>
        /// <param name="onLineUserId"></param>
        /// <returns></returns>
        public HandleResult <bool> AddOrUpdateArticlelist(BlogArticleDto blogArticleDto, string onLineUserId)
        {
            var handleResult = new HandleResult <bool>();
            var blogArticle  = Mapper.Map <BlogArticle>(blogArticleDto);

            //是否置顶
            if (blogArticleDto.ArticleTop)
            {
                int intMaxArticleSort = _blogArticle.GetMaxArticleSortValue();
                if (intMaxArticleSort != blogArticle.ArticleSortValue)
                {
                    blogArticle.ArticleSortValue = intMaxArticleSort + 1;
                }
            }
            else
            {
                blogArticle.ArticleSortValue = 0;
            }
            if (blogArticle.ArticleId == 0)//新增
            {
                blogArticle.CreateTime   = DateTime.Now;
                blogArticle.CreateUserId = onLineUserId;
                //添加文章
                _blogArticle.Add(blogArticle);
                if (_blogArticle.SaveChanges())
                {
                    //添加文章标签关联表
                    foreach (var lableId in blogArticleDto.LableId)
                    {
                        _blogRelated.Add(new BlogRelated
                        {
                            RelatedArticleId = blogArticle.ArticleId,
                            RelatedLableId   = lableId
                        });
                    }
                    if (_blogRelated.SaveChanges())
                    {
                        handleResult.Msg = "文章添加成功";
                    }
                    else
                    {
                        handleResult.Msg    = "文章添加成功,文章标签添加失败!";
                        handleResult.Result = false;
                    }
                }
                else
                {
                    handleResult.Msg    = "文章添加失败";
                    handleResult.Result = false;
                }
            }
            else
            {
                var blogArticleUpdate = _blogArticle.GetModels(t => t.ArticleId == blogArticle.ArticleId).First();
                blogArticleUpdate.ArticleTitle       = blogArticle.ArticleTitle;
                blogArticleUpdate.ArticleThrink      = blogArticle.ArticleThrink;
                blogArticleUpdate.ArticleBody        = blogArticle.ArticleBody;
                blogArticleUpdate.ArticleBodySummary = blogArticle.ArticleBodySummary;
                blogArticleUpdate.ArticleSortValue   = blogArticle.ArticleSortValue;
                blogArticleUpdate.EditTime           = DateTime.Now;
                _blogArticle.Update(blogArticleUpdate);
                _blogRelated.Delete(t => t.RelatedArticleId == blogArticle.ArticleId);
                //添加文章标签关联表
                foreach (var lableId in blogArticleDto.LableId)
                {
                    _blogRelated.Add(new BlogRelated
                    {
                        RelatedArticleId = blogArticle.ArticleId,
                        RelatedLableId   = lableId
                    });
                }
                if (_blogRelated.SaveChanges())
                {
                    handleResult.Msg = "文章修改成功";
                }
                else
                {
                    handleResult.Msg    = "文章修改成功";
                    handleResult.Result = false;
                }
            }
            return(handleResult);
        }
        public BlogArticleDto Update(BlogArticleDto entity)
        {
            var v = Mapper.Map <BlogArticleEntity>(entity);

            return(Mapper.Map <BlogArticleDto>(_repository.Update(v)));
        }
        public BlogArticleDto Insert(BlogArticleDto entity)
        {
            var v = Mapper.Map <BlogArticleEntity>(entity);

            return(Mapper.Map <BlogArticleDto>(_repository.Insert(v)));
        }