コード例 #1
0
 public CPGroup UpdateGroup(CPGroup group)
 {
     if (group == null)
     {
         return(null);
     }
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         var match = context.SecurityGroups.FirstOrDefault(g => g.GroupId == group.ID);
         if (match == null)
         {
             return(null);
         }
         match.GroupName  = group.Name;
         match.UserRights = (int)group.UserRights;
         try
         {
             context.SaveChanges();
         }
         catch (OptimisticConcurrencyException)
         {
             context.Refresh(RefreshMode.ClientWins, match);
             context.SaveChanges();
         }
         catch (ConstraintException)
         {
         }
         return(GetGroup(match.GroupName));
     }
 }
コード例 #2
0
ファイル: AccountExplorer.cs プロジェクト: simoncwu/CAccess
 /// <summary>
 /// Creates a tree node to represent a C-Access security group.
 /// </summary>
 /// <param name="group">The group represented by the tree node.</param>
 /// <returns>A new tree node that represents the specified group.</returns>
 private TreeNode CreateGroupNode(CPGroup group)
 {
     return(group == null ? null : new TreeNode(group.Name, _groupsImageIndex, _groupsImageIndex)
     {
         Name = group.Name,
         Tag = GroupNodeTag
     });
 }
コード例 #3
0
        private void _groupsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            CPUserRights rights = CPUserRights.None;
            IEnumerable  items  = _groupsListBox.SelectedItems.Count > 0 ? _groupsListBox.SelectedItems as IEnumerable : _groupsListBox.Items;

            foreach (var i in items)
            {
                CPGroup group = i as CPGroup;
                if (group == null)
                {
                    continue;
                }
                rights |= group.UserRights;
            }
            foreach (var flag in _permissionFlags)
            {
                CPUserRights flagRights;
                flag.Visible = Enum.TryParse(flag.Tag as string, out flagRights) && rights.HasRights(flagRights);
            }
        }
コード例 #4
0
        public CPUser CreateUser(string firstName, char?middleInitial, string lastName, string candidateID, string password, string email, string creator, EntityType type = EntityType.Generic, char?committeeID = null, string electionCycle = null, byte?liaisonID = null, string username = null)
        {
            if (username == null)
            {
                username = GenerateUserName(firstName, middleInitial, lastName, candidateID);
            }
            if (!string.IsNullOrWhiteSpace(username))
            {
                if (password == null)
                {
                    password = Membership.GeneratePassword(10, 0);
                }
                if (UserManagement.CreateUser(username, password, email, creator) != null)
                {
                    using (CPSecurityEntities context = new CPSecurityEntities())
                    {
                        switch (type) // sanitize CFIS source entity properties first
                        {
                        case EntityType.Liaison:
                            electionCycle = null;
                            break;

                        case EntityType.Treasurer:
                            liaisonID = null;
                            break;

                        default:
                            committeeID   = null;
                            electionCycle = null;
                            liaisonID     = null;
                            break;
                        }
                        context.DeleteSecurityUserProfile(username);
                        CPUser user = CPUserFactory.CreateUser(context.AddToSecurityUserProfiles(username, candidateID, Entity.ToFullName(firstName, lastName, middleInitial, false), type, committeeID, electionCycle, liaisonID));
                        if (user != null)
                        {
                            CPGroup group = GetGroup(type.ToString() + "s");
                            if (group != null)
                            {
                                AddUserToGroups(user.UserName, new List <byte>(new[] { group.ID }));
                            }
                            if (electionCycle != null)
                            {
                                user.ElectionCycles.Add(electionCycle);
                            }
                            if (!user.Save())
                            {
                                this.DeleteUser(user.UserName);
                                user = null;
                            }
                        }
                        else
                        {
                            UserManagement.DeleteUser(Membership.GetUser(username));
                        }
                        return(user);
                    }
                }
            }
            return(null);
        }
コード例 #5
0
 /// <summary>
 /// Updates a C-Access Security group.
 /// </summary>
 /// <param name="group">The group to update.</param>
 /// <returns>The resultant <see cref="CPGroup"/> after it has been updated.</returns>
 public CPGroup UpdateGroup(CPGroup group)
 {
     using (SecurityClient client = new SecurityClient()) { return(client.UpdateGroup(group)); }
 }