internal GroupPrincipalViewModel(GroupPrincipal group)
     : base(group)
 {
     foreach (var member in group.Members)
     {
         _memberViewModels.Add(new SecurityPrincipalViewModel(member));
     }
 }
Example #2
0
        private void UpdateGroupInternal(GroupPrincipal groupPrincipal)
        {
            var members = new XElement("Members",
                from m in groupPrincipal.Members.OfType<UserPrincipal>()
                select new XElement("Member", new XAttribute("userId", _users[m])),
                from g in groupPrincipal.Members.OfType<GroupPrincipal>()
                select new XElement("Member", new XAttribute("groupId", _groups[g])));

            //update general information about the client
            var updateCommand = new SqlCommand("sp_UpdateGroup", _connection) { CommandType = System.Data.CommandType.StoredProcedure };
            updateCommand.Parameters.Add(new SqlParameter("token", "null_token"));    //TODO: token will go here
            updateCommand.Parameters.Add(new SqlParameter("groupId", _groups[groupPrincipal]));
            updateCommand.Parameters.Add(new SqlParameter("groupName", groupPrincipal.Name));
            updateCommand.Parameters.Add(new SqlParameter("isAdmin", groupPrincipal.IsAdmin ? 1 : 0));
            updateCommand.Parameters.Add(new SqlParameter("members", members.ToString()));
            updateCommand.ExecuteNonQuery();

            _groups.SetItemClean(groupPrincipal);
        }
Example #3
0
        private GroupPrincipal CreateOrUpdateGroup(SqlDataReader reader, int idIndex, int nameIndex, int adminIndex, out bool createdNew)
        {
            int id = (int)reader[idIndex];

            GroupPrincipal group;
            if (!_groups.TryGetItem(id, out group))
            {
                group = new GroupPrincipal();
                _groups.Add(id, group);
                createdNew = true;
            }
            else
            {
                createdNew = false;
            }

            if (nameIndex != -1)
                group.Name = (string)reader[nameIndex];
            if (adminIndex != -1)
                group.IsAdmin = (bool)reader[adminIndex];

            return group;
        }