USP_AUCTIONITEM_DELETEPOSTED

Executes the "Delete a posted auction item." 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_AUCTIONITEM_DELETEPOSTED
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    )
                    as begin

                        declare @REVENUEPOSTEDID uniqueidentifier;
                        declare @PURCHASEID uniqueidentifier;
                        declare @RESERVATIONID uniqueidentifier;
                        declare @INRESERVEDPACKAGEID uniqueidentifier;
                        declare @CURRENTDATE date = getdate();

                        begin try
                            select
                                @REVENUEPOSTEDID = REVENUEPOSTED.ID,
                                @PURCHASEID = AUCTIONITEMPURCHASE.PURCHASEID,
                                @RESERVATIONID = AUCTIONITEMRESERVATION.ID,
                                @INRESERVEDPACKAGEID = [RESERVEDPARENTPACKAGE].AUCTIONITEMID
                            from dbo.AUCTIONITEM
                            left join dbo.AUCTIONITEMPURCHASE
                                on AUCTIONITEM.ID = AUCTIONITEMPURCHASE.AUCTIONITEMID
                            left join dbo.REVENUEPOSTED
                                on REVENUEPOSTED.ID = AUCTIONITEM.REVENUEAUCTIONDONATIONID
                            left join dbo.AUCTIONITEMRESERVATION
                                on AUCTIONITEM.ID = AUCTIONITEMRESERVATION.AUCTIONITEMID
                            left join dbo.AUCTIONITEMRESERVATION [RESERVEDPARENTPACKAGE]
                                on [RESERVEDPARENTPACKAGE].AUCTIONITEMID = AUCTIONITEM.PACKAGEID
                            where AUCTIONITEM.ID = @ID

                            if @PURCHASEID is not null
                                raiserror('Purchased items cannot be deleted.', 13, 1);

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

                            if @INRESERVEDPACKAGEID is not null
                                raiserror('This item is part of a package that is pending purchase and cannot be deleted.', 13, 1);

                            if @REVENUEPOSTEDID is null
                                raiserror('Unposted auction items should not be deleted with this task.', 13, 1);

                            update dbo.AUCTIONITEM
                            set COPIEDFROMID = null,
                                CHANGEDBYID = @CHANGEAGENTID,
                                DATECHANGED = @CURRENTDATE
                            where COPIEDFROMID = @ID;

                            exec dbo.USP_AUCTIONITEM_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID

                            if @REVENUEPOSTEDID is not null
                                exec dbo.USP_REVENUE_DELETEPOSTED @REVENUEPOSTEDID, @CHANGEAGENTID
                        end try

                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1
                        end catch

                        return 0;

                    end