diff --git a/OpenAuth.Mvc/AutofacExt.cs b/OpenAuth.App/AutofacExt.cs
similarity index 72%
rename from OpenAuth.Mvc/AutofacExt.cs
rename to OpenAuth.App/AutofacExt.cs
index 14d1dd7d..d8f1f141 100644
--- a/OpenAuth.Mvc/AutofacExt.cs
+++ b/OpenAuth.App/AutofacExt.cs
@@ -12,15 +12,17 @@
// IOC扩展
// ***********************************************************************
+using System.Reflection;
+using System.Web.Http;
+using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
-using OpenAuth.App;
-using System.Reflection;
-using System.Web.Mvc;
+using Autofac.Integration.WebApi;
using OpenAuth.Repository;
using OpenAuth.Repository.Interface;
+using IContainer = Autofac.IContainer;
-namespace OpenAuth.Mvc
+namespace OpenAuth.App
{
public static class AutofacExt
{
@@ -35,12 +37,15 @@ namespace OpenAuth.Mvc
builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork)).PropertiesAutowired();
//注册app层
- builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (UserManagerApp))).PropertiesAutowired();
+ builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).PropertiesAutowired();
// 注册controller,使用属性注入
- builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
-
- builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
+ builder.RegisterControllers(Assembly.GetCallingAssembly()).PropertiesAutowired();
+
+ //注册所有的ApiControllers
+ builder.RegisterApiControllers(Assembly.GetCallingAssembly()).PropertiesAutowired();
+
+ builder.RegisterModelBinders(Assembly.GetCallingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
@@ -54,7 +59,12 @@ namespace OpenAuth.Mvc
// Set the dependency resolver to be Autofac.
_container = builder.Build();
+
+ //Set the MVC DependencyResolver
DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));
+
+ //Set the WebApi DependencyResolver
+ GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver((IContainer)_container);
}
///
diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj
index dde858c0..97acaa56 100644
--- a/OpenAuth.App/OpenAuth.App.csproj
+++ b/OpenAuth.App/OpenAuth.App.csproj
@@ -33,6 +33,18 @@
false
+
+ ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll
+ True
+
+
+ ..\packages\Autofac.Mvc5.3.3.4\lib\net45\Autofac.Integration.Mvc.dll
+ True
+
+
+ ..\packages\Autofac.WebApi2.3.4.0\lib\net45\Autofac.Integration.WebApi.dll
+ True
+
..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
True
@@ -41,18 +53,27 @@
..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
True
-
- ..\packages\WorkflowEngine.NET-Core.1.5.5.2\lib\net45\OptimaJet.Workflow.Core.dll
- True
-
+
+
+ ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll
+ True
+
..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll
True
+
+ ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll
+ True
+
+
+ ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll
+ True
+
..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll
True
@@ -81,6 +102,7 @@
+
@@ -111,7 +133,6 @@
-
diff --git a/OpenAuth.App/OrgManagerApp.cs b/OpenAuth.App/OrgManagerApp.cs
index 625131ee..61cde704 100644
--- a/OpenAuth.App/OrgManagerApp.cs
+++ b/OpenAuth.App/OrgManagerApp.cs
@@ -7,39 +7,41 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
- public class OrgManagerApp
+ public class OrgManagerApp : BaseApp
{
- public IUnitWork _unitWork { get; set; }
-
///
/// 添加部门
///
/// The org.
/// System.Int32.
/// 未能找到该组织的父节点信息
- public string AddOrUpdate(Org org)
+ public string Add(Org org)
{
ChangeModuleCascade(org);
- if (org.Id == string.Empty)
- {
- _unitWork.Add(org);
- }
- else
- {
- //获取旧的的CascadeId
- var CascadeId = _unitWork.FindSingle(o => o.Id == org.Id).CascadeId;
- //根据CascadeId查询子部门
- var orgs = _unitWork.Find(u => u.CascadeId.Contains(CascadeId) && u.Id != org.Id).OrderBy(u => u.CascadeId).ToList();
- //更新操作
- _unitWork.Update(org);
+ Repository.Add(org);
- //更新子部门的CascadeId
- foreach (var a in orgs)
- {
- ChangeModuleCascade(a);
- _unitWork.Update(a);
- }
+ return org.Id;
+ }
+
+ public string Update(Org org)
+ {
+ ChangeModuleCascade(org);
+
+ //获取旧的的CascadeId
+ var cascadeId = Repository.FindSingle(o => o.Id == org.Id).CascadeId;
+ //根据CascadeId查询子部门
+ var orgs = Repository.Find(u => u.CascadeId.Contains(cascadeId) && u.Id != org.Id)
+ .OrderBy(u => u.CascadeId).ToList();
+
+ //更新操作
+ UnitWork.Update(org);
+
+ //更新子部门的CascadeId
+ foreach (var a in orgs)
+ {
+ ChangeModuleCascade(a);
+ UnitWork.Update(a);
}
return org.Id;
@@ -50,10 +52,10 @@ namespace OpenAuth.App
///
public void DelOrg(string[] ids)
{
- var delOrg = _unitWork.Find(u => ids.Contains(u.Id)).ToList();
+ var delOrg = Repository.Find(u => ids.Contains(u.Id)).ToList();
foreach (var org in delOrg)
{
- _unitWork.Delete(u => u.CascadeId.Contains(org.CascadeId));
+ Repository.Delete(u => u.CascadeId.Contains(org.CascadeId));
}
}
@@ -67,17 +69,17 @@ namespace OpenAuth.App
{
//用户角色
var userRoleIds =
- _unitWork.Find(u => u.FirstId == userId && u.Key == "UserRole").Select(u => u.SecondId).ToList();
+ UnitWork.Find(u => u.FirstId == userId && u.Key == "UserRole").Select(u => u.SecondId).ToList();
//用户角色与自己分配到的角色ID
var moduleIds =
- _unitWork.Find(
+ UnitWork.Find(
u =>
(u.FirstId == userId && u.Key == "UserOrg") ||
(u.Key == "RoleOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
if (!moduleIds.Any()) return new List();
- return _unitWork.Find(u => moduleIds.Contains(u.Id)).ToList();
+ return UnitWork.Find(u => moduleIds.Contains(u.Id)).ToList();
}
///
@@ -87,11 +89,11 @@ namespace OpenAuth.App
public List LoadForRole(string roleId)
{
var moduleIds =
- _unitWork.Find(u => u.FirstId == roleId && u.Key == "RoleOrg")
+ UnitWork.Find(u => u.FirstId == roleId && u.Key == "RoleOrg")
.Select(u => u.SecondId)
.ToList();
if (!moduleIds.Any()) return new List();
- return _unitWork.Find(u => moduleIds.Contains(u.Id)).ToList();
+ return UnitWork.Find(u => moduleIds.Contains(u.Id)).ToList();
}
@@ -114,13 +116,13 @@ namespace OpenAuth.App
string cascadeId = "0.";
if (!string.IsNullOrEmpty(orgId))
{
- var org = _unitWork.FindSingle(u => u.Id == orgId);
+ var org = UnitWork.FindSingle(u => u.Id == orgId);
if (org == null)
throw new Exception("未能找到指定对象信息");
cascadeId = org.CascadeId;
}
- return _unitWork.Find(u => u.CascadeId.Contains(cascadeId));
+ return UnitWork.Find(u => u.CascadeId.Contains(cascadeId));
}
#region 私有方法
@@ -130,19 +132,19 @@ namespace OpenAuth.App
{
string cascadeId;
int currentCascadeId = 1; //当前结点的级联节点最后一位
- var sameLevels = _unitWork.Find(o => o.ParentId == org.ParentId && o.Id != org.Id);
+ var sameLevels = UnitWork.Find(o => o.ParentId == org.ParentId && o.Id != org.Id);
foreach (var obj in sameLevels)
{
int objCascadeId = int.Parse(obj.CascadeId.TrimEnd('.').Split('.').Last());
if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1;
}
- if (org.ParentId != null && org.ParentId != string.Empty)
+ if (!string.IsNullOrEmpty(org.ParentId))
{
- var parentOrg = _unitWork.FindSingle(o => o.Id == org.ParentId);
+ var parentOrg = UnitWork.FindSingle(o => o.Id == org.ParentId);
if (parentOrg != null)
{
- cascadeId = parentOrg.CascadeId + currentCascadeId+".";
+ cascadeId = parentOrg.CascadeId + currentCascadeId + ".";
org.ParentName = parentOrg.Name;
}
else
@@ -152,7 +154,7 @@ namespace OpenAuth.App
}
else
{
- cascadeId = ".0." + currentCascadeId+".";
+ cascadeId = ".0." + currentCascadeId + ".";
org.ParentName = "根节点";
}
diff --git a/OpenAuth.App/Response/CommandModel.cs b/OpenAuth.App/Response/CommandModel.cs
deleted file mode 100644
index c7781057..00000000
--- a/OpenAuth.App/Response/CommandModel.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// ***********************************************************************
-// Assembly : OpenAuth.App
-// Author : yubaolee
-// Created : 09-05-2016
-//
-// Last Modified By : yubaolee
-// Last Modified On : 09-05-2016
-// Contact : Microsoft
-// File: CommandModel.cs
-// ***********************************************************************
-
-using OptimaJet.Workflow.Core.Model;
-
-namespace OpenAuth.App.Response
-{
- ///
- /// workflow命令
- ///
- public class CommandModel
- {
- public string Key { get; set; }
- public string Value { get; set; }
- public TransitionClassifier Classifier { get; set; }
- }
-}
\ No newline at end of file
diff --git a/OpenAuth.App/packages.config b/OpenAuth.App/packages.config
index 00ed5e7c..fc56dc1f 100644
--- a/OpenAuth.App/packages.config
+++ b/OpenAuth.App/packages.config
@@ -1,9 +1,14 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenAuth.Mvc/Controllers/OrgManagerController.cs b/OpenAuth.Mvc/Controllers/OrgManagerController.cs
index 567c0092..4852dbd9 100644
--- a/OpenAuth.Mvc/Controllers/OrgManagerController.cs
+++ b/OpenAuth.Mvc/Controllers/OrgManagerController.cs
@@ -40,11 +40,11 @@ namespace OpenAuth.Mvc.Controllers
//添加组织提交
[HttpPost]
- public string AddOrUpdate(Org org)
+ public string Add(Org org)
{
try
{
- OrgApp.AddOrUpdate(org);
+ OrgApp.Add(org);
}
catch (Exception ex)
{
@@ -53,7 +53,23 @@ namespace OpenAuth.Mvc.Controllers
}
return JsonHelper.Instance.Serialize(Result);
}
-
+
+ //编辑
+ [HttpPost]
+ public string Update(Org org)
+ {
+ try
+ {
+ OrgApp.Update(org);
+ }
+ catch (Exception ex)
+ {
+ Result.Code = 500;
+ Result.Message = ex.Message;
+ }
+ return JsonHelper.Instance.Serialize(Result);
+ }
+
public string LoadChildren(string id)
{
return JsonHelper.Instance.Serialize(OrgApp.LoadAllChildren(id));
diff --git a/OpenAuth.Mvc/Global.asax.cs b/OpenAuth.Mvc/Global.asax.cs
index 3bd69ecb..18e9883b 100644
--- a/OpenAuth.Mvc/Global.asax.cs
+++ b/OpenAuth.Mvc/Global.asax.cs
@@ -1,11 +1,10 @@
-using System;
-using System.Web;
+using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Infrastructure;
using Newtonsoft.Json.Linq;
-using OpenAuth.Mvc.Controllers;
+using OpenAuth.App;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc
diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
index 3398e482..c34bda16 100644
--- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj
+++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
@@ -146,7 +146,6 @@
-
@@ -373,7 +372,6 @@
-
diff --git a/OpenAuth.Mvc/Web.config b/OpenAuth.Mvc/Web.config
index 0e786858..2a797910 100644
--- a/OpenAuth.Mvc/Web.config
+++ b/OpenAuth.Mvc/Web.config
@@ -64,7 +64,7 @@
-
+
@@ -103,6 +103,14 @@
+
+
+
+
+
+
+
+
diff --git a/OpenAuth.UnitTest/App.config b/OpenAuth.UnitTest/App.config
index 7290dba8..bd995966 100644
--- a/OpenAuth.UnitTest/App.config
+++ b/OpenAuth.UnitTest/App.config
@@ -72,6 +72,14 @@
+
+
+
+
+
+
+
+
diff --git a/OpenAuth.UnitTest/AutofacExt.cs b/OpenAuth.UnitTest/AutofacExt.cs
deleted file mode 100644
index e03c3f4b..00000000
--- a/OpenAuth.UnitTest/AutofacExt.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System.Reflection;
-using System.Web.Mvc;
-using Autofac;
-using Autofac.Integration.Mvc;
-using OpenAuth.App;
-using OpenAuth.Repository;
-using OpenAuth.Repository.Interface;
-
-namespace OpenAuth.UnitTest
-{
- public class AutofacExt
- {
- private static IContainer _container;
-
- public static void InitDI()
- {
- var builder = new ContainerBuilder();
-
- //注册数据库基础操作和工作单元
- builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>)).PropertiesAutowired();
- builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork)).PropertiesAutowired();
-
- //注册app层
- builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(UserManagerApp))).PropertiesAutowired();
-
- _container = builder.Build();
- DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));
- }
-
- public static T GetFromFac()
- {
- return _container.Resolve();
- }
- }
-}
\ No newline at end of file
diff --git a/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj b/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj
index 85617b64..429125e4 100644
--- a/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj
+++ b/OpenAuth.UnitTest/OpenAuth.UnitTest.csproj
@@ -118,7 +118,6 @@
-
diff --git a/OpenAuth.UnitTest/TestBase.cs b/OpenAuth.UnitTest/TestBase.cs
index 4214c55d..38074ae0 100644
--- a/OpenAuth.UnitTest/TestBase.cs
+++ b/OpenAuth.UnitTest/TestBase.cs
@@ -1,10 +1,12 @@
-namespace OpenAuth.UnitTest
+using OpenAuth.App;
+
+namespace OpenAuth.UnitTest
{
public class TestBase
{
public TestBase()
{
- AutofacExt.InitDI();
+ AutofacExt.InitAutofac();
}
}
}
\ No newline at end of file
diff --git a/OpenAuth.UnitTest/TestOrg.cs b/OpenAuth.UnitTest/TestOrg.cs
index 21092a3e..11e59aa8 100644
--- a/OpenAuth.UnitTest/TestOrg.cs
+++ b/OpenAuth.UnitTest/TestOrg.cs
@@ -25,7 +25,7 @@ namespace OpenAuth.UnitTest
{
var random = new Random();
int val = random.Next();
- _app.AddOrUpdate(new Org
+ _app.Add(new Org
{
Id = string.Empty,
Name = "test" + val,
diff --git a/OpenAuth.WebApi/AutofacExt.cs b/OpenAuth.WebApi/AutofacExt.cs
deleted file mode 100644
index 25e4c746..00000000
--- a/OpenAuth.WebApi/AutofacExt.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-// ***********************************************************************
-// Assembly : OpenAuth.Mvc
-// Author : yubaolee
-// Created : 10-26-2015
-//
-// Last Modified By : yubaolee
-// Last Modified On : 10-26-2015
-// ***********************************************************************
-//
-// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
-//
-// IOC扩展
-// ***********************************************************************
-
-using System.Reflection;
-using System.Web.Http;
-using System.Web.Mvc;
-using Autofac;
-using Autofac.Integration.Mvc;
-using Autofac.Integration.WebApi;
-using OpenAuth.App;
-using OpenAuth.Repository;
-using OpenAuth.Repository.Interface;
-
-namespace OpenAuth.WebApi
-{
- internal static class AutofacExt
- {
- public static void InitAutofac()
- {
- var builder = new ContainerBuilder();
-
- //注册数据库基础操作和工作单元
- builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>)).PropertiesAutowired();
- builder.RegisterType(typeof (UnitWork)).As(typeof (IUnitWork)).PropertiesAutowired();
-
- //注册app层
- builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (AuthorizeApp))).PropertiesAutowired();
-
-
- // OPTIONAL: Register model binders that require DI.
- builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
- builder.RegisterModelBinderProvider();
-
- // OPTIONAL: Register web abstractions like HttpContextBase.
- builder.RegisterModule();
-
- // OPTIONAL: Enable property injection in view pages.
- builder.RegisterSource(new ViewRegistrationSource());
-
- // OPTIONAL: Enable property injection into action filters.
- builder.RegisterFilterProvider();
-
- //注册所有的ApiControllers
- builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
-
- var container = builder.Build();
- HttpConfiguration config = GlobalConfiguration.Configuration;
- //注册api容器需要使用HttpConfiguration对象
- config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
- DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
- }
-
- ///
- /// 从容器中获取对象
- ///
- ///
- public static T GetFromFac()
- {
- return (T)DependencyResolver.Current.GetService(typeof(T));
- }
- }
-}
\ No newline at end of file
diff --git a/OpenAuth.WebApi/Global.asax.cs b/OpenAuth.WebApi/Global.asax.cs
index cc5fd9e9..961204ed 100644
--- a/OpenAuth.WebApi/Global.asax.cs
+++ b/OpenAuth.WebApi/Global.asax.cs
@@ -1,11 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.Http;
+using System.Web.Http;
using System.Web.Mvc;
-using System.Web.Optimization;
using System.Web.Routing;
+using OpenAuth.App;
namespace OpenAuth.WebApi
{
diff --git a/OpenAuth.WebApi/OpenAuth.WebApi.csproj b/OpenAuth.WebApi/OpenAuth.WebApi.csproj
index 8b4eecfe..ddfbfed5 100644
--- a/OpenAuth.WebApi/OpenAuth.WebApi.csproj
+++ b/OpenAuth.WebApi/OpenAuth.WebApi.csproj
@@ -178,7 +178,6 @@
-
Global.asax
diff --git a/OpenAuth.WebTest/Web.config b/OpenAuth.WebTest/Web.config
index 2a6e023c..f642ec4a 100644
--- a/OpenAuth.WebTest/Web.config
+++ b/OpenAuth.WebTest/Web.config
@@ -1,62 +1,74 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+