/// <summary>
        /// Creates the XML payload for the CreateStandardTerm Term API Request
        /// </summary>
        /// <param name="request"><see cref="CreateStandardTermRequest">object</see></param>
        /// <returns><see cref="API.StandardTermEx"/>object</returns>
        private API.StandardTermEx SetCreateStandardTermRequest(CreateStandardTermRequest request)
        {
            // Initialize and Set the CreateStandardTermRequest
            API.StandardTermEx createTerm = new API.StandardTermEx();
            createTerm.ClientString = request.ClientString;
            createTerm.BillingClassificationType = request.BillingClassificationType.ToString();

            // Set the Nodes the Term will be tied to accordingly
            if (request.AssociatedEPOrganization != null)
                createTerm.AssociatedEPOrganization = request.AssociatedEPOrganization;
            else
                createTerm.AssociatedEPOrganization = new string[] { ALL_NODES };

            // Set the various Term timeframe properties
            createTerm.CourseActualTimeFrame = new API.TimeFrame();
            createTerm.CourseActualTimeFrame.StartDate = request.CourseActualStartDate;
            createTerm.CourseActualTimeFrame.EndDate = request.CourseActualEndDate;
            createTerm.DropAddPeriodTimeFrame = new API.TimeFrame();
            createTerm.DropAddPeriodTimeFrame.StartDate = request.DropAddPeriodStartDate;
            createTerm.DropAddPeriodTimeFrame.EndDate = request.DropAddPeriodEndDate;
            createTerm.TermTimeFrame = new API.TimeFrame();
            createTerm.TermTimeFrame.StartDate = request.TermStartDate;
            createTerm.TermTimeFrame.EndDate = request.TermEndDate;

            if (request.RegistrationStartDate != null)
            {
                createTerm.RegistrationTimeFrame = new API.TimeFrame();
                createTerm.RegistrationTimeFrame.StartDate = request.RegistrationStartDate;
                createTerm.RegistrationTimeFrame.EndDate = request.RegistrationEndDate;
            }

            if (request.WithdrawPeriodEndsOn != null)
                createTerm.WithdrawPeriodEndsOn = request.WithdrawPeriodEndsOn;

            createTerm.Name = request.Name;
            createTerm.Description = request.Description;
            createTerm.TermTypeCode = API.TermType.Standard;

            // Set the Destination Term Identifier
            createTerm.ID = new API.TermIdentifier();
            createTerm.ID.ID = request.TermSourcedId;
            createTerm.ID.MappingType = API.MappedTermIDType.SourcedID;

            return createTerm;
        }
        /// <summary>
        /// Generates a CreateStandardTerm Term API Request
        /// </summary>
        /// <param name="request"><see cref="CreateStandardTermRequest">object</see></param>
        /// <returns><see cref="Response"/>object</returns>
        public Response CreateStandardTerm(CreateStandardTermRequest request)
        {
            API.StandardTermEx createTerm = null;
            Response response = null;

            try
            {
                // Validate the Request Object
                ValidateCreateStandardTermRequest(request);

                // Intialize and Set the CopyCourseContentRequest
                createTerm = SetCreateStandardTermRequest(request);

                // Build the Response object from the SOAP response
                response = ReadCreateStandardTermResponse(createTerm);
            }
            catch (Exception ex)
            {
                Logger.Error("Exception from CreateStandardTerm: ", ex);
                throw;
            }
            finally
            {
                if (this.termAPI != null)
                    this.termAPI.Close();
            }

            return response;
        }
 /// <summary>
 /// Performs validation and business logic checks on the CreateStandardTermRequest values
 /// </summary>
 /// <param name="request"><see cref="CreateStandardTermRequest">object</see></param>
 /// <exception cref="ArgumentNullException">Thrown when a required value is not set in the <see cref="CreateStandardTermRequest">object</see></exception>
 /// <exception cref="ArgumentException">Thrown when there is a conflict between the values in the <see cref="CreateStandardTermRequest">object</see></exception>
 /// <exception cref="ArgumentOutOfRangeException">Thrown when a value in the <see cref="CreateStandardTermRequest">object</see> is invalid.</exception>
 private static void ValidateCreateStandardTermRequest(CreateStandardTermRequest request)
 {
     // Perform a Parameter Validation and Business Logic Check on the Request
     if (request.ClientString == null)
         throw new ArgumentNullException("The ClientString value is required.  Please correct and try the reqeust again.");
     else if (request.CourseActualStartDate == null || request.CourseActualStartDate == DateTime.MinValue)
         throw new ArgumentNullException("The CourseActualStartDate value is required.  Please correct and try the request again.");
     else if (request.CourseActualEndDate == null  || request.CourseActualEndDate == DateTime.MinValue)
         throw new ArgumentNullException("The CourseActualEndDate value is required.  Please correct and try the request again.");
     else if (request.DropAddPeriodStartDate == null || request.DropAddPeriodStartDate == DateTime.MinValue)
         throw new ArgumentNullException("The DropAddPeriodStartDate value is required.  Please correct and try the request again.");
     else if (request.DropAddPeriodEndDate == null  || request.DropAddPeriodEndDate == DateTime.MinValue)
         throw new ArgumentNullException("The DropAddPeriodEndDate value is required.  Please correct and try the request again");
     else if (request.TermSourcedId == null)
         throw new ArgumentNullException("The TermSourcedId values is required.  Please correct and try the request again");
     else if (request.Name == null)
         throw new ArgumentNullException("The Name value is required.  Please correct and try the request again.");
     else if (request.TermStartDate == null || request.TermStartDate == DateTime.MinValue)
         throw new ArgumentNullException("The TermStartDate value is required.  Please correct and try the request again.");
     else if (request.TermEndDate == null || request.TermEndDate == DateTime.MinValue)
         throw new ArgumentNullException("The TermEndDate value is required.  Please correct and try the request again.");
     else if (request.DropAddPeriodStartDate == request.CourseActualStartDate)
         throw new ArgumentException("The DropAddPeriodStartDate value is set to the CourseActualStartDate.  This could cause downstream integration issues with the LearningStudio Enrollment API.  " +
             "Best practice is to set the DropAddPeriodEndDate = CourseActualEndDate and set the DropAddPeriodStartDate = (CourseActualEndDate - 1 Day).  Please correct and try the request again.");
     else if (request.CourseActualEndDate <= request.CourseActualStartDate)
         throw new ArgumentOutOfRangeException("The CourseActualStartDate must be before the CourseActualEndDate.  Please correct and try the request again.");
     else if (request.DropAddPeriodEndDate <= request.DropAddPeriodStartDate)
         throw new ArgumentOutOfRangeException("The DropAddPeriodStartDate must be before the DropAddPeriodEndDate.  Best practice is to set the DropAddPeriodEndDate = CourseActualEndDate and set the " +
             "DropAddPeriodStartDate = (CourseActualEndDate - 1 Day).  Please correct and try the request again.");
     else if (request.TermEndDate <= request.TermStartDate)
         throw new ArgumentOutOfRangeException("The TermStartDate must be before the TermEndDate.  Please correct and try the request again.");
     else if (!request.TermSourcedId.Contains(":"))
         throw new ArgumentOutOfRangeException("The TermSourcedId should have a format of \"{Source}:{Id}\".  Note the colon delimiter that seperates the two concatenated values.  " +
             "In addition, please use your ClientString as the {Source} portion of this concatenated value.  Please correct and try the request again.");
     else if (request.RegistrationEndDate != DateTime.MinValue && request.RegistrationStartDate != DateTime.MinValue)
     {
         if (request.RegistrationEndDate <= request.RegistrationStartDate)
             throw new ArgumentOutOfRangeException("The RegistrationStartDate must be before the RegistrationEndDate.  Please correct and try the request again.");
     }
 }