USP_REGISTRANT_TOGGLECANCELLEDSTATUS
Executes the "Registrant: Toggle Cancelled Status" record operation.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | Input parameter indicating the ID of the record being updated. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the update. |
Definition
Copy
CREATE procedure dbo.USP_REGISTRANT_TOGGLECANCELLEDSTATUS
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = null
)
as
set nocount on;
declare @CURRENTDATE datetime = getdate();
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
update
dbo.REGISTRANT
set
ISCANCELLED = ~ISCANCELLED,
USERMARKEDATTENDANCE = ~ISCANCELLED, --user marked attendance if canceling, if un-canceling, get rid of flag so not no-show
ATTENDED = case when ISCANCELLED = 0 then 0 else ATTENDED end, --mark not attended if canceling
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE
where
REGISTRANT.ID = @ID;
if (select ISCANCELLED from dbo.REGISTRANT where ID = @ID) = 1
begin
--Mark guests as canceled
update
dbo.REGISTRANT
set
ISCANCELLED = 1,
USERMARKEDATTENDANCE = 1, --user marked attendance if canceling
ATTENDED = 0, --mark not attended if canceling
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE
where
REGISTRANT.GUESTOFREGISTRANTID = @ID;
--Remove the registrant from their seat if they are cancelling.
--Remove guests from their seats as well.
update
dbo.EVENTSEATINGSEAT
set
REGISTRANTID = null,
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE
from
dbo.EVENTSEATINGSEAT
inner join dbo.REGISTRANT on REGISTRANT.ID = EVENTSEATINGSEAT.REGISTRANTID
where
REGISTRANT.ID = @ID
or REGISTRANT.GUESTOFREGISTRANTID = @ID;
end
else
begin
--Mark guests as not canceled
update
dbo.REGISTRANT
set
ISCANCELLED = 0,
USERMARKEDATTENDANCE = 0, --if un-canceling, get rid of flag so not no-show
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE
where
REGISTRANT.GUESTOFREGISTRANTID = @ID;
end
return 0;