USP_DATAFORMTEMPLATE_EDIT_APPLICATIONUSEREDIT_2
The save procedure used by the edit dataform template "Application User 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 |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_APPLICATIONUSEREDIT_2
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = null,
@CONSTITUENTID uniqueidentifier,
@SITEID uniqueidentifier,
@CURRENCYSETID uniqueidentifier
)
as
set nocount on;
declare @CURRENTDATE datetime;
begin try
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
if exists (select top 1 1 from APPUSER where ISSYSTEM = 1 and ID = @ID)
RAISERROR ('ERR_APPUSER_ISSYSTEM', 16, 1);
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 @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;