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
DepartmentInfo.Provider.Set(newDepartment);

> Back to list of examples

Updating a department



// Gets the department
DepartmentInfo updateDepartment = DepartmentInfo.Provider.Get("NewDepartment", SiteContext.CurrentSiteID);
if (updateDepartment != null)
{
    // Updates the department properties
    updateDepartment.DepartmentDisplayName = updateDepartment.DepartmentDisplayName.ToLower();

    // Saves the changes to the database
    DepartmentInfo.Provider.Set(updateDepartment);
}

> Back to list of examples

Updating multiple departments



// Gets all departments whose code name starts with 'NewDepartment'
var departments = DepartmentInfo.Provider.Get().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
    DepartmentInfo.Provider.Set(modifyDepartment);
}

> Back to list of examples

Deleting a department



// Gets the department
DepartmentInfo deleteDepartment = DepartmentInfo.Provider.Get("NewDepartment", SiteContext.CurrentSiteID);

if (deleteDepartment != null)
{
    // Deletes the department
    DepartmentInfo.Provider.Delete(deleteDepartment);
}

> Back to list of examples

Department tax classes

Applying tax classes to a department



// Gets the department
DepartmentInfo department = DepartmentInfo.Provider.Get("NewDepartment", SiteContext.CurrentSiteID);

// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

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

    // Saves the changes to the database
    DepartmentInfo.Provider.Set(department);
}

> Back to list of examples

Removing tax classes from a department



// Gets the department
DepartmentInfo department = DepartmentInfo.Provider.Get("NewDepartment", SiteContext.CurrentSiteID);

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

    // Saves the changes to the database
    DepartmentInfo.Provider.Set(department);
}

> Back to list of examples