/// <summary> /// Performs validation and business logic checks on the CopyCourseSectionAndContentRequest values /// </summary> /// <param name="request"><see cref="CreateCourseSectionRequest">object</see></param> /// <exception cref="ArgumentNullException">Thrown when a required value is not set in the <see cref="CreateCourseSectionRequest">object</see></exception> /// <exception cref="ArgumentException">Thrown when there is a conflict between the values in the <see cref="CreateCourseSectionRequest">object</see></exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when a value in the <see cref="CreateCourseSectionRequest">object</see> is invalid.</exception> private static void ValidateCreateCourseSectionRequest(CreateCourseSectionRequest 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.PrimaryClientSortString == null) throw new ArgumentNullException("The PrimaryClientSortString value is required. Please correct and try the request again."); else if (request.DestinationCourseCallNumber == null) throw new ArgumentNullException("The DestinationCourseCallNumber value is required. Please correct and try the request again."); else if (request.DestinationTermId == null && request.DestinationTermSourcedId == null) throw new ArgumentNullException("Either a DestinationTermId or DestinationTermSourcedId value is required. Please correct and try the request again."); else if (request.DisplayCourseCode == null) throw new ArgumentNullException("The DisplayCourseCode value is required. Please correct and try the request again."); else if (request.SectionTitle == null) throw new ArgumentNullException("The SectionTitle value is required. Please correct and try the request again."); else if (request.DestinationTermId != null && request.DestinationTermSourcedId != null) throw new ArgumentException("The DestinationTermId and DestinationTermSourcedId values are mutually exclusive. Only set one of the values for a given Destination Term. Please correct and try the request again."); else if (request.SectionNumber > 255) throw new ArgumentOutOfRangeException("The SectionNumber has a Maximum allowed Value of 255. Please correct and try the request again."); else if (request.DestinationTermSourcedId != null) if (!request.DestinationTermSourcedId.Contains(":")) throw new ArgumentOutOfRangeException("The DestinationTermSourcedId 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."); }
/// <summary> /// Creates the XML payload for the CreateCourseSection Course API Request /// </summary> /// <param name="request"><see cref="CreateCourseSectionRequest">object</see></param> /// <returns><see cref="API.CourseMessage"/>object</returns> private API.CourseMessage SetCreateCourseSectionRequest(CreateCourseSectionRequest request) { // Initialize and Set the CopyCourseSectionRequest API.CourseMessage createCourse = new API.CourseMessage(); createCourse.BillingClassification = request.BillingClassification; createCourse.ClientString = request.ClientString; createCourse.CourseVersion = API.CourseType.DotNext; createCourse.DestinationCourseIdentifier = new API.CourseIdentifier(); createCourse.DestinationCourseIdentifier.ID = request.DestinationCourseCallNumber; createCourse.DestinationCourseIdentifier.MappingType = API.MappedIDType.CallNumber; createCourse.DestinationTermIdentifier = new API.TermIdentifier(); // Set the Destination Term Identifier accordingly if (request.DestinationTermId != null) { createCourse.DestinationTermIdentifier.ID = INTERNAL_IDENTIFIER + request.DestinationTermId; createCourse.DestinationTermIdentifier.MappingType = API.MappedTermIDType.TermID; } else { createCourse.DestinationTermIdentifier.ID = request.DestinationTermSourcedId; createCourse.DestinationTermIdentifier.MappingType = API.MappedTermIDType.SourcedID; } createCourse.DisplayCourseCode = request.DisplayCourseCode; createCourse.IsEnrollable = true; createCourse.PrimaryClientSortString = request.PrimaryClientSortString; createCourse.SectionDescription = request.SectionDescription; createCourse.SectionNumber = request.SectionNumber; createCourse.SectionTitle = request.SectionTitle; return createCourse; }
/// <summary> /// Generates a CreateCourseSection Course API Request /// </summary> /// <param name="request"><see cref="CreateCourseSectionRequest">object</see></param> /// <returns><see cref="Response"/>object</returns> public Response CreateCourseSection(CreateCourseSectionRequest request) { API.CourseMessage createCourse = null; Response response = null; try { // Validate the Request Object ValidateCreateCourseSectionRequest(request); // Intialize and Set the CreateCourseSectionRequest createCourse = SetCreateCourseSectionRequest(request); // Build the Response object from the SOAP response response = ReadCreateCourseSectionResponse(createCourse); } catch (Exception ex) { Logger.Error("Exception from CreateCourseSection: ", ex); throw; } finally { if (this.courseAPI != null) this.courseAPI.Close(); } return response; }