USP_DATAFORMTEMPLATE_ADD_EVENTSTAFFRESOURCE
The save procedure used by the add dataform template "Event Staff Resource Add Data Form".
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | INOUT | The output parameter indicating the ID of the record added. |
@EVENTID | 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. |
@VOLUNTEERTYPEID | uniqueidentifier | IN | Resource |
@QUANTITYNEEDED | int | IN | Quantity needed |
@FILLEDBYCODE | tinyint | IN | Filled by |
@JOBID | uniqueidentifier | IN | Job |
@VOLUNTEERS | xml | IN | Volunteers |
@ASSIGNMENTS | xml | IN | Volunteers |
@IGNORECONFLICTS | bit | IN | Ignore conflicts when saving |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_EVENTSTAFFRESOURCE
(
@ID uniqueidentifier = null output,
@EVENTID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = null,
@VOLUNTEERTYPEID uniqueidentifier,
@QUANTITYNEEDED int,
@FILLEDBYCODE tinyint = 0,
@JOBID uniqueidentifier = null,
@VOLUNTEERS xml = null,
@ASSIGNMENTS xml = null,
@IGNORECONFLICTS bit = 0
)
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()
declare
@STARTDATETIME datetime,
@ENDDATETIME datetime,
@STAFFRESOURCES xml;
select
@STARTDATETIME = STARTDATETIME,
@ENDDATETIME = ENDDATETIME
from dbo.EVENT
where ID = @EVENTID
set @STAFFRESOURCES = ( select @VOLUNTEERTYPEID VOLUNTEERTYPEID, @QUANTITYNEEDED QUANTITYNEEDED, @FILLEDBYCODE FILLEDBYCODE, @JOBID JOBID for xml raw('ITEM'), type, elements, root('STAFFRESOURCES'), binary base64 )
begin try
if @JOBID = '00000000-0000-0000-0000-000000000000'
set @JOBID = null
if @IGNORECONFLICTS = 0
begin
if dbo.UFN_CONFLICTCHECK_CONFLICTSEXIST
(
@STARTDATETIME, @ENDDATETIME,
null, null, @STAFFRESOURCES,
null, @EVENTID, null,
0,
1,
0,
0
) = 1
begin
raiserror('BBERR_CONFLICTSEXIST', 13, 1);
return 1;
end
end
/* handle inserting the data */
insert into dbo.EVENTSTAFFRESOURCE
(ID, EVENTID, VOLUNTEERTYPEID, QUANTITYNEEDED, FILLEDBYCODE, JOBID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
values
(@ID, @EVENTID, @VOLUNTEERTYPEID, @QUANTITYNEEDED, @FILLEDBYCODE, @JOBID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)
if (@FILLEDBYCODE = 0)
begin
/* Get the job occurrence ID */
declare @JOBOCCURRENCEID uniqueidentifier;
select @JOBOCCURRENCEID = EVENTSTAFFRESOURCE.JOBOCCURRENCEID
from dbo.EVENTSTAFFRESOURCE
where EVENTSTAFFRESOURCE.ID = @ID;
/* Handle updating the volunteers */
exec dbo.USP_STAFFRESOURCE_PROCESSVOLUNTEERS @VOLUNTEERS, @CHANGEAGENTID;
exec dbo.USP_EVENTSTAFFRESOURCE_GETVOLUNTEERS_ADDFROMXML @JOBOCCURRENCEID, @VOLUNTEERS, @CHANGEAGENTID;
end
else
begin
exec dbo.USP_EVENTSTAFFRESOURCE_GETASSIGNMENTS_ADDFROMXML @ID, @ASSIGNMENTS, @CHANGEAGENTID;
end
end try
begin catch
exec dbo.USP_RAISE_ERROR
return 1
end catch
return 0