USP_REGISTRANTREGISTRATION_DELETE

Executes the "Registrant Registration: Delete" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being deleted.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the delete.

Definition

Copy


                    create procedure dbo.USP_REGISTRANTREGISTRATION_DELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    )
                    as
                        set nocount on;

                        --check deletion rules, if any


                        declare @contextCache varbinary(128);

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

                        declare @CURRENTDATE datetime;
                        set @CURRENTDATE = getdate();

                        begin try
                            /* cache current context information */
                            set @contextCache = CONTEXT_INFO();

                            /* set CONTEXT_INFO to @CHANGEAGENTID */
                            set CONTEXT_INFO @CHANGEAGENTID;

                            -- Clear any other registrant registration maps that point to the same registrant package

                            -- other registrations from a package are now considered single event registrations

                            update dbo.REGISTRANTREGISTRATIONMAP
                            set
                                REGISTRANTPACKAGEID = null,
                                DATECHANGED = @CURRENTDATE,
                                CHANGEDBYID = @CHANGEAGENTID
                            from
                                dbo.REGISTRANTREGISTRATIONMAP
                                inner join dbo.REGISTRANTREGISTRATIONMAP [MAPTODELETE] on REGISTRANTREGISTRATIONMAP.REGISTRANTPACKAGEID = [MAPTODELETE].REGISTRANTPACKAGEID
                            where
                                [MAPTODELETE].REGISTRANTREGISTRATIONID = @ID;

                            delete from dbo.REGISTRANTPACKAGE
                            from
                                dbo.REGISTRANTPACKAGE
                                inner join dbo.REGISTRANTREGISTRATIONMAP on REGISTRANTPACKAGE.ID = REGISTRANTREGISTRATIONMAP.REGISTRANTPACKAGEID
                            where
                                REGISTRANTREGISTRATIONMAP.REGISTRANTREGISTRATIONID = @ID;

                            -- Delete registrant registration mappings for this registration

                            delete from dbo.REGISTRANTREGISTRATIONMAP where REGISTRANTREGISTRATIONID = @ID;

                            /* reset CONTEXT_INFO to previous value */
                            if not @contextCache is null
                                set CONTEXT_INFO @contextCache;

                            exec USP_REGISTRANTREGISTRATION_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;

                            return 0;
                        end try

                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1
                        end catch