[dbo].[MssWebSubscribeToSakariContact]
create procedure [dbo].[MssWebSubscribeToSakariContact]
@inSysUserId int,
@inOrderId int,
@inContactPriKey int
as
begin
set nocount on;
;with insertUpdateSakariContactSysuserMap as
(
select
SysuserFID = @inSysUserId,
SakariContactFID = @inContactPriKey
)
merge SakariContactSysuserMap with (tablock)
using insertUpdateSakariContactSysuserMap on
SakariContactSysuserMap.SysUserFID = insertUpdateSakariContactSysuserMap.SysuserFID and
SakariContactSysuserMap.SakariContactFID = insertUpdateSakariContactSysuserMap.SakariContactFID
when matched then
update set
LastReadAt = sysdatetimeoffset(),
Subscribed = 1
when not matched then
insert
(
SysuserFID,
SakariContactFID,
LastReadAt,
Subscribed
)
values
(
insertUpdateSakariContactSysuserMap.SysuserFID,
insertUpdateSakariContactSysuserMap.SakariContactFID,
sysdatetimeoffset(),
1
);
insert into SakariContactOrderMap
(
OrderFID,
SakariContactFID
)
select
@inOrderId,
@inContactPriKey
where not exists
(
select top 1 1
from SakariContactOrderMap
where
OrderFID = @inOrderId and
SakariContactFID = @inContactPriKey
)
end
GO
GRANT EXECUTE ON [dbo].[MssWebSubscribeToSakariContact] TO [MssExec]
GO