diff --git a/OpenAuth.App/OrgManagerApp.cs b/OpenAuth.App/OrgManagerApp.cs index dd00625f..e807eabb 100644 --- a/OpenAuth.App/OrgManagerApp.cs +++ b/OpenAuth.App/OrgManagerApp.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using OpenAuth.Domain; using OpenAuth.Domain.Interface; @@ -18,5 +19,37 @@ namespace OpenAuth.App { return _repository.LoadOrgs(); } + + public int AddOrg(Org org) + { + string cascadeId; + //根据同一级个数计算ID + int currentCascadeId = _repository.GetCount(o => o.ParentId == 0) + 1; + + if (org.ParentId != 0) + { + var parentOrg = _repository.FindSingle(o => o.Id == org.ParentId); + if (parentOrg != null) + { + cascadeId = parentOrg.CascadeId +"." + currentCascadeId; + org.ParentName = parentOrg.Name; + } + else + { + throw new Exception("未能找到该组织的父节点信息"); + } + } + else + { + cascadeId = "0." + currentCascadeId; + org.ParentName = ""; + } + + org.CascadeId = cascadeId; + org.CreateTime = DateTime.Now; + _repository.Add(org); + _repository.Save(); + return org.Id; + } } } diff --git a/OpenAuth.Domain/Interface/IOrgRepository.cs b/OpenAuth.Domain/Interface/IOrgRepository.cs index 40f065a2..419c37ca 100644 --- a/OpenAuth.Domain/Interface/IOrgRepository.cs +++ b/OpenAuth.Domain/Interface/IOrgRepository.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace OpenAuth.Domain.Interface { - public interface IOrgRepository + public interface IOrgRepository :IRepository { IEnumerable LoadOrgs(); } diff --git a/OpenAuth.Domain/Interface/IUserRepository.cs b/OpenAuth.Domain/Interface/IUserRepository.cs index 260a1eab..0a4f1167 100644 --- a/OpenAuth.Domain/Interface/IUserRepository.cs +++ b/OpenAuth.Domain/Interface/IUserRepository.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.Linq; - -namespace OpenAuth.Domain.Interface -{ - public interface IUserRepository - { - User FindByAccount(string account); - User FindById(string id); - - IEnumerable LoadUsers(); - - } +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.Domain.Interface +{ + public interface IUserRepository :IRepository + { + User FindByAccount(string account); + User FindById(string id); + + IEnumerable LoadUsers(); + + } } \ No newline at end of file diff --git a/OpenAuth.Domain/Org.cs b/OpenAuth.Domain/Org.cs index 209dc6e4..1d0307b1 100644 --- a/OpenAuth.Domain/Org.cs +++ b/OpenAuth.Domain/Org.cs @@ -21,5 +21,13 @@ namespace OpenAuth.Domain public System.DateTime CreateTime { get; set; } public int CreateId { get; set; } public int SortNo { get; set; } + + public Org() + { + HotKey = ""; + IconName = ""; + BizCode = ""; + CustomCode = ""; + } } } diff --git a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt b/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt index 06f4332c..ddb3a39a 100644 --- a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt +++ b/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt @@ -72,11 +72,11 @@ namespace <#= code.EscapeNamespace(efHost.Namespace) #> { if (isKey && storeGeneratedPattern != StoreGeneratedPattern.Identity) { - configLines.Add(".HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)"); + // configLines.Add(".HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)"); } else if ((!isKey || efHost.EntityType.KeyMembers.Count > 1) && storeGeneratedPattern == StoreGeneratedPattern.Identity) { - configLines.Add(".HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)"); + // configLines.Add(".HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)"); } } diff --git a/OpenAuth.Repository/Models/Mapping/ModuleRoleMap.cs b/OpenAuth.Repository/Models/Mapping/ModuleRoleMap.cs index 3e125fc2..661c3226 100644 --- a/OpenAuth.Repository/Models/Mapping/ModuleRoleMap.cs +++ b/OpenAuth.Repository/Models/Mapping/ModuleRoleMap.cs @@ -12,8 +12,7 @@ namespace OpenAuth.Repository.Models.Mapping this.HasKey(t => t.Id); // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); + this.Property(t => t.Id); // Table & Column Mappings this.ToTable("ModuleRole"); diff --git a/OpenAuth.Repository/Models/Mapping/PageElementGrantMap.cs b/OpenAuth.Repository/Models/Mapping/PageElementGrantMap.cs index bcddb522..d5935e81 100644 --- a/OpenAuth.Repository/Models/Mapping/PageElementGrantMap.cs +++ b/OpenAuth.Repository/Models/Mapping/PageElementGrantMap.cs @@ -12,8 +12,7 @@ namespace OpenAuth.Repository.Models.Mapping this.HasKey(t => t.Id); // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); + this.Property(t => t.Id); // Table & Column Mappings this.ToTable("PageElementGrant"); diff --git a/OpenAuth.Repository/Models/Mapping/PageElementMap.cs b/OpenAuth.Repository/Models/Mapping/PageElementMap.cs index f89a1f00..f562d6c0 100644 --- a/OpenAuth.Repository/Models/Mapping/PageElementMap.cs +++ b/OpenAuth.Repository/Models/Mapping/PageElementMap.cs @@ -11,9 +11,6 @@ namespace OpenAuth.Repository.Models.Mapping // Primary Key this.HasKey(t => t.Id); - // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t => t.DomId) .IsRequired() diff --git a/OpenAuth.Repository/Models/Mapping/UserCfgMap.cs b/OpenAuth.Repository/Models/Mapping/UserCfgMap.cs index 118eaad2..b274aac3 100644 --- a/OpenAuth.Repository/Models/Mapping/UserCfgMap.cs +++ b/OpenAuth.Repository/Models/Mapping/UserCfgMap.cs @@ -11,9 +11,6 @@ namespace OpenAuth.Repository.Models.Mapping // Primary Key this.HasKey(t => t.Id); - // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t => t.Theme) .IsRequired() diff --git a/OpenAuth.Repository/Models/Mapping/UserExtMap.cs b/OpenAuth.Repository/Models/Mapping/UserExtMap.cs index ccb22c21..313ab3d6 100644 --- a/OpenAuth.Repository/Models/Mapping/UserExtMap.cs +++ b/OpenAuth.Repository/Models/Mapping/UserExtMap.cs @@ -11,9 +11,6 @@ namespace OpenAuth.Repository.Models.Mapping // Primary Key this.HasKey(t => t.Id); - // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t => t.Email) .IsRequired() diff --git a/OpenAuth.Repository/Models/Mapping/UserMap.cs b/OpenAuth.Repository/Models/Mapping/UserMap.cs index 148ce0cf..f8538048 100644 --- a/OpenAuth.Repository/Models/Mapping/UserMap.cs +++ b/OpenAuth.Repository/Models/Mapping/UserMap.cs @@ -11,9 +11,6 @@ namespace OpenAuth.Repository.Models.Mapping // Primary Key this.HasKey(t => t.Id); - // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t => t.Account) .IsRequired() diff --git a/OpenAuth.Repository/Models/Mapping/UserModuleMap.cs b/OpenAuth.Repository/Models/Mapping/UserModuleMap.cs index 5b8d963f..8e3be2af 100644 --- a/OpenAuth.Repository/Models/Mapping/UserModuleMap.cs +++ b/OpenAuth.Repository/Models/Mapping/UserModuleMap.cs @@ -11,10 +11,6 @@ namespace OpenAuth.Repository.Models.Mapping // Primary Key this.HasKey(t => t.Id); - // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); - // Table & Column Mappings this.ToTable("UserModule"); this.Property(t => t.Id).HasColumnName("Id"); diff --git a/OpenAuth.Repository/Models/Mapping/UserOrgMap.cs b/OpenAuth.Repository/Models/Mapping/UserOrgMap.cs index 242866fb..6084dfca 100644 --- a/OpenAuth.Repository/Models/Mapping/UserOrgMap.cs +++ b/OpenAuth.Repository/Models/Mapping/UserOrgMap.cs @@ -12,8 +12,7 @@ namespace OpenAuth.Repository.Models.Mapping this.HasKey(t => t.Id); // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); + this.Property(t => t.Id); // Table & Column Mappings this.ToTable("UserOrg"); diff --git a/OpenAuth.Repository/Models/Mapping/UserRoleMap.cs b/OpenAuth.Repository/Models/Mapping/UserRoleMap.cs index 8294c032..45698edf 100644 --- a/OpenAuth.Repository/Models/Mapping/UserRoleMap.cs +++ b/OpenAuth.Repository/Models/Mapping/UserRoleMap.cs @@ -12,8 +12,7 @@ namespace OpenAuth.Repository.Models.Mapping this.HasKey(t => t.Id); // Properties - this.Property(t => t.Id) - .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); + this.Property(t => t.Id); // Table & Column Mappings this.ToTable("UserRole"); diff --git a/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj b/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj index 31e07102..04f8ed13 100644 --- a/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj +++ b/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj @@ -66,6 +66,7 @@ + diff --git a/OpenAuth.UnitTest/TestOrgApp.cs b/OpenAuth.UnitTest/TestOrgApp.cs new file mode 100644 index 00000000..ba98d05b --- /dev/null +++ b/OpenAuth.UnitTest/TestOrgApp.cs @@ -0,0 +1,93 @@ +using System; +using System.Text; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenAuth.App; +using OpenAuth.Domain; +using OpenAuth.Repository; + +namespace OpenAuth.UnitTest +{ + /// + /// TestOrgApp 的摘要说明 + /// + [TestClass] + public class TestOrgApp + { + public TestOrgApp() + { + // + //TODO: 在此处添加构造函数逻辑 + // + } + + private TestContext testContextInstance; + private OrgManagerApp _app = new OrgManagerApp(new OrgRepository()); + + /// + ///获取或设置测试上下文,该上下文提供 + ///有关当前测试运行及其功能的信息。 + /// + public TestContext TestContext + { + get + { + return testContextInstance; + } + set + { + testContextInstance = value; + } + } + + #region 附加测试特性 + // + // 编写测试时,可以使用以下附加特性: + // + // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码 + // [ClassInitialize()] + // public static void MyClassInitialize(TestContext testContext) { } + // + // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码 + // [ClassCleanup()] + // public static void MyClassCleanup() { } + // + // 在运行每个测试之前,使用 TestInitialize 来运行代码 + // [TestInitialize()] + // public void MyTestInitialize() { } + // + // 在每个测试运行完之后,使用 TestCleanup 来运行代码 + // [TestCleanup()] + // public void MyTestCleanup() { } + // + #endregion + + [TestMethod] + public void TestAddOrg() + { + int id = _app.AddOrg(new Org + { + Name = "集团总部", + ParentId = 0 + }); + Assert.IsTrue(id != 0); + id = _app.AddOrg(new Org + { + Name = "一分公司", + ParentId = id + }); + + Assert.IsTrue(id != 0); + } + + [TestMethod] + public void TestLoadOrg() + { + var orgs = _app.GetAll(); + foreach (var org in orgs) + { + Console.WriteLine(org.Name); + } + } + } +}