示例图
C#端实现代码
/// <summary> /// 创建类别 /// </summary> /// <param name="input">创建Dto</param> [AbpAuthorize(MallPermissions.Category_Edit)] public async Task CreateCategory(CreateOrUpdateCategoryInput input) { var query = _categoryRepository.GetAll(); var names = input.Category.Name.Split(new char[2] { ' ', ' ' }); var items = new List<string>(); foreach (var name in names) { if (string.IsNullOrEmpty(name.Trim())) continue; items.Add(name); } foreach (var item in items) { var result = _categoryRepository.FirstOrDefault(x => x.Name == item && x.ParentId == input.Category.ParentId); if (result != null) { continue; } var category = ObjectMapper.Map<Category>(input.Category); category.Name = item; Category targetNode = null; if (category.ParentId != null) { targetNode = query.FirstOrDefault(x => x.Id == category.ParentId); } query.AppendNode<Category, Guid, Guid?>(category, targetNode); await _categoryRepository.InsertAsync(category); _unitOfWorkManager.Current.SaveChanges(); } }