Routine Update

This commit is contained in:
yubaolee
2015-10-31 23:04:01 +08:00
parent 1f574aca70
commit bd7842d5be
6 changed files with 127 additions and 78 deletions

View File

@@ -1,8 +1,8 @@
using System;
using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
namespace OpenAuth.App
{
@@ -15,7 +15,6 @@ namespace OpenAuth.App
_repository = repository;
}
public IEnumerable<Org> GetAll()
{
return _repository.LoadOrgs();
@@ -30,24 +29,14 @@ namespace OpenAuth.App
public int AddOrg(Org org)
{
string cascadeId;
int currentCascadeId = 1;
int currentCascadeId = GetMaxCascadeId(org.ParentId);
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);
if (parentOrg != null)
{
cascadeId = parentOrg.CascadeId +"." + currentCascadeId;
cascadeId = parentOrg.CascadeId + "." + currentCascadeId;
org.ParentName = parentOrg.Name;
}
else
@@ -70,17 +59,54 @@ namespace OpenAuth.App
/// <summary>
/// 部门的直接子部门
/// <para>TODO:可以根据用户的喜好决定选择LoadAllChildren或LoadDirectChildren</para>
/// </summary>
/// <param name="orgId">The org unique identifier.</param>
/// <returns>IEnumerable{Org}.</returns>
public IEnumerable<Org> LoadChildren(int orgId)
public IEnumerable<Org> LoadDirectChildren(int 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
}
}
}

View File

@@ -32,7 +32,7 @@ namespace OpenAuth.Mvc.Controllers
public string LoadChildren(int id)
{
return JsonHelper.Instance.Serialize(_orgApp.LoadChildren(id));
return JsonHelper.Instance.Serialize(_orgApp.LoadAllChildren(id));
}
public void DelOrg(string json)

View File

@@ -45,6 +45,14 @@
<Reference Include="Autofac.Integration.Mvc">
<HintPath>..\packages\Autofac.Mvc5.3.3.4\lib\net45\Autofac.Integration.Mvc.dll</HintPath>
</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="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -108,14 +116,6 @@
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
</Reference>
</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>
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />

View File

@@ -5,11 +5,11 @@
-->
<configuration>
<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="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<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" />

View File

@@ -1,48 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="Autofac" version="3.5.2" targetFramework="net45" />
<package id="Autofac.Mvc5" version="3.3.4" targetFramework="net45" />
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
<package id="EntityFramework" version="6.0.0" 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.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.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.zh-Hans" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.1.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc.zh-Hans" version="5.1.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor.zh-Hans" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization.zh-Hans" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.zh-Hans" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Cookies" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Facebook" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Facebook.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Google" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Google.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.MicrosoftAccount.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.OAuth" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Twitter" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Twitter.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Respond" version="1.2.0" targetFramework="net45" />
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="Autofac" version="3.5.2" targetFramework="net45" />
<package id="Autofac.Mvc5" version="3.3.4" targetFramework="net45" />
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
<package id="jQuery" version="1.10.2" 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.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.zh-Hans" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.1.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc.zh-Hans" version="5.1.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor.zh-Hans" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization.zh-Hans" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.zh-Hans" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Cookies" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Facebook" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Facebook.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Google" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Google.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.MicrosoftAccount.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.OAuth" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Twitter" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Twitter.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.zh-Hans" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Respond" version="1.2.0" targetFramework="net45" />
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
</packages>

View File

@@ -90,6 +90,32 @@ namespace OpenAuth.UnitTest
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]
public void TestLoadOrg()
{