Departments


List of examples:

Departments

Creating a new department




// Creates a new department object
DepartmentInfo newDepartment = new DepartmentInfo();

// Sets the department properties
newDepartment.DepartmentDisplayName = "New department";
newDepartment.DepartmentName = "NewDepartment";
newDepartment.DepartmentSiteID = SiteContext.CurrentSiteID;

// Saves the department to the database
DepartmentInfoProvider.SetDepartmentInfo(newDepartment);


> Back to list of examples

Updating a department




// Gets the department
DepartmentInfo updateDepartment = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", SiteContext.CurrentSiteName);
if (updateDepartment != null)
{
    // Updates the department properties
    updateDepartment.DepartmentDisplayName = updateDepartment.DepartmentDisplayName.ToLower();

    // Saves the changes to the database
    DepartmentInfoProvider.SetDepartmentInfo(updateDepartment);
}


> Back to list of examples

Updating multiple departments




// Gets all departments whose code name starts with 'NewDepartment'
var departments = DepartmentInfoProvider.GetDepartments().WhereStartsWith("DepartmentName", "NewDepartment");

// Loops through the departments
foreach (DepartmentInfo modifyDepartment in departments)
{
    // Updates the department properties
    modifyDepartment.DepartmentDisplayName = modifyDepartment.DepartmentDisplayName.ToUpper();

    // Saves the changes to the database
    DepartmentInfoProvider.SetDepartmentInfo(modifyDepartment);
}


> Back to list of examples

Deleting a department




// Gets the department
DepartmentInfo deleteDepartment = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", SiteContext.CurrentSiteName);

if (deleteDepartment != null)
{
    // Deletes the department
    DepartmentInfoProvider.DeleteDepartmentInfo(deleteDepartment);
}


> Back to list of examples

Department tax classes

Applying tax classes to a department




// Gets the department
DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", SiteContext.CurrentSiteName);

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);

if ((department != null) && (taxClass != null))
{
    // Adds the tax class to the department
    department.DepartmentDefaultTaxClassID = taxClass.TaxClassID;

    // Saves the changes to the database
    DepartmentInfoProvider.SetDepartmentInfo(department);
}


> Back to list of examples

Removing tax classes from a department




// Gets the department
DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", SiteContext.CurrentSiteName);

if (department != null)
{
    // Removes the tax class to the department
    department.DepartmentDefaultTaxClassID = 0;

    // Saves the changes to the database
    DepartmentInfoProvider.SetDepartmentInfo(department);
}


> Back to list of examples