mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 22:58:11 +08:00
Routine Update
This commit is contained in:
parent
7acef13ce2
commit
e320ba7da8
117
OpenAuth.App/UserManagerApp.cs
Normal file
117
OpenAuth.App/UserManagerApp.cs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
using OpenAuth.App.ViewModel;
|
||||||
|
using OpenAuth.Domain;
|
||||||
|
using OpenAuth.Domain.Interface;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenAuth.App
|
||||||
|
{
|
||||||
|
public class UserManagerApp
|
||||||
|
{
|
||||||
|
private IUserRepository _repository;
|
||||||
|
private IOrgRepository _orgRepository;
|
||||||
|
|
||||||
|
public UserManagerApp(IUserRepository repository,
|
||||||
|
IOrgRepository orgRepository)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_orgRepository = orgRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetUserCntInOrg(int orgId)
|
||||||
|
{
|
||||||
|
if (orgId == 0)
|
||||||
|
{
|
||||||
|
return _repository.Find(null).Count();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _repository.GetUserCntInOrgs(GetSubOrgIds(orgId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载一个部门及子部门全部用户
|
||||||
|
/// </summary>
|
||||||
|
public dynamic Load(int orgId, int pageindex, int pagesize)
|
||||||
|
{
|
||||||
|
IEnumerable<User> users;
|
||||||
|
int total = 0;
|
||||||
|
if (orgId == 0)
|
||||||
|
{
|
||||||
|
users = _repository.LoadUsers(pageindex, pagesize);
|
||||||
|
total = _repository.GetCount();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
users = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
|
||||||
|
total = _repository.GetUserCntInOrgs(orgId);
|
||||||
|
}
|
||||||
|
var userviews = new List<UserView>();
|
||||||
|
foreach (var user in users)
|
||||||
|
{
|
||||||
|
UserView uv = user;
|
||||||
|
uv.Organizations = string.Join(",", _orgRepository.LoadByUser(user.Id).Select(u => u.Name).ToList());
|
||||||
|
userviews.Add(uv);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
total = total,
|
||||||
|
list = userviews,
|
||||||
|
pageCurrent = pageindex
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取当前组织的所有下级组织
|
||||||
|
/// </summary>
|
||||||
|
private int[] GetSubOrgIds(int orgId)
|
||||||
|
{
|
||||||
|
var org = _orgRepository.FindSingle(u => u.Id == orgId);
|
||||||
|
var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
|
||||||
|
return orgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserView Find(int id)
|
||||||
|
{
|
||||||
|
var user = _repository.FindSingle(u => u.Id == id);
|
||||||
|
if (user == null) return new UserView();
|
||||||
|
|
||||||
|
UserView view = user;
|
||||||
|
foreach (var org in _orgRepository.LoadByUser(id))
|
||||||
|
{
|
||||||
|
view.Organizations += "," + org.Name;
|
||||||
|
view.OrganizationIds += "," + org.Id;
|
||||||
|
}
|
||||||
|
view.OrganizationIds = view.OrganizationIds.TrimStart(',');
|
||||||
|
view.Organizations = view.Organizations.TrimStart(',');
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
_repository.Delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddOrUpdate(UserView view)
|
||||||
|
{
|
||||||
|
User user = view;
|
||||||
|
if (user.Id == 0)
|
||||||
|
{
|
||||||
|
user.CreateTime = DateTime.Now;
|
||||||
|
_repository.Add(user);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_repository.Update(user);
|
||||||
|
}
|
||||||
|
int[] orgIds = view.OrganizationIds.Split(',').Select(id => int.Parse(id)).ToArray();
|
||||||
|
|
||||||
|
_repository.SetOrg(user.Id, orgIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
return View(_app.Find(id));
|
return View(_app.Find(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加组织提交
|
//添加或修改组织
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public string Add(UserView view)
|
public string Add(UserView view)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
filterThead: false,
|
filterThead: false,
|
||||||
toolbarItem: 'refresh, |, del',
|
toolbarItem: 'refresh, |, del',
|
||||||
toolbarCustom: '<a href="/UserManager/Add" class="btn btn-green" data-icon ="plus" ' +
|
toolbarCustom: '<a href="/UserManager/Add" class="btn btn-green" data-icon ="plus" ' +
|
||||||
'data-toggle="dialog" data-id="dialog-mask" data-mask="true">添加</a>' +
|
'data-toggle="dialog" data-id="dialog-mask" data-mask="true" data-on-close="loadDataGrid">添加</a>' +
|
||||||
'<button class=" btn-green" onclick="editOrg()" data-icon="pencil" type="button">编辑</button>',
|
'<button class=" btn-green" onclick="editOrg()" data-icon="pencil" type="button">编辑</button>',
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
@ -88,8 +88,6 @@
|
|||||||
dataUrl: 'UserManager/Load?orgId=' + selectedId,
|
dataUrl: 'UserManager/Load?orgId=' + selectedId,
|
||||||
delUrl: 'UserManager/Delete',
|
delUrl: 'UserManager/Delete',
|
||||||
delPK: "Id",
|
delPK: "Id",
|
||||||
editUrl: 'UserManager/Edit',
|
|
||||||
editMode: 'dialog',
|
|
||||||
fullGrid: true,
|
fullGrid: true,
|
||||||
showLinenumber: true,
|
showLinenumber: true,
|
||||||
showCheckboxcol: true,
|
showCheckboxcol: true,
|
||||||
@ -103,13 +101,6 @@
|
|||||||
else {
|
else {
|
||||||
$(this).alertmsg('warn', delResult.message);
|
$(this).alertmsg('warn', delResult.message);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
editCallback: function (delResult) {
|
|
||||||
if (delResult.statusCode == "200")
|
|
||||||
loadDataGrid();
|
|
||||||
else {
|
|
||||||
$(this).alertmsg('warn', delResult.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -170,7 +161,14 @@
|
|||||||
var selected = getSelected(2);
|
var selected = getSelected(2);
|
||||||
if (selected == null) return;
|
if (selected == null) return;
|
||||||
|
|
||||||
$(this).dialog({ id: 'editDialog', url: '/UserManager/Add?id='+selected, title: '编辑' });
|
$(this).dialog({
|
||||||
|
id: 'editDialog',
|
||||||
|
url: '/UserManager/Add?id=' + selected,
|
||||||
|
title: '编辑',
|
||||||
|
onClose:function() {
|
||||||
|
loadDataGrid();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
//@@ sourceURL=userManagerIndex.js
|
//@@ sourceURL=userManagerIndex.js
|
||||||
|
Loading…
Reference in New Issue
Block a user