CREATE TABLE [dbo].[PushSetup](
[RowID] [int] IDENTITY(1,1) NOT NULL,
[UnitID] [int] NOT NULL,
[ServiceID] [varchar](50) NOT NULL,
[APIKey] [varchar](50) NOT NULL,
[PlatForm] [tinyint] NOT NULL CONSTRAINT [DF_PushSetup_PlatForm] DEFAULT ((0)),
[BrandID] [int] NOT NULL CONSTRAINT [DF_PushSetup_BrandID] DEFAULT ((0)),
[Description] [varchar](50) NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[PushSetup_Devices](
[PushID] [int] IDENTITY(1,1) NOT NULL,
[ServiceID] [varchar](50) NOT NULL,
[DeviceID] [varchar](500) NOT NULL,
[Data] [int] NOT NULL CONSTRAINT [DF_PushSetup_Devices_Data] DEFAULT ((0)),
[Active] [bit] NOT NULL CONSTRAINT [DF_PushSetup_Devices_Active] DEFAULT ((1)),
[Platform] [tinyint] NOT NULL CONSTRAINT [DF_PushSetup_Devices_Platform] DEFAULT ((0))
) ON [PRIMARY]
--Platform defaults to 0 for android, caller could send "1" for Apple, "2" for MS, etc.
--ServiceID is the ID of the GCM project, not sure how apple, etc. is yet
CREATE PROCEDURE dbo.[spUpdatePushDevices] (@ServiceID varchar(50),@DeviceID varchar(500),@Data int,@Platform tinyint=0,@Active bit=1)
as
--check if we have a device registered for this service yet
DECLARE @PushID int;set @PushID=0
DECLARE @IDCount int
SELECT @IDCount=count(*) FROM EasyOrder.POS_PushSetup_Devices
WHERE Data=@Data and ServiceID=@ServiceID
IF @IDCount>1 --just in case we have dupes we wanna delete them
BEGIN
delete from EasyOrder.POS_PushSetup_Devices
WHERE Data=@Data and ServiceID=@ServiceID and Platform=@Platform
END
SELECT @PushID=isnull(pushid,0) FROM EasyOrder.POS_PushSetup_Devices
WHERE Data=@Data and ServiceID=@ServiceID --and Platform=@Platform
----if so then probably just updating it's subscription, i.e. on/off or data
IF @PushID<>0
BEGIN
UPDATE EasyOrder.POS_PushSetup_Devices SET Data=@Data,Active=@Active,Platform=@Platform
WHERE PushID=@PushID
END
ELSE
BEGIN
INSERT INTO EasyOrder.POS_PushSetup_Devices (ServiceID,DeviceID,Data,Active,Platform)
VALUES(@ServiceID,@DeviceID,@Data,@Active,@Platform)
SET @PushID=(SELECT @@IDENTITY)
END
SELECT @PushID