Ejemplo n.º 1
0
        public IActionResult EditArticleCategory(ArticleCategory model)
        {
            if (model.Id <= 0)
            {
                tip.Message = "错误参数传递!";
                Json(tip);
            }
            if (string.IsNullOrWhiteSpace(model.KindName))
            {
                tip.Message = "文章栏目标题不能为空!";
                return(Json(tip));
            }

            ArticleCategory entity = ArticleCategory.Find(ArticleCategory._.Id == model.Id);

            if (entity == null)
            {
                tip.Message = "系统找不到本记录!";
                Json(tip);
            }

            if (!string.IsNullOrEmpty(model.FilePath))
            {
                if (!model.FilePath.StartsWith("/"))
                {
                    tip.Message = "栏目路径请以/开头!";
                    return(Json(tip));
                }
                if (model.FilePath.EndsWith("/"))
                {
                    tip.Message = "栏目路径结尾不用加上/";
                    return(Json(tip));
                }

                if (model.FilePath.Count(x => x == '/') > 4)
                {
                    tip.Message = "最多只能四级路径!";
                    return(Json(tip));
                }
            }



            if (!string.IsNullOrEmpty(model.FilePath) && !AdminUtils.CheckFilePathIsOK(model.FilePath, entity.Id, 0))
            {
                tip.Message = "栏目路径不可用,请重新填写!";
                return(Json(tip));
            }

            if (entity.PId != model.PId)
            {
                if (entity.Id == model.PId)
                {
                    tip.Message = "上级栏目不能选择本身!";
                    return(Json(tip));
                }
                entity.PId      = model.PId;
                entity.Location = ArticleCategory.GetNewLocation(model.PId);
                entity.Level    = ArticleCategory.GetNewLevel(model.PId);
                //修改文章的location
                IList <Article> alist = Article.FindAll(Article._.KId == model.Id, null, null, 0, 0);
                if (alist != null && alist.Count > 0)
                {
                    foreach (var a in alist)
                    {
                        a.Location = entity.Location + "," + entity.Id;
                        //a.FilePath = entity.FilePath;
                    }
                    alist.Save();
                }
            }
            bool idNeedUpdateAllArticleFilePath = entity.FilePath == model.FilePath;

            //赋值
            entity.PId                = model.PId;
            entity.KindName           = model.KindName;
            entity.SubTitle           = model.SubTitle;
            entity.KindTitle          = model.KindTitle;
            entity.Keyword            = model.Keyword;
            entity.Description        = model.Description;
            entity.LinkURL            = model.LinkURL;
            entity.TitleColor         = model.TitleColor;
            entity.TemplateFile       = model.TemplateFile;
            entity.DetailTemplateFile = model.DetailTemplateFile;
            entity.IsList             = model.IsList;
            entity.PageSize           = model.PageSize <= 0 ? 15 : model.PageSize;
            entity.IsLock             = model.IsLock;
            entity.IsHide             = model.IsHide;
            entity.IsShowSubDetail    = model.IsShowSubDetail;
            entity.BannerImg          = model.BannerImg;
            entity.Pic                = model.Pic;
            entity.KindInfo           = model.KindInfo;
            entity.KindDomain         = model.KindDomain;
            entity.Rank               = model.Rank;
            entity.Pic                = model.Pic;
            entity.FilePath           = model.FilePath;


            entity.Save();
            //修改所有文章的路径
            if (idNeedUpdateAllArticleFilePath)
            {
                IList <Article> listArticles = Article.FindAll(Article._.KId == entity.Id, null, null, 0, 0);
                if (listArticles != null && listArticles.Count > 0)
                {
                    foreach (var item in listArticles)
                    {
                        item.FilePath = entity.FilePath;
                    }
                    listArticles.Update();
                }
            }
            Core.Admin.WriteLogActions("修改文章栏目(id:" + entity.Id + ");");
            tip.Status    = JsonTip.SUCCESS;
            tip.Message   = "修改文章栏目成功";
            tip.ReturnUrl = "close";

            return(Json(tip));
        }
Ejemplo n.º 2
0
        public IActionResult EditArticleCategory(ArticleCategory model)
        {
            if (model.Id <= 0)
            {
                tip.Message = "错误参数传递!";
                Json(tip);
            }
            if (string.IsNullOrWhiteSpace(model.KindName))
            {
                tip.Message = "文章栏目标题不能为空!";
                return(Json(tip));
            }

            ArticleCategory entity = ArticleCategory.Find(ArticleCategory._.Id == model.Id);

            if (entity == null)
            {
                tip.Message = "系统找不到本记录!";
                Json(tip);
            }

            if (entity.PId != model.PId)
            {
                if (entity.Id == model.PId)
                {
                    tip.Message = "上级栏目不能选择本身!";
                    return(Json(tip));
                }
                entity.PId      = model.PId;
                entity.Location = ArticleCategory.GetNewLocation(model.PId);
                entity.Level    = ArticleCategory.GetNewLevel(model.PId);
                //修改文章的location
                IList <Article> alist = Article.FindAll(Article._.KId == model.Id, null, null, 0, 0);
                if (alist != null && alist.Count > 0)
                {
                    foreach (var a in alist)
                    {
                        a.Location = entity.Location + "," + entity.Id;
                        //a.FilePath = entity.FilePath;
                    }
                    alist.Save();
                }
            }
            //赋值
            entity.PId                = model.PId;
            entity.KindName           = model.KindName;
            entity.SubTitle           = model.SubTitle;
            entity.KindTitle          = model.KindTitle;
            entity.Keyword            = model.Keyword;
            entity.Description        = model.Description;
            entity.LinkURL            = model.LinkURL;
            entity.TitleColor         = model.TitleColor;
            entity.TemplateFile       = model.TemplateFile;
            entity.DetailTemplateFile = model.DetailTemplateFile;
            entity.IsList             = model.IsList;
            entity.PageSize           = model.PageSize <= 0 ? 15 : model.PageSize;
            entity.IsLock             = model.IsLock;
            entity.IsHide             = model.IsHide;
            entity.IsShowSubDetail    = model.IsShowSubDetail;
            entity.BannerImg          = model.BannerImg;
            entity.Pic                = model.Pic;
            entity.KindInfo           = model.KindInfo;
            entity.KindDomain         = model.KindDomain;
            entity.Rank               = model.Rank;
            entity.Pic                = model.Pic;


            entity.Save();
            Core.Admin.WriteLogActions("修改文章栏目(id:" + entity.Id + ");");
            tip.Status    = JsonTip.SUCCESS;
            tip.Message   = "修改文章栏目成功";
            tip.ReturnUrl = "close";

            return(Json(tip));
        }