public void CreateNewCategory(EditArticleCategoryModel model) { var articleCategory = new ArticleCategory(); articleCategory.CategoryName = model.FormData.Name; articleCategory.Unit = model.Unit; if (model.ParentId.HasValue) { articleCategory.ParentArticleCategory = _articleCategoryRepository.Find(model.ParentId.Value); } articleCategory.RecordDescription.CreateBy(NpcContext.CurrentUser); _articleCategoryRepository.Save(articleCategory); }
private ArticleCategoryTreeModelComponent ConvertArticleCategoryToModel(ArticleCategory articleCategory, bool isNeedSub) { var model = new ArticleCategoryTreeModelComponent() { Id = articleCategory.Id, Name = articleCategory.CategoryName, IconCls = ApplicationConst.TreeLeafCls, CategoryId = articleCategory.Id }; var childrens = _articleCategoryRepository.GetSubs(NpcContext.CurrentUser.Unit.Id, articleCategory.Id).ToList(); if (childrens.Any()) { if (isNeedSub) { childrens.ForEach(o => model.Childrens.Add(ConvertArticleCategoryToModel(o, true))); } model.IconCls = ApplicationConst.TreeParentNode; model.State = isNeedSub ? "open" : "closed"; } return model; }