mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 18:22:11 +08:00
优化autofac注入方式,Controller使用属性注入
This commit is contained in:
@@ -10,12 +10,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class CategoryManagerController : BaseController
|
||||
{
|
||||
private CategoryManagerApp _app;
|
||||
|
||||
public CategoryManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<CategoryManagerApp>();
|
||||
}
|
||||
public CategoryManagerApp App { get; set; }
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
@@ -30,12 +25,12 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string Load(Guid parentId, int page = 1, int rows = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(parentId, page, rows));
|
||||
return JsonHelper.Instance.Serialize(App.Load(parentId, page, rows));
|
||||
}
|
||||
|
||||
public string LoadForTree()
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.LoadAll());
|
||||
return JsonHelper.Instance.Serialize(App.LoadAll());
|
||||
}
|
||||
|
||||
//添加或修改Category
|
||||
@@ -44,7 +39,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
App.AddOrUpdate(model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -59,7 +54,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(ids);
|
||||
App.Delete(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -12,13 +12,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
private ModuleManagerApp _app;
|
||||
|
||||
public HomeController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.NavBar = GetNavBar();
|
||||
|
@@ -24,12 +24,8 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class ModuleElementManagerController : BaseController
|
||||
{
|
||||
private ModuleElementManagerApp _app;
|
||||
public ModuleElementManagerApp App { get; set; }
|
||||
|
||||
public ModuleElementManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<ModuleElementManagerApp>();
|
||||
}
|
||||
public ActionResult Index(Guid id)
|
||||
{
|
||||
ViewBag.ModuleId = id;
|
||||
@@ -37,14 +33,14 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
public ActionResult Get(Guid moduleId)
|
||||
{
|
||||
return Json(_app.LoadByModuleId(moduleId), JsonRequestBehavior.AllowGet);
|
||||
return Json(App.LoadByModuleId(moduleId), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
[HttpPost]
|
||||
public string AddOrEditButton(ModuleElement button)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(button);
|
||||
App.AddOrUpdate(button);
|
||||
}
|
||||
catch (DbEntityValidationException e)
|
||||
{
|
||||
@@ -58,7 +54,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(ids);
|
||||
App.Delete(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -83,7 +79,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
public string LoadWithAccess(Guid tId, Guid firstId, string key)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.LoadWithAccess(key, firstId, tId));
|
||||
return JsonHelper.Instance.Serialize(App.LoadWithAccess(key, firstId, tId));
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,12 +14,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class ModuleManagerController : BaseController
|
||||
{
|
||||
private ModuleManagerApp _app;
|
||||
|
||||
public ModuleManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
|
||||
}
|
||||
public ModuleManagerApp App { get; set; }
|
||||
|
||||
// GET: /ModuleManager/
|
||||
[Authenticate]
|
||||
@@ -34,7 +29,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
ViewBag.ModuleType = key;
|
||||
|
||||
var moduleWithChildren = AuthUtil.GetCurrentUser().ModuleWithChildren;
|
||||
var modules = key == "UserModule" ? _app.LoadForUser(firstId) : _app.LoadForRole(firstId);
|
||||
var modules = key == "UserModule" ? App.LoadForUser(firstId) : App.LoadForRole(firstId);
|
||||
|
||||
CheckModule(moduleWithChildren, modules);
|
||||
|
||||
@@ -106,7 +101,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string Load(Guid orgId, int page = 1, int rows = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(orgId, page, rows));
|
||||
return JsonHelper.Instance.Serialize(App.Load(orgId, page, rows));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -116,7 +111,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// <returns>System.String.</returns>
|
||||
public string LoadForUser(Guid firstId)
|
||||
{
|
||||
var orgs = _app.LoadForUser(firstId);
|
||||
var orgs = App.LoadForUser(firstId);
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
@@ -127,7 +122,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// <returns>System.String.</returns>
|
||||
public string LoadForRole(Guid firstId)
|
||||
{
|
||||
var orgs = _app.LoadForRole(firstId);
|
||||
var orgs = App.LoadForRole(firstId);
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
@@ -145,7 +140,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
App.AddOrUpdate(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -162,7 +157,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
foreach (var obj in ids)
|
||||
{
|
||||
_app.Delete(obj);
|
||||
App.Delete(obj);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -10,12 +10,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class OrgManagerController : BaseController
|
||||
{
|
||||
private OrgManagerApp _orgApp;
|
||||
|
||||
public OrgManagerController()
|
||||
{
|
||||
_orgApp = AutofacExt.GetFromFac<OrgManagerApp>();
|
||||
}
|
||||
public OrgManagerApp OrgApp { get; set; }
|
||||
|
||||
//
|
||||
// GET: /OrgManager/
|
||||
@@ -38,13 +33,13 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
public string LoadForUser(Guid firstId)
|
||||
{
|
||||
var orgs = _orgApp.LoadForUser(firstId);
|
||||
var orgs = OrgApp.LoadForUser(firstId);
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
public string LoadForRole(Guid firstId)
|
||||
{
|
||||
var orgs = _orgApp.LoadForRole(firstId);
|
||||
var orgs = OrgApp.LoadForRole(firstId);
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
@@ -55,7 +50,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_orgApp.AddOrUpdate(org);
|
||||
OrgApp.AddOrUpdate(org);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -67,7 +62,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
public string LoadChildren(Guid id)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_orgApp.LoadAllChildren(id));
|
||||
return JsonHelper.Instance.Serialize(OrgApp.LoadAllChildren(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,7 +75,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_orgApp.DelOrg(ids);
|
||||
OrgApp.DelOrg(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -12,19 +12,14 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class RelevanceManagerController : BaseController
|
||||
{
|
||||
private RevelanceManagerApp _app;
|
||||
|
||||
public RelevanceManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<RevelanceManagerApp>();
|
||||
}
|
||||
public RevelanceManagerApp App { get; set; }
|
||||
|
||||
[HttpPost]
|
||||
public string Assign(string type, Guid firstId, Guid[] secIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Assign(type, firstId, secIds);
|
||||
App.Assign(type, firstId, secIds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -38,7 +33,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.UnAssign(type, firstId, secIds);
|
||||
App.UnAssign(type, firstId, secIds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -11,12 +11,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class ResourceManagerController : BaseController
|
||||
{
|
||||
private ResourceManagerApp _app;
|
||||
|
||||
public ResourceManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<ResourceManagerApp>();
|
||||
}
|
||||
public ResourceManagerApp App { get; set; }
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
@@ -32,7 +27,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
App.AddOrUpdate(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -47,12 +42,12 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string Load(Guid categoryId, int page = 1, int rows = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(AuthUtil.GetUserName(), categoryId, page, rows));
|
||||
return JsonHelper.Instance.Serialize(App.Load(AuthUtil.GetUserName(), categoryId, page, rows));
|
||||
}
|
||||
|
||||
public string LoadForTree()
|
||||
{
|
||||
var models = _app.LoadAll();
|
||||
var models = App.LoadAll();
|
||||
return JsonHelper.Instance.Serialize(models);
|
||||
}
|
||||
|
||||
@@ -61,7 +56,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(ids);
|
||||
App.Delete(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -96,7 +91,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// <returns>System.String.</returns>
|
||||
public string LoadWithAccess(Guid cId, Guid firstId, string key)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.LoadWithAccess(AuthUtil.GetUserName(),key,firstId, cId));
|
||||
return JsonHelper.Instance.Serialize(App.LoadWithAccess(AuthUtil.GetUserName(),key,firstId, cId));
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,12 +10,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class RoleManagerController : BaseController
|
||||
{
|
||||
private RoleManagerApp _app;
|
||||
|
||||
public RoleManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<RoleManagerApp>();
|
||||
}
|
||||
public RoleManagerApp App { get; set; }
|
||||
|
||||
//
|
||||
// GET: /RoleManager/
|
||||
@@ -31,7 +26,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(obj);
|
||||
App.AddOrUpdate(obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -46,7 +41,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string Load(Guid orgId, int pageCurrent = 1, int pageSize = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize));
|
||||
return JsonHelper.Instance.Serialize(App.Load(orgId, pageCurrent, pageSize));
|
||||
}
|
||||
|
||||
[System.Web.Mvc.HttpPost]
|
||||
@@ -56,7 +51,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
foreach (var obj in ids)
|
||||
{
|
||||
_app.Delete(obj);
|
||||
App.Delete(obj);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -78,7 +73,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
public string LoadForOrgAndUser(Guid orgId, Guid userId)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.LoadForOrgAndUser(orgId, userId));
|
||||
return JsonHelper.Instance.Serialize(App.LoadForOrgAndUser(orgId, userId));
|
||||
}
|
||||
|
||||
#endregion 为用户设置角色界面
|
||||
|
@@ -14,12 +14,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public class StockManagerController : BaseController
|
||||
{
|
||||
private StockManagerApp _app;
|
||||
|
||||
public StockManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<StockManagerApp>();
|
||||
}
|
||||
public StockManagerApp App { get; set; }
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
@@ -37,7 +32,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
var newmodel = new Stock();
|
||||
model.CopyTo(newmodel);
|
||||
_app.AddOrUpdate(newmodel);
|
||||
App.AddOrUpdate(newmodel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -52,14 +47,14 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string Load(Guid parentId, int page = 1, int rows = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(AuthUtil.GetUserName(), parentId, page, rows));
|
||||
return JsonHelper.Instance.Serialize(App.Load(AuthUtil.GetUserName(), parentId, page, rows));
|
||||
}
|
||||
|
||||
public string Delete(Guid[] ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(ids);
|
||||
App.Delete(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -13,12 +13,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class UserManagerController : BaseController
|
||||
{
|
||||
private UserManagerApp _app;
|
||||
|
||||
public UserManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<UserManagerApp>();
|
||||
}
|
||||
public UserManagerApp App { get; set; }
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
@@ -34,7 +29,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(view);
|
||||
App.AddOrUpdate(view);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -50,7 +45,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string Load(Guid orgId, int page = 1, int rows = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(orgId, page, rows));
|
||||
return JsonHelper.Instance.Serialize(App.Load(orgId, page, rows));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -58,7 +53,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(ids);
|
||||
App.Delete(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -81,7 +76,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
var treeList = new List<TreeEntity>();
|
||||
string companyid = "";
|
||||
string departmentid = "";
|
||||
foreach (UserView item in _app.Load(Guid.Empty, 1, 10).rows)
|
||||
foreach (UserView item in App.Load(Guid.Empty, 1, 10).rows)
|
||||
{
|
||||
TreeEntity tree = new TreeEntity();
|
||||
|
||||
@@ -107,7 +102,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
/// </summary>
|
||||
public string GetAccessedUsers()
|
||||
{
|
||||
IEnumerable<UserView> users = _app.Load(Guid.Empty, 1, 10).rows;
|
||||
IEnumerable<UserView> users = App.Load(Guid.Empty, 1, 10).rows;
|
||||
var result = new Dictionary<string , object>();
|
||||
foreach (var user in users)
|
||||
{
|
||||
|
Reference in New Issue
Block a user