USP_DATAFORMTEMPLATE_ADD_COURSERESTRICTION

The save procedure used by the add dataform template "Course Restriction Add Data Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@COURSEID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@SESSIONSTARTDATE date IN Session
@SESSIONENDDATE date IN Session
@LENGTHINTERMS int IN Terms in length
@STARTTERMS xml IN Starting in terms
@PATTERNID uniqueidentifier IN Pattern
@COURSEGRADINGID uniqueidentifier IN
@COURSEGRADINGMARKINGCOLUMNS xml IN

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_COURSERESTRICTION
(
    @ID uniqueidentifier = null output,
    @COURSEID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @SESSIONSTARTDATE date = null,
    @SESSIONENDDATE date = null,
    @LENGTHINTERMS integer = 1,
    @STARTTERMS xml = null,
    @PATTERNID uniqueidentifier = null,
    @COURSEGRADINGID uniqueidentifier = null,
    @COURSEGRADINGMARKINGCOLUMNS xml = null
)
as

set nocount on;

if @ID is null
    set @ID = newid()

if @CHANGEAGENTID is null  
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

begin try

    -- handle inserting the data

    insert into dbo.COURSERESTRICTION
        (ID, COURSEID, STARTDATE, ENDDATE, LENGTHINTERMS, PATTERNID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
    values
        (@ID, @COURSEID, @SESSIONSTARTDATE, @SESSIONENDDATE, @LENGTHINTERMS, @PATTERNID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)

    exec dbo.USP_COURSERESTRICTION_GETSTARTTERMS_ADDFROMXML @ID, @STARTTERMS, @CHANGEAGENTID, @CURRENTDATE;

    -- validate LENGTHINTERMS vs. selected STARTTERMS; these can be edited at either parent or child level, so validating here after both have been saved

    if dbo.UFN_COURSERESTRICTION_LENGTHINTERMS_VALID(@ID, @LENGTHINTERMS) = 0 
        raiserror('CK_COURSERESTRICTION_LENGTHINTERMS_VALID', 13, 1)

    if @COURSEGRADINGID is not null
        exec dbo.USP_COURSEGRADING_GETMARKINGCOLUMNS_UPDATEFROMXML @COURSEGRADINGID, @COURSEID, @SESSIONSTARTDATE, @SESSIONENDDATE, @COURSEGRADINGMARKINGCOLUMNS, @CHANGEAGENTID, @CURRENTDATE;    
end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0