第一步定义类
/// <summary> /// 控制面板中 商品分类 /// ZKCloud.Shop.Product.Domain.CallBacks.ProductCalssRelation /// </summary> [ClassProperty("商品分类", Icon = "fa-diamond", Description = "商品分类", PageType = ViewPageType.List, Mark = 1)] public class ProductClassRelation : IRelation { } /// <summary> /// <summary> /// 支付测试 /// </summary> [ClassProperty("运费模板", Icon = "fa fa-eraser", Url = "/Admin/DeliveryTemplate/list", Description = "运费模板", SortOrder = 21)] public class CMSControl : IControl { }
第二步:在视图中使用TagHelper引用
<recursive for="Classes" filter="ZKCloud.Shop.Product.Domain.CallBacks.ProductClassRelation" root="0" mode="Tree"></recursive> <recursive for="Tags" filter="ZKCloud.Shop.Product.Domain.CallBacks.ProductTagRelation" root="0" mode="Tag"></recursive>
第三步:在服务中保存数据 (使用事物)
Resolve<IRelationIndexService>().AddUpdateOrDelete<ProductClassRelation>(product.Id, request.Form["Classes"].ToStr());
Resolve<IRelationIndexService>().AddUpdateOrDelete<ProductTagRelation>(product.Id, request.Form["Tags"].ToStr());
var context = Repository<ProductRepository>().RepositoryContext; context.BeginTransaction(); try { List<RelationIndex> relationIndexAddList = new List<RelationIndex>(); //商品添加 if (product.Id == 0) { result = Add(product); product.Id = result.Id.ToInt64(); } else { result = Update(product); } //添加商品分类和标签 Resolve<IRelationIndexService>().AddUpdateOrDelete<ProductClassRelation>(product.Id, request.Form["Classes"].ToStr()); Resolve<IRelationIndexService>().AddUpdateOrDelete<ProductTagRelation>(product.Id, request.Form["Tags"].ToStr()); context.SaveChanges(); context.CommitTransaction(); } catch (Exception ex) { context.RollbackTransaction(); return ServiceResult.FailedWithMessage("更新失败:" + ex.Message); } finally { context.DisposeTransaction(); }