public static UsersSource GetUsers() { IUserManagementDataAccessAgent agent; IEnumerable <User> users; UsersSource usersDataSet; System.Configuration.Configuration configuration = DicomDemoSettingsManager.GetGlobalPacsConfiguration(); agent = DataAccessFactory.GetInstance(new UserManagementDataAccessConfigurationView(configuration, PacsProduct.ProductName, PacsProduct.ServiceName)).CreateDataAccessAgent <IUserManagementDataAccessAgent> ( ); users = agent.GetUsers( ); usersDataSet = new UsersSource( ); foreach (User userData in users) { UsersSource.UsersRow user; user = usersDataSet.Users.NewUsersRow( ); user.UserName = userData.UserName; user.IsAdmin = userData.IsAdmin; usersDataSet.Users.AddUsersRow(user); } usersDataSet.AcceptChanges( ); return(usersDataSet); }
public static void UpdateUsers(UsersSource users) { IUserManagementDataAccessAgent agent; UsersSource usersDataSet; if (null == AuthenticatedUser) { throw new SecurityException("User is not authenticated."); } if (!AuthenticatedUser.IsAdmin) { throw new SecurityException("Authenticated User doesn't have permissions."); } agent = GetDataAccessAgent( ); usersDataSet = ( UsersSource )users.GetChanges( ); if (null == usersDataSet) { return; } foreach (UsersSource.UsersRow user in usersDataSet.Users) { if (user.RowState == DataRowState.Added) { if (user.IsNewPasswordNull( )) { throw new InvalidOperationException("New user has no password."); } agent.AddUser(user.UserName, user.NewPassword, user.IsAdmin); } else if (user.RowState == DataRowState.Deleted) { agent.RemoveUser(user.Field <string> (usersDataSet.Users.UserNameColumn, DataRowVersion.Original)); } else if (user.RowState == DataRowState.Modified) { agent.SetAdminUser(user.UserName, user.IsAdmin); if (!user.IsNewPasswordNull( )) { agent.SetUserPassword(user.UserName, user.NewPassword); } } } users.AcceptChanges( ); }