Example #1
0
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            Condition c = null;

            foreach (string s in roleNames)
            {
                c |= CK.K["Name"] == s;
            }
            Condition cu = null;

            foreach (string s in usernames)
            {
                cu |= CK.K["UserName"] == s;
            }
            DbEntry.UsingTransaction(delegate
            {
                List <DbEntryMembershipUser> ls = DbEntryMembershipUser.Find(cu);
                foreach (DbEntryRole r in DbEntryRole.Find(c))
                {
                    foreach (DbEntryMembershipUser u in ls)
                    {
                        if (!r.Users.Contains(u))
                        {
                            r.Users.Add(u);
                        }
                    }
                    r.Save();
                }
            });
        }
Example #2
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            Condition c = null;

            foreach (string s in roleNames)
            {
                c |= CK.K["Name"] == s;
            }
            var uns = new List <string>();

            foreach (var username in usernames)
            {
                uns.Add(username);
            }
            DbEntry.UsingTransaction(delegate
            {
                var roles = DbEntryRole.Find(c);
                foreach (DbEntryRole r in roles)
                {
                    for (int i = r.Users.Count - 1; i >= 0; i--)
                    {
                        if (uns.Contains(r.Users[i].UserName))
                        {
                            r.Users.RemoveAt(i);
                        }
                    }
                    r.Save();
                }
            });
        }
Example #3
0
        public override string[] GetAllRoles()
        {
            var ls = new List <string>();

            foreach (DbEntryRole r in DbEntryRole.Find(Condition.Empty))
            {
                ls.Add(r.Name);
            }
            return(ls.ToArray());
        }