USP_AUCTIONPACKAGE_DELETE

Executes the "Auction Package Delete Record Operation" 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_AUCTIONPACKAGE_DELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    )
                    as begin

                        declare @RESERVATIONID uniqueidentifier;
                        declare @REVENUEID uniqueidentifier;
                        declare @AMPROIMPORTID uniqueidentifier;

                        begin try
                            --check deletion rules, if any

                            select
                                @RESERVATIONID = AUCTIONITEMRESERVATION.ID,
                                @REVENUEID = AUCTIONITEMREVENUEPURCHASE.REVENUEPURCHASEID,
                                @AMPROIMPORTID = BATCHAMPROIMPORTPACKAGE.ID
                            from dbo.AUCTIONITEM
                            left join dbo.AUCTIONITEMREVENUEPURCHASE
                                on AUCTIONITEM.ID = AUCTIONITEMREVENUEPURCHASE.AUCTIONITEMID
                            left join dbo.AUCTIONITEMRESERVATION
                                on AUCTIONITEM.ID = AUCTIONITEMRESERVATION.AUCTIONITEMID
                            left join dbo.BATCHAMPROIMPORTPACKAGE
                                on AUCTIONITEM.ID = BATCHAMPROIMPORTPACKAGE.PACKAGE_LINKID
                            where AUCTIONITEM.ID = @ID

                            if @RESERVATIONID is not null
                                raiserror('This package is pending purchase and cannot be deleted.', 13, 1);

                            if @REVENUEID is not null
                                raiserror('This package is purchased and cannot be deleted.', 13, 1);

                            if @AMPROIMPORTID is not null
                                raiserror('This package is in an AuctionMaestro Pro import batch and cannot be deleted.', 13, 1);

                            --Update the items that were in the package

                            update 
                                dbo.AUCTIONITEM
                            set 
                                PACKAGEID = null,
                                EVENTAUCTIONID = null
                            where PACKAGEID = @ID

                            -- use the system generated delete routine to allow proper recording of the deleting agent

                            exec USP_AUCTIONITEM_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID                  

                            return 0;
                        end try
                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1;
                        end catch
                    end