USP_DATAFORMTEMPLATE_EDIT_APPLICATIONUSERCMSEDIT_2
The save procedure used by the edit dataform template "Application User CMS Edit Form".
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | The input ID parameter indicating the ID of the record being edited. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the procedure. |
@CONSTITUENTID | uniqueidentifier | IN | Constituent ID |
@SITEID | uniqueidentifier | IN | Site |
@CURRENCYSETID | uniqueidentifier | IN | Currency set |
@CMSUSERNAME | uniqueidentifier | IN | Link to an existing CMS user |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_APPLICATIONUSERCMSEDIT_2
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = null,
@CONSTITUENTID uniqueidentifier,
@SITEID uniqueidentifier,
@CURRENCYSETID uniqueidentifier,
@CMSUSERNAME uniqueidentifier
)
as
set nocount on;
declare @CURRENTDATE datetime;
declare @CMSNAME nvarchar(50);
begin try
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
set @CURRENTDATE = getdate();
if @CONSTITUENTID is not null begin
--Remove any old link because duplicates are not allowed.
--Another way to do this would be to make the user remove the old link - but that would be annoying so we do it for them.
update
dbo.APPUSER
set
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE,
CONSTITUENTID = NULL
where
(CONSTITUENTID = @CONSTITUENTID) and (ID <> @ID);
end
update
dbo.APPUSER
set
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE,
CONSTITUENTID = @CONSTITUENTID,
SITEID = @SITEID
where
ID = @ID;
if @CMSUSERNAME is not null begin
declare @NAME nvarchar(50) = dbo.UFN_CMS_GETUSERNAME(@CMSUSERNAME);
if exists (select BBNCUSERNAME from dbo.BBNCUSERMAP where ID = @ID)
begin
exec dbo.USP_BBNCUSERMAP_EDIT @ID, @CHANGEAGENTID, 1, @NAME
end
else
begin
declare @newID as uniqueidentifier;
exec dbo.USP_BBNCUSERMAP_ADD @newID, @CHANGEAGENTID, 1, @ID, @NAME
end
end
else if exists (select BBNCUSERNAME from dbo.BBNCUSERMAP where ID = @ID) --CMS user not set, remove from BBNCUSERMAP if set
begin
exec dbo.USP_BBNCUSERMAP_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;
end
if @CURRENCYSETID is null
begin
declare @CURRENTCURRENCYSETID uniqueidentifier;
select
@CURRENTCURRENCYSETID = APPUSERCURRENCYSET.ID
from
dbo.APPUSERCURRENCYSET
where
APPUSERCURRENCYSET.APPUSERID = @ID;
exec dbo.USP_APPUSERCURRENCYSET_DELETEBYID_WITHCHANGEAGENTID @CURRENTCURRENCYSETID, @CHANGEAGENTID;
end
else
begin
update
dbo.APPUSERCURRENCYSET
set
CURRENCYSETID = @CURRENCYSETID,
CHANGEDBYID = @CHANGEAGENTID,
DATECHANGED = @CURRENTDATE
where
APPUSERID = @ID;
if @@ROWCOUNT < 1
insert into dbo.APPUSERCURRENCYSET
(APPUSERID, CURRENCYSETID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
values
(@ID, @CURRENCYSETID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE);
end
end try
begin catch
EXEC dbo.USP_RAISE_ERROR;
return 1;
end catch
return 0;