spAddUpdate_NewsStories

Parameters

Parameter Parameter Type Mode Description
@PKID int INOUT
@NewsChannelID int IN
@Title nvarchar(510) IN
@Description ntext IN
@Guid uniqueidentifier IN
@LinkURL nvarchar(1024) IN
@Categories nvarchar(1024) IN
@Approved bit IN
@PostId int IN
@LinkedPageId int IN
@LinkedPageTabId int IN
@PublicationDate datetime IN

Definition

Copy

                CREATE PROCEDURE [dbo].[spAddUpdate_NewsStories]
                (
                    @PKID            int output        ,
                    @NewsChannelID    int                ,
                    @Title            nvarchar(510)    ,
                    @Description    ntext            ,
                    @Guid            uniqueidentifier,
                    @LinkURL         nvarchar(1024),
                    @Categories        nvarchar(1024),
                    @Approved        bit,
                    @PostId            int,
                    @LinkedPageId   int,
                    @LinkedPageTabId int,
                    @PublicationDate datetime
                )
                AS
                BEGIN
                    set nocount on

                    declare @ChannelPublicationDate datetime
                    set @ChannelPublicationDate = getutcdate()

                    if @PostId=0
                        set @PostId = null

                    begin transaction

                    declare @ApprovedDate datetime
                    declare @ApprovedID int


                    if (@PKID<=0)
                    begin
                        if @Approved=1
                            begin
                                set @ApprovedDate = @PublicationDate
                                set @ApprovedID = @PostId
                            end
                        else
                            begin
                                set @ApprovedDate = null
                                set @ApprovedID = null
                            end


                        INSERT INTO NewsStories
                        (
                        NewsChannelID    ,
                        Title            ,
                        Description        ,
                        PublicationDate    ,
                        Guid            ,
                        LinkURL            ,
                        Approved        ,
                        ApprovedID        ,
                        ApprovedDate    ,
                        PostId            ,
                        Categories,
                        LinkedPageId,
                        LinkedPageTabId
                        )

                        VALUES
                        (
                        @NewsChannelID    ,
                        @Title            ,
                        @Description    ,
                        @PublicationDate,
                        @Guid,
                        @LinkURL,
                        @Approved,
                        @ApprovedID        ,
                        @ApprovedDate    ,
                        @PostId            ,
                        @Categories        ,
                        @LinkedPageId    ,
                        @LinkedPageTabId
                        )

                        SELECT @PKID = @@Identity

                    end 
                    else 
                    begin

                        if @Approved=0
                            begin
                                set @ApprovedDate = null
                                set @ApprovedID = null
                            end


                        UPDATE NewsStories SET
                            Title            =@Title                ,
                            Description        =@Description        ,
                            PublicationDate    =@PublicationDate    ,
                            LinkURL            =@LinkURL            ,
                            Categories        =@Categories    ,            
                            LinkedPageId    = @LinkedPageId,
                            LinkedPageTabId    = @LinkedPageTabId,
                            Approved        = @Approved
                            ApprovedId        = @ApprovedId
                            ApprovedDate    = @ApprovedDate
                            UpdateDate        =getutcdate()
                        WHERE ID=@PKID

                    end

                    UPDATE dbo.NewsChannels SET PublicationDate = @ChannelPublicationDate WHERE ID = @NewsChannelID

                    commit transaction
                END