diff --git a/OpenAuth.App/OrgManagerApp.cs b/OpenAuth.App/OrgManagerApp.cs index 39d42ed4..a55d20ad 100644 --- a/OpenAuth.App/OrgManagerApp.cs +++ b/OpenAuth.App/OrgManagerApp.cs @@ -27,20 +27,24 @@ namespace OpenAuth.App } CaculateCascade(org); - Repository.Add(org); - - //如果当前账号不是SYSTEM,则直接分配 - var loginUser = _auth.GetCurrentUser(); - if (loginUser.User.Account != Define.SYSTEM_USERNAME) + UnitWork.ExecuteWithTransaction(() => { - _revelanceApp.Assign(new AssignReq + UnitWork.Add(org); + UnitWork.Save(); + + //如果当前账号不是SYSTEM,则直接分配 + var loginUser = _auth.GetCurrentUser(); + if (loginUser.User.Account != Define.SYSTEM_USERNAME) { - type=Define.USERORG, - firstId = loginContext.User.Id, - secIds = new[]{org.Id} - }); - } - + _revelanceApp.Assign(new AssignReq + { + type = Define.USERORG, + firstId = loginContext.User.Id, + secIds = new[] { org.Id } + }); + } + }); + return org.Id; } diff --git a/OpenAuth.App/Test/TestBase.cs b/OpenAuth.App/Test/TestBase.cs index dc0548bd..7ae9041a 100644 --- a/OpenAuth.App/Test/TestBase.cs +++ b/OpenAuth.App/Test/TestBase.cs @@ -21,6 +21,7 @@ namespace OpenAuth.App.Test var serviceCollection = GetService(); serviceCollection.AddMemoryCache(); serviceCollection.AddOptions(); + serviceCollection.AddLogging(); var optionMock = new Mock>(); optionMock.Setup(x => x.Value).Returns(new AppSetting { DbType = Define.DBTYPE_MYSQL}); diff --git a/OpenAuth.Repository/Test/TestBase.cs b/OpenAuth.Repository/Test/TestBase.cs index a530c210..63391726 100644 --- a/OpenAuth.Repository/Test/TestBase.cs +++ b/OpenAuth.Repository/Test/TestBase.cs @@ -22,6 +22,7 @@ namespace OpenAuth.Repository.Test var serviceCollection = GetService(); serviceCollection.AddMemoryCache(); serviceCollection.AddOptions(); + serviceCollection.AddLogging(); serviceCollection.AddScoped(typeof(IRepository<,>), typeof(BaseRepository<,>)); serviceCollection.AddScoped(typeof(IUnitWork<>), typeof(UnitWork<>)); diff --git a/OpenAuth.WebApi/Controllers/OrgsController.cs b/OpenAuth.WebApi/Controllers/OrgsController.cs index f057a472..bfd6eb73 100644 --- a/OpenAuth.WebApi/Controllers/OrgsController.cs +++ b/OpenAuth.WebApi/Controllers/OrgsController.cs @@ -15,6 +15,9 @@ namespace OpenAuth.WebApi.Controllers { private readonly OrgManagerApp _app; + /// + /// 获取机构详情 + /// [HttpGet] public Response Get(string id) { @@ -32,7 +35,12 @@ namespace OpenAuth.WebApi.Controllers return result; } - //添加或修改 + /// + /// 新增机构 + /// 如果ID为空,会自动创建ID;会自动为当前登录用户分配添加的机构 + /// + /// + /// [HttpPost] public Response Add(Org obj) {