USP_DATAFORMTEMPLATE_EDITSAVE_EVENTLODGINGLOCATIONS

The save procedure used by the edit dataform template "Event Lodging Option Edit Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@EVENTLODGINGLOCATIONID uniqueidentifier IN Lodging location
@ROOMINFORMATION xml IN Room types
@EVENTLODGINGID uniqueidentifier IN Event lodging ID

Definition

Copy


          CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDITSAVE_EVENTLODGINGLOCATIONS
            (
              @ID uniqueidentifier,
              @CHANGEAGENTID uniqueidentifier = null,    
              @EVENTLODGINGLOCATIONID uniqueidentifier,
              @ROOMINFORMATION xml,
              @EVENTLODGINGID uniqueidentifier 
            )

            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()

            set @EVENTLODGINGID = @ID



            begin try
              exec dbo.USP_EVENTLODGINGROOM_VALIDATEROOMINFO @ROOMINFORMATION

              update dbo.EVENTLODGING
                set EVENTLODGINGLOCATIONID  = @EVENTLODGINGLOCATIONID
              where ID = @ID

                -- build a temporary table containing the values from the XML

                declare @TempTbl table (
                [ALLOCATED] int,
                [ID] uniqueidentifier,
                [ROOMTYPECODEID] uniqueidentifier,
                [SLEEPS] int)

                insert into @TempTbl select
                [ALLOCATED],
                [ID],
                [ROOMTYPECODEID],
                [SLEEPS]
                from dbo.UFN_EVENTLODGINGROOM_GETEVENTLODGINGROOMINFORMATION_FROMITEMLISTXML(@ROOMINFORMATION)

                --verify not trying to delete a room type where registrants are already assigned

                declare @count int;
                  declare @ERRORMESSAGE nvarchar(max);

                select @count = count(EVENTLODGINGROOMINSTANCE.ID)
                from EVENTLODGINGROOMINSTANCE
                where EVENTLODGINGROOMINSTANCE.EVENTLODGINGID = @EVENTLODGINGID and
                EVENTLODGINGROOMINSTANCE.EVENTLODGINGROOMID not in (select ID from @TempTbl)

                if @count > 0
                begin
                select @ERRORMESSAGE = 'ERR_DELETE_ROOM_WITHREGISTRANT' from dbo.EVENTLODGINGROOM;
                raiserror(@ERRORMESSAGE, 13, 1);
                end

                --verify not trying to reduce allocated below the number currently allocated

                select @count = COUNT(temp.id)
                from @TempTbl as temp
                where ALLOCATED < dbo.UFN_EVENTLODGINGROOM_GETROOMSASSIGNED(@EVENTLODGINGID,temp.id)

                if @count > 0
                begin
                    select @ERRORMESSAGE = 'ERR_ALLOCATED_LESS_THAN_ASSIGNED' from dbo.EVENTLODGINGROOM;
                    raiserror(@ERRORMESSAGE, 13, 1);
                end

              exec dbo.USP_EVENTLODGINGROOM_GETEVENTLODGINGROOMINFORMATION_UPDATEFROMXML @ID, @ROOMINFORMATION, @CHANGEAGENTID

            end try

            begin catch
              exec dbo.USP_RAISE_ERROR
              return 1
            end catch

            return 0