增加功能:部门管理增加分配用户/分配角色按钮功能
This commit is contained in:
parent
5c1780cc00
commit
99a8b5432d
|
@ -145,6 +145,31 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
public override IEnumerable<DataAccess.Role> RetrieveRolesByGroupId(string groupId)
|
||||
{
|
||||
var roles = RoleHelper.RetrieveRoles();
|
||||
var group = GroupHelper.RetrieveGroups().Cast<Group>().FirstOrDefault(u => u.Id == groupId);
|
||||
roles.ToList().ForEach(r => r.Checked = group.Roles.Any(id => id == r.Id) ? "checked" : "");
|
||||
return roles;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
public override bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
|
||||
{
|
||||
MongoDbAccessManager.Groups.FindOneAndUpdate(u => u.Id == groupId, Builders<Group>.Update.Set(u => u.Roles, roleIds));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -189,5 +189,46 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
public override IEnumerable<DataAccess.User> RetrieveUsersByGroupId(string groupId)
|
||||
{
|
||||
var users = UserHelper.RetrieveUsers().Cast<User>().ToList();
|
||||
users.ForEach(p => p.Checked = (p.Groups != null && p.Groups.Contains(groupId)) ? "checked" : "");
|
||||
return users;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public override bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
|
||||
{
|
||||
var users = MongoDbAccessManager.Users.Find(md => md.Groups != null && md.Groups.Contains(groupId)).ToList();
|
||||
|
||||
// Remove roles
|
||||
users.ForEach(p =>
|
||||
{
|
||||
var groups = p.Groups == null ? new List<string>() : p.Groups.ToList();
|
||||
groups.Remove(groupId);
|
||||
MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders<User>.Update.Set(md => md.Groups, groups));
|
||||
});
|
||||
|
||||
users = MongoDbAccessManager.Users.Find(md => userIds.Contains(md.Id)).ToList();
|
||||
// Add roles
|
||||
users.ForEach(p =>
|
||||
{
|
||||
var groups = p.Groups == null ? new List<string>() : p.Groups.ToList();
|
||||
groups.Add(groupId);
|
||||
MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders<User>.Update.Set(md => md.Groups, groups));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue