コード例 #1
0
        /// <summary>
        /// Remove a user.
        /// </summary>
        /// <param name="user">The user to remove.</param>
        private void RemoveUser(User user)
        {
            try
            {
                AdminSupportClient adminSupportClient = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint);

                adminSupportClient.DisableUserAccount(user.IdentityName);
                adminSupportClient.Close();
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
                this.Dispatcher.BeginInvoke(new Action(() =>
                                                       MessageBox.Show(this, String.Format(Properties.Resources.DeleteUserFailed, user), this.Title)));
            }
        }
コード例 #2
0
ファイル: User.cs プロジェクト: radtek/credit-card-exchange
        /// <summary>
        /// Commit any changes to this user to the server.
        /// </summary>
        public override void Commit()
        {
            AdminSupportClient client = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint);

            AdminSupportReference.User user = new AdminSupportReference.User();
            MethodResponseErrorCode    response;

            this.PopulateRecord(user);

            if (this.Deleted)
            {
                response = client.DeleteUserAccount(user.LookupId);

                if (this.GetFirstErrorCode(response) == ErrorCode.RecordNotFound)
                {
                    throw new UserNotFoundException(this, "User not found");
                }
            }
            else
            {
                response = client.UpdateUser(new AdminSupportReference.User[] { user });

                if (this.GetFirstErrorCode(response) == ErrorCode.RecordNotFound)
                {
                    throw new UserNotFoundException(this, "User not found");
                }

                if (response.IsSuccessful)
                {
                    if (this.AccountDisabled)
                    {
                        response = client.DisableUserAccount(this.IdentityName);
                    }
                }

                if (response.IsSuccessful)
                {
                    lock (DataModel.SyncRoot)
                    {
                        List <Group>    newGroups = this.Groups.ToList();
                        List <Guid>     add       = new List <Guid>();
                        List <Guid>     del       = new List <Guid>();
                        GroupUsersRow[] oldGroups = DataModel.User.UserKey.Find(this.UserId).GetGroupUsersRows();
                        ErrorCode       firstError;

                        foreach (GroupUsersRow groupUsersRow in oldGroups)
                        {
                            Group group = newGroups.FirstOrDefault(g => g.GroupId == groupUsersRow.GroupId);

                            if (group == null)
                            {
                                del.Add(groupUsersRow.GroupId);
                            }
                            else
                            {
                                if (group.Deleted)
                                {
                                    del.Add(group.GroupId);
                                }
                                newGroups.Remove(group);
                            }
                        }

                        foreach (Group group in newGroups)
                        {
                            response = client.AddUserToGroup(this.IdentityName, group.GroupId, this.TenantId);

                            firstError = this.GetFirstErrorCode(response);

                            if (firstError == ErrorCode.RecordNotFound)
                            {
                                throw new GroupNotFoundException(this.DefaultGroup, "Group not found");
                            }
                            else if (firstError != ErrorCode.Success)
                            {
                                break;
                            }
                        }

                        foreach (Guid group in del)
                        {
                            response = client.RemoveUserFromGroup(this.IdentityName, group);

                            firstError = this.GetFirstErrorCode(response);

                            if (firstError != ErrorCode.RecordNotFound && firstError != ErrorCode.Success)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (!response.IsSuccessful)
            {
                GuardianObject.ThrowErrorInfo(response.Errors[0]);
            }

            client.Close();

            this.Modified = false;
        }