---
title: Departments
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

## Departments

### Creating a new department

```csharp

// 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](#toc)

### Updating a department

```csharp

// 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](#toc)

### Updating multiple departments

```csharp

// 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](#toc)

### Deleting a department

```csharp

// 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](#toc)

## Department tax classes

### Applying tax classes to a department

```csharp

// 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](#toc)

### Removing tax classes from a department

```csharp

// 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](#toc)
