USP_DATAFORMTEMPLATE_ADD_USERROLE

The save procedure used by the add dataform template "App User Role Add Data Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CONTEXTID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@ROLEID uniqueidentifier IN CMS Role

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_USERROLE
(
    @ID uniqueidentifier = null output,
    @CONTEXTID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @ROLEID uniqueidentifier = null
)
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()

declare @ClientUsersID int
select 
    @ClientUsersId = ClientUsers.ID 
from dbo.ClientUsers
    join dbo.BBNCUSERMAP on dbo.ClientUsers.UserName=BBNCUSERMAP.BBNCUSERNAME
where BBNCUSERMAP.ID=@CONTEXTID

declare @RoleInt int
select @RoleInt = ID from ClientRoles where Guid=@ROLEID


begin try
    -- handle inserting the data

    insert into dbo.UserRoles
        (ClientUsersID, ManuallyAdded, ClientRolesID)
    values
        (@ClientUsersID, 1, @RoleInt)

    if @@Rowcount = 0 
        raiserror('This role already exists for this user.', 13, 1);
end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0