diff --git a/Bootstrap.DataAccess.MongoDB/Role.cs b/Bootstrap.DataAccess.MongoDB/Role.cs
index e733dcbc..ea1cf175 100644
--- a/Bootstrap.DataAccess.MongoDB/Role.cs
+++ b/Bootstrap.DataAccess.MongoDB/Role.cs
@@ -145,6 +145,31 @@ namespace Bootstrap.DataAccess.MongoDB
return true;
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable RetrieveRolesByGroupId(string groupId)
+ {
+ var roles = RoleHelper.RetrieveRoles();
+ var group = GroupHelper.RetrieveGroups().Cast().FirstOrDefault(u => u.Id == groupId);
+ roles.ToList().ForEach(r => r.Checked = group.Roles.Any(id => id == r.Id) ? "checked" : "");
+ return roles;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override bool SaveRolesByGroupId(string groupId, IEnumerable roleIds)
+ {
+ MongoDbAccessManager.Groups.FindOneAndUpdate(u => u.Id == groupId, Builders.Update.Set(u => u.Roles, roleIds));
+ return true;
+ }
+
///
///
///
diff --git a/Bootstrap.DataAccess.MongoDB/User.cs b/Bootstrap.DataAccess.MongoDB/User.cs
index 5cf27506..27b5605c 100644
--- a/Bootstrap.DataAccess.MongoDB/User.cs
+++ b/Bootstrap.DataAccess.MongoDB/User.cs
@@ -189,5 +189,46 @@ namespace Bootstrap.DataAccess.MongoDB
});
return true;
}
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable RetrieveUsersByGroupId(string groupId)
+ {
+ var users = UserHelper.RetrieveUsers().Cast().ToList();
+ users.ForEach(p => p.Checked = (p.Groups != null && p.Groups.Contains(groupId)) ? "checked" : "");
+ return users;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override bool SaveUsersByGroupId(string groupId, IEnumerable 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() : p.Groups.ToList();
+ groups.Remove(groupId);
+ MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders.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() : p.Groups.ToList();
+ groups.Add(groupId);
+ MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Groups, groups));
+ });
+ return true;
+ }
}
}