Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec#
var p = C.ManagementRole.GetByPersonID(3150);
 
//Write the results to the console
if (p.Count > 0)
{
   Console.WriteLine("{0} has the following Management Roles: ", C.Person.GetByPersonID(3150).FriendlyName);
   foreach (var a in p)
      Console.WriteLine(a.FriendlyName);
}

Get People in Business Role and Location

Code Block
languagec#
string columnsToSearch = "Friendly Name"string textToSearch = "Standard Employee in Temporary Location ";
 
E.VList<C.PersonView> p = C.PersonView.GetByOrgRoleOrgZoneID(2309, columnsToSearch, textToSearch);

Get People in a Group

Code Block
languagec#
var grMembers = C.Person.GetByGroupID(66);
 
//Write the results to the console
if(grMembers.Count > 0)
{
  Console.WriteLine("{0} has {1} members.", C.Group.GetByGroupID(66).FriendlyName, p.Count.ToString());
  foreach (var m in grMembers)
      Console.WriteLine(m.FriendlyName);
}

Get a Person's Group memberships

Code Block
languagec#
var grMemberships = C.GroupView.GetByPersonID(3148)
 
//Write the results to the console
foreach(var gr in grMemberships)
Console.WriteLine("{0} is a member of {1}", C.Person.GetByPersonID(3150).FriendlyName, gr.FriendlyName);

Check specific access to a resource

Code Block
languagec#
//In this example, we pass in the specific PersonID, ResourceID, and Operation
string operation = "List";
int resourceID = 93;
int personID = 3150;
var hasAccess = C.Resource.HasAccess(personID, resourceID, operation);
 
//Write the results to the console
Console.WriteLine(hasAccess);

Check all access to a resource

Code Block
languagec#
//Pass in the PersonID
int personID = 3148;
 
//Pass in the ResourceID
int resourceID = 953500;
 
//Check the allowed operations
var allowedOperations = C.ResourceTypeOperation.GetByPersonIDAndResourceID(personID, resourceID);
 
//Write the results to the console
Console.WriteLine("{0} has the following operations allowed for {1}: ", C.Person.GetByPersonID(3148).FriendlyName,  C.Resource.GetByResourceID(953500).FriendlyName);
foreach(var operation in allowedOperations)
   Console.WriteLine(operation.Name);

Get People able to execute an operation against a resource

Code Block
languagec#
//In this example, we pass in the ResourceID of the resource and the name of the Operation
int resourceID = 1183422;
string operation = "MoveMailbox";
var whoHasAccess = C.Resource.GetPeopleWithAccess(resourceID, operation);
 
//Write the results to the console
foreach(var person in whoHasAccess)
   Console.WriteLine(person.FriendlyName);

Get all operations executed by a Person

Code Block
var columnsToSearch = " ";
var textToSearch = " ";
var operationsExecutedByPerson = C.BusinessProcessTaskSlotView.GetByPersonID(3148, columnsToSearch, textToSearch);
 
//Write the results to the console
foreach (var operation in operationsExecutedByPerson)
 Console.WriteLine(operation.BusinessProcessTaskFriendlyName);

Working with User Accounts

In EmpowerID, user accounts are Identity Warehouse objects that represent the user accounts in external account stores, such as Active Directory or Office 365. User accounts are generally linked to EmpowerID Person objects, and as such, any actions performed against an account can affect the Person objects to which they are linked and vice-versa. As with the EmpowerID Person, the Workflow Studio object model contains two namespaces with multiple classes for working with accounts in EmpowerID—the People.Components namespace and the People.Entities namespace.

Info

Required Namespaces

When working with Account objects, minimally you should add references to the following namespaces:

Code Block
languagec#
using TheDotNetFactory.Framework;
using TheDotNetFactory.FrameWork.Common;
using TheDotNetFactory.FrameWork.Common.Shared;
using TheDotNetFactory.Framework.Core;
using C = TheDotNetFactory.Framework.People.Components;
using E = TheDotNetFactory.Framework.People.Entities;

Create an account and a Person linked to the account

Code Block
//Create a new account, add it to an account store, and set some properties for it
C.AccountStore accStore = C.AccountStore.GetByAccountStoreID(259);
C.Account acc = new C.Account();
acc.AccountStoreID = 259;
acc.Name = "Jacques Clouseay";
acc.LogonName = "jClouseay";
acc.CreatedDate = DateTime.UtcNow;
acc.DistinguishedName = "CN=Jacques Clouseay,OU=Sydney,OU=Offices,DC=tdnfdemo,DC=com";
 
//Create the account and set the password for it
acc.Create(acc, "pass@word1");
  
//Create an EmpowerID Person for the account
C.Person per = new C.Person();
per.FirstName = acc.FirstName;
per.LastName = acc.LastName;
per.Name = acc.Name;
per.Login = acc.LogonName;
acc.PersonID = per.PersonID;
  
//Write the results to the console
Console.WriteLine("New Person: {0} created from Account: {1}", per.Name, acc.Name);

Move an account

Code Block
languagec#
//Get the account you wish to move by AccountID
var acc = C.Account.GetByAccountID(3120);
  
//Move the account, passing in the new OU path
acc.Move("OU=New Mexico,OU=Offices,DC=tdnfdemo,DC=com");
  
//Write the results to the console
Console.WriteLine(acc.ResourceIDSource.ParentOU);
  
//Verify the move occurred in the Account Store
Console.WriteLine(acc.AccountStoreIdentityEntry.Path);

Add an account to a group

Code Block
languagec#
//Create a new Group TList and add a group to the list
var groupList = new TList<C.Group>();
groupList.Add(C.Group.GetByGroupID(66));
  
//Add the account to the groups in the list
var account = C.Account.GetByAccountID(26471).AddToGroups(groupList);
  
//Write the results to the console
var acc = C.AccountView.GetByGroupID(66, columnsToSearch: "", textToSearch: "");
foreach (var a in acc)
   if (a.AccountID == 26471)
    Console.WriteLine(a.Name);

Restore deleted accounts

Code Block
languagec#
//Retrieve deleted accounts
var deletedAccounts = C.Account.GetByDeleted(true);
  
//Restore each account in the list of deleted accounts
foreach(var acc in deletedAccounts)
    acc.RestoreDeletedAccount();

Join an account to a Person

Code Block
languagec#
//Call JoinAccountToPerson(), passing in the AccountID and PersonID
//Person cannot currently have an account
 
var person = C.Person.JoinAccountToPerson(7824, 3194);

Remove an account from a Person

Code Block
languagec#
//Call UnJoinAccountToPerson(), passing in the AccountID
 
var person = C.Person.UnJoinAccountToPerson(7824);

Unlock all locked accounts

Code Block
languagec#
//Return a list of locked out accounts
var account = C.Account.GetByLockedOut(true);
  
//Unlock each account in the list
foreach(var acc in account)
    acc.Unlock();

Create mailbox for user

Code Block
languagec#
//Add reference for TheDotNetFactory.Framework.People.Common.Enum to your project for access to the ExchangeMailboxTypeList enum
  
//Return an account without a mailbox
var accountCollection = C.AccountView.GetNonMailboxAccountsByAccountStoreID("LogonName", "jclouseay");
//Get the account store
var accStore = C.AccountStore.GetByFQN("exchange.com");
  
//Configure the mailbox you are creating
foreach (var acc in accountCollection)
{
   var mailboxConfig = new C.MailBoxConfig();
   mailboxConfig.AccountStore = accStore;
   mailboxConfig.Alias = acc.LogonName;
   mailboxConfig.cn = acc.Name;
   mailboxConfig.MasterAccountID = acc.DistinguishedName;
  
   //Set the MailboxContainer
   var mailboxContainer = C.ExchangeMailboxObjectContainer.GetByMostAvailableSpace();
   foreach (var mBC in mailboxContainer)
       mailboxConfig.MailboxContainer = mBC;
   mailboxConfig.AccountStore = accStore;
   mailboxConfig.Path = acc.DistinguishedName;
    
   //Person linked with the account
   var owner = C.Person.GetByLogin(acc.LogonName);
 
   //Set the account
   var targetAccount = C.Account.GetByAccountID(acc.AccountID);
                    
   //Create the mailbox, passing in owner, targetAccount, and mailboxConfig
   //Also set the type of mailbox and process it immediately
   var createMailbox = C.ExchangeMailbox.CreateMailbox(owner, targetAccount, mailboxConfig, ExchangeMailboxTypeList.UserMailbox, refreshRbac: true, sendToQueue: false);
                     
    //Write the results to the console
    Console.WriteLine("Mailbox with MailboxID: {0} has been created for Account: {1}", createMailbox.ExchangeMailboxID,        CreateteMailbox.AccountIDSource.FriendlyName);
}