mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 18:22:11 +08:00
Routine Update
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using OpenAuth.Domain;
|
||||||
|
using OpenAuth.Domain.Interface;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenAuth.Domain;
|
|
||||||
using OpenAuth.Domain.Interface;
|
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,6 @@ namespace OpenAuth.App
|
|||||||
_repository = repository;
|
_repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<Org> GetAll()
|
public IEnumerable<Org> GetAll()
|
||||||
{
|
{
|
||||||
return _repository.LoadOrgs();
|
return _repository.LoadOrgs();
|
||||||
@@ -30,24 +29,14 @@ namespace OpenAuth.App
|
|||||||
public int AddOrg(Org org)
|
public int AddOrg(Org org)
|
||||||
{
|
{
|
||||||
string cascadeId;
|
string cascadeId;
|
||||||
int currentCascadeId = 1;
|
int currentCascadeId = GetMaxCascadeId(org.ParentId);
|
||||||
|
|
||||||
|
|
||||||
if (org.ParentId != 0)
|
if (org.ParentId != 0)
|
||||||
{
|
{
|
||||||
//根据同一级中最大的语义ID
|
|
||||||
var maxCascadeIdOrg = _repository.Find(o => o.ParentId == org.ParentId)
|
|
||||||
.OrderByDescending(o =>o.CascadeId).FirstOrDefault();
|
|
||||||
if (maxCascadeIdOrg != null)
|
|
||||||
{
|
|
||||||
var cascades = maxCascadeIdOrg.CascadeId.Split('.');
|
|
||||||
currentCascadeId = int.Parse(cascades[cascades.Length - 1]) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var parentOrg = _repository.FindSingle(o => o.Id == org.ParentId);
|
var parentOrg = _repository.FindSingle(o => o.Id == org.ParentId);
|
||||||
if (parentOrg != null)
|
if (parentOrg != null)
|
||||||
{
|
{
|
||||||
cascadeId = parentOrg.CascadeId +"." + currentCascadeId;
|
cascadeId = parentOrg.CascadeId + "." + currentCascadeId;
|
||||||
org.ParentName = parentOrg.Name;
|
org.ParentName = parentOrg.Name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -70,17 +59,54 @@ namespace OpenAuth.App
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部门的直接子部门
|
/// 部门的直接子部门
|
||||||
|
/// <para>TODO:可以根据用户的喜好决定选择LoadAllChildren或LoadDirectChildren</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="orgId">The org unique identifier.</param>
|
/// <param name="orgId">The org unique identifier.</param>
|
||||||
/// <returns>IEnumerable{Org}.</returns>
|
/// <returns>IEnumerable{Org}.</returns>
|
||||||
public IEnumerable<Org> LoadChildren(int orgId)
|
public IEnumerable<Org> LoadDirectChildren(int orgId)
|
||||||
{
|
{
|
||||||
return _repository.Find(u => u.ParentId == orgId);
|
return _repository.Find(u => u.ParentId == orgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DelOrg(int Id)
|
//得到部门的所有子部门
|
||||||
|
public IEnumerable<Org> LoadAllChildren(int orgId)
|
||||||
{
|
{
|
||||||
_repository.Delete(u =>u.Id ==Id);
|
var org = _repository.FindSingle(u => u.Id == orgId);
|
||||||
|
if (org == null)
|
||||||
|
throw new Exception("未能找到指定对象信息");
|
||||||
|
|
||||||
|
return _repository.Find(u => u.CascadeId.Contains(org.CascadeId) && u.Id != orgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除指定ID的部门及其所有子部门
|
||||||
|
/// </summary>
|
||||||
|
public void DelOrg(int id)
|
||||||
|
{
|
||||||
|
var delOrg = _repository.FindSingle(u => u.Id == id);
|
||||||
|
if (delOrg == null)
|
||||||
|
throw new Exception("未能找到要删除的对象");
|
||||||
|
|
||||||
|
_repository.Delete(u => u.CascadeId.Contains(delOrg.CascadeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 私有方法
|
||||||
|
|
||||||
|
//根据同一级中最大的语义ID
|
||||||
|
private int GetMaxCascadeId(int parentId)
|
||||||
|
{
|
||||||
|
int currentCascadeId = 1;
|
||||||
|
|
||||||
|
var maxCascadeIdOrg = _repository.Find(o => o.ParentId == parentId)
|
||||||
|
.OrderByDescending(o => o.CascadeId).FirstOrDefault();
|
||||||
|
if (maxCascadeIdOrg != null)
|
||||||
|
{
|
||||||
|
var cascades = maxCascadeIdOrg.CascadeId.Split('.');
|
||||||
|
currentCascadeId = int.Parse(cascades[cascades.Length - 1]) + 1;
|
||||||
|
}
|
||||||
|
return currentCascadeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion 私有方法
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -32,7 +32,7 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
|
|
||||||
public string LoadChildren(int id)
|
public string LoadChildren(int id)
|
||||||
{
|
{
|
||||||
return JsonHelper.Instance.Serialize(_orgApp.LoadChildren(id));
|
return JsonHelper.Instance.Serialize(_orgApp.LoadAllChildren(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DelOrg(string json)
|
public void DelOrg(string json)
|
||||||
|
@@ -45,6 +45,14 @@
|
|||||||
<Reference Include="Autofac.Integration.Mvc">
|
<Reference Include="Autofac.Integration.Mvc">
|
||||||
<HintPath>..\packages\Autofac.Mvc5.3.3.4\lib\net45\Autofac.Integration.Mvc.dll</HintPath>
|
<HintPath>..\packages\Autofac.Mvc5.3.3.4\lib\net45\Autofac.Integration.Mvc.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
@@ -108,14 +116,6 @@
|
|||||||
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
|
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="EntityFramework">
|
|
||||||
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="EntityFramework.SqlServer">
|
|
||||||
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="App_Start\BundleConfig.cs" />
|
<Compile Include="App_Start\BundleConfig.cs" />
|
||||||
<Compile Include="App_Start\FilterConfig.cs" />
|
<Compile Include="App_Start\FilterConfig.cs" />
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
-->
|
-->
|
||||||
<configuration>
|
<configuration>
|
||||||
<configSections>
|
<configSections>
|
||||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
|
||||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||||
|
|
||||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||||
</configSections>
|
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
|
||||||
|
|
||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<add name="OpenAuthDBContext" connectionString="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=000000;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
|
<add name="OpenAuthDBContext" connectionString="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=000000;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
|
||||||
|
@@ -4,14 +4,11 @@
|
|||||||
<package id="Autofac" version="3.5.2" targetFramework="net45" />
|
<package id="Autofac" version="3.5.2" targetFramework="net45" />
|
||||||
<package id="Autofac.Mvc5" version="3.3.4" targetFramework="net45" />
|
<package id="Autofac.Mvc5" version="3.3.4" targetFramework="net45" />
|
||||||
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
|
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
|
||||||
<package id="EntityFramework" version="6.0.0" targetFramework="net45" />
|
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
|
||||||
<package id="EntityFramework.zh-Hans" version="6.0.0" targetFramework="net45" />
|
|
||||||
<package id="jQuery" version="1.10.2" targetFramework="net45" />
|
<package id="jQuery" version="1.10.2" targetFramework="net45" />
|
||||||
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
|
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Identity.Core.zh-Hans" version="1.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Identity.Core.zh-Hans" version="1.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
|
|
||||||
<package id="Microsoft.AspNet.Identity.EntityFramework.zh-Hans" version="1.0.0" targetFramework="net45" />
|
|
||||||
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Identity.Owin.zh-Hans" version="1.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Identity.Owin.zh-Hans" version="1.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Mvc" version="5.1.3" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Mvc" version="5.1.3" targetFramework="net45" />
|
||||||
|
@@ -90,6 +90,32 @@ namespace OpenAuth.UnitTest
|
|||||||
Assert.IsTrue(id != 0);
|
Assert.IsTrue(id != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestDelOrg()
|
||||||
|
{
|
||||||
|
int rootId = _app.AddOrg(new Org
|
||||||
|
{
|
||||||
|
Name = "即将被删除",
|
||||||
|
ParentId = 0
|
||||||
|
});
|
||||||
|
Assert.IsTrue(rootId != 0);
|
||||||
|
|
||||||
|
int id = _app.AddOrg(new Org
|
||||||
|
{
|
||||||
|
Name = "即将被删除1",
|
||||||
|
ParentId = rootId
|
||||||
|
});
|
||||||
|
id = _app.AddOrg(new Org
|
||||||
|
{
|
||||||
|
Name = "即将被删除2",
|
||||||
|
ParentId = id
|
||||||
|
});
|
||||||
|
|
||||||
|
_app.DelOrg(rootId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestLoadOrg()
|
public void TestLoadOrg()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user