spAddUpdate_NetAccountRelation

Parameters

Parameter Parameter Type Mode Description
@PKID int INOUT
@NetAccountID int IN
@RelationAccountID int IN
@Confirmation int IN
@BlockedID int IN

Definition

Copy



CREATE PROCEDURE [dbo].[spAddUpdate_NetAccountRelation]
(
    @PKID int output,
    @NetAccountID int,
    @RelationAccountID int,
    @Confirmation int,
    @BlockedID int

)
    AS
    BEGIN

        SELECT @PKID = ISNULL(dbo.fnGetNetAccountRelationID(@NetAccountID, @RelationAccountID),0)

        IF (@PKID<=0
        BEGIN

            INSERT INTO [NetAccountRelation]
            (
            NetAccountID,
            RelationAccountID,
            Confirmation,
            BlockedID            
            )
            VALUES
            (
            @NetAccountID,
            @RelationAccountID,
            @Confirmation,
            @BlockedID
            )

            SELECT @PKID = @@Identity

        END
        ELSE 
        BEGIN
            UPDATE [NetAccountRelation] SET
            NetAccountID = @NetAccountID,
            RelationAccountID = @RelationAccountID,
            Confirmation = @Confirmation ,
            BlockedID = @BlockedID,
            UpdateDate = getUTCDate()
            WHERE [ID]=@PKID
            AND (BlockedID IS NULL OR BlockedID = @NetAccountID)
        END

        if @Confirmation > 0 
        begin
            UPDATE [NetAccountRelation] SET ConfirmationDate = getUTCDate() WHERE [ID]=@PKID AND ConfirmationDate IS NULL
        end
        else
        begin
            UPDATE [NetAccountRelation] SET ConfirmationDate = NULL WHERE [ID]=@PKID
        end

    END