Public/Edit-AeriesStaffAssignment.ps1

function Edit-AeriesStaffAssignment
{
    <#
        .SYNOPSIS
        Edit a Staff Assignment in Aeries

        .DESCRIPTION
        The Edit-AeriesStaffAssignment cmdlet is used to edit a Staff Assignment in Aeries
        If the AssignmentType is classified, a max of 3 characters is allowed for JobClassification
        If the AssignmentType is certificated, a max of 2 characters is allowed for JobClassification

        .EXAMPLE
        Edit-AeriesStaffAssignment -StaffID 1 -AssignmentType "classified" -Sequence 1
        This will edit a Staff Assignment for Staff ID 1 with an Assignment Type of "classified" and Sequence of 1 in Aeries
    #>


    [CmdletBinding()]
    param (
        [ValidateRange(1, [Int]::MaxValue)]
        [Parameter(Mandatory=$true)]
        [int]
        $StaffID,

        [ValidateSet("classified", "certificated")]
        [Parameter(Mandatory=$true)]
        [string]
        $AssignmentType,

        [ValidateRange(1, [Int16]::MaxValue)]
        [Parameter(Mandatory=$true)]
        [Int16]
        $Sequence,

        [ValidateScript({
            if ([string]::IsNullOrWhiteSpace($_))
            {
                <# If the passed in value is blank or null, accept it #>
                return $true
            }
            elseif ($AssignmentType -eq "classified")
            {
                <# Classified can have up to 3 character codes #>
                return ($_.Length -le 3)
            }
            elseif ($AssignmentType -eq "certificated")
            {
                <# Certificated can have up to 2 character codes #>
                return ($_.Length -le 2)
            }
            else {
                return $false
            }
        })]
        [Parameter(Mandatory=$false)]
        [string]
        $JobClassification,

        [Parameter(Mandatory=$false)]
        [double]
        $FullTimePercentage = -1,

        [ValidateLength(0,4)]
        [Parameter(Mandatory=$false)]
        [string]
        $NonClassroomBasedJobAssignment1,

        [ValidateLength(0,4)]
        [Parameter(Mandatory=$false)]
        [string]
        $NonClassroomBasedJobAssignment2,

        [ValidateLength(0,4)]
        [Parameter(Mandatory=$false)]
        [string]
        $NonClassroomBasedJobAssignment3,

        [ValidateLength(0,4)]
        [Parameter(Mandatory=$false)]
        [string]
        $NonClassroomBasedJobAssignment4,

        [ValidateLength(0,4)]
        [Parameter(Mandatory=$false)]
        [string]
        $NonClassroomBasedJobAssignment5,

        [ValidateLength(0,4)]
        [Parameter(Mandatory=$false)]
        [string]
        $NonClassroomBasedJobAssignment6,

        [ValidateLength(0,4)]
        [Parameter(Mandatory=$false)]
        [string]
        $NonClassroomBasedJobAssignment7,

        [ValidateRange(1, [Int16]::MaxValue)]
        [Parameter(Mandatory=$false)]
        [Int16]
        $SchoolCode = -1,

        [Parameter(Mandatory=$false)]
        [datetime]
        $StartDate,

        [Parameter(Mandatory=$false)]
        [datetime]
        $EndDate
    )

    Begin {
        Write-Verbose -Message "Begin running $($MyInvocation.MyCommand)"

        $Method = "Put"
        $SuccessStatusCode = 200,201
        $Endpoint = "v5/staff/$StaffID/assignments/$AssignmentType/$Sequence"
        $ContentType = "application/json"
        $Body = @{}
    }

    Process {
        If (![string]::IsNullOrWhiteSpace($JobClassification)) {
            <# String value #>
            $Body.JobClassification = $JobClassification
        }

        If ($FullTimePercentage -gt -1) {
            <# double value #>
            $Body.FullTimePercentage = $FullTimePercentage
        }

        If ($AssignmentType -eq "certificated") {
            <# These only apply for Certificated #>

            If (![string]::IsNullOrWhiteSpace($NonClassroomBasedJobAssignment1)) {
                <# String value #>
                $Body.NonClassroomBasedJobAssignment1 = $NonClassroomBasedJobAssignment1
            }

            If (![string]::IsNullOrWhiteSpace($NonClassroomBasedJobAssignment2)) {
                <# String value #>
                $Body.NonClassroomBasedJobAssignment2 = $NonClassroomBasedJobAssignment2
            }

            If (![string]::IsNullOrWhiteSpace($NonClassroomBasedJobAssignment3)) {
                <# String value #>
                $Body.NonClassroomBasedJobAssignment3 = $NonClassroomBasedJobAssignment3
            }

            If (![string]::IsNullOrWhiteSpace($NonClassroomBasedJobAssignment4)) {
                <# String value #>
                $Body.NonClassroomBasedJobAssignment4 = $NonClassroomBasedJobAssignment4
            }

            If (![string]::IsNullOrWhiteSpace($NonClassroomBasedJobAssignment5)) {
                <# String value #>
                $Body.NonClassroomBasedJobAssignment5 = $NonClassroomBasedJobAssignment5
            }

            If (![string]::IsNullOrWhiteSpace($NonClassroomBasedJobAssignment6)) {
                <# String value #>
                $Body.NonClassroomBasedJobAssignment6 = $NonClassroomBasedJobAssignment6
            }

            If (![string]::IsNullOrWhiteSpace($NonClassroomBasedJobAssignment7)) {
                <# String value #>
                $Body.NonClassroomBasedJobAssignment7 = $NonClassroomBasedJobAssignment7
            }
        }

        If ($SchoolCode -gt -1) {
            <# Int16 value #>
            $Body.SchoolCode = $SchoolCode
        }

        If (![string]::IsNullOrWhiteSpace($StartDate)) {
            <# Datetime value #>
            $Body.StartDate = $StartDate.ToString("yyyy-MM-dd")
        }

        If (![string]::IsNullOrWhiteSpace($EndDate)) {
            <# Datetime value #>
            $Body.EndDate = $EndDate.ToString("yyyy-MM-dd")
        }

        <# Turn the $Body variable into a JSON string for sending to the server #>
        $BodyJSON = ($Body | ConvertTo-Json -Compress)

        $Result = (Invoke-AeriesApiCall -Method $Method -Endpoint $Endpoint -SuccessStatusCode $SuccessStatusCode -Body $BodyJSON -ContentType $ContentType)
    }

    End {
        Write-Verbose -Message "Finish running $($MyInvocation.MyCommand)"
        return $Result
    }
}