
-- SQLAzureMWParseTSQL TSQL Output File:
-- Generated at: 3/1/2014 3:07:23 PM

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsLocation' and column_name = 'eventColor')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] add eventColor nvarchar(50) null
 end
GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsLocation' and column_name = 'eventFontColor')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] add eventFontColor nvarchar(50) null
 end
GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventCategories' and column_name = 'eventColor')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventCategories] add eventColor nvarchar(50) null
 end
GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventCategories' and column_name = 'eventFontColor')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventCategories] add eventFontColor nvarchar(50) null
 end
GO

alter procedure {databaseOwner}{objectQualifier}usp_nadevEventsInsertUpdateCategory
(
 @categoryId int,
 @moduleId int,
 @categoryName nvarchar(255),
 @isActive bit,
 @eventFontColor nvarchar(50),
 @eventColor nvarchar(50)
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventCategories] where categoryId = @categoryId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventCategories] set moduleId = @moduleId,
																			 categoryName = @categoryName,
																			 isActive = @isActive,
																			 eventFontColor =@eventFontColor,
																			 eventColor =@eventColor
																		  										 
									 
																			where categoryId = @categoryId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventCategories] (moduleId,categoryName,isActive,eventFontColor,eventColor)

	values (@moduleId,@categoryName,@isActive,@eventFontColor,@eventColor)
	
	SELECT SCOPE_IDENTITY()

GO

alter procedure {databaseOwner}{objectQualifier}usp_nadev_Event_Location_Save_Location
(
 @locationId int,
 @moduleId int,
 @locationName nvarchar(max),
 @isArchived bit,
 @parentId int,
 @longitude nvarchar(255),
 @latitude nvarchar (255),
 @eventFontColor nvarchar(50),
 @eventColor nvarchar(50)
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] where locationId = @locationId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] set moduleId = @moduleId,
																			 locationName = @locationName,
																			 isArchived = @isArchived,
																			 parentId = @parentId,
																			 longitude = @longitude,
																			 latitude = @latitude,
																			 eventFontColor =@eventFontColor,
																			 eventColor =@eventColor
																		  										 
																			where locationId = @locationId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] (moduleId,locationName,isArchived,parentId,longitude,latitude,eventFontColor,eventColor)

	values (@moduleId,@locationName,@isArchived,@parentId,@longitude,@latitude,@eventFontColor,@eventColor)
	
	SELECT SCOPE_IDENTITY()

GO

if not exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}tblNaDevEventAttendee]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 begin

	CREATE TABLE {databaseOwner}[{objectQualifier}tblNaDevEventAttendee](
		[attendeeId] [int] IDENTITY(1,1) NOT NULL,
		[moduleId] [int] NOT NULL,
		[firstName] nvarchar(255) not null,
		[surname] nvarchar(255) not null,
		[email] nvarchar(255) not null
	 CONSTRAINT [PK_{objectQualifier}tblNaDevEventAttendee] PRIMARY KEY CLUSTERED 
	(
		[attendeeId] ASC
	)
	)
 end
GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_save]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_nadev_Event_Attendee_save
GO

create procedure {databaseOwner}{objectQualifier}usp_nadev_Event_Attendee_save
(
 @attendeeId int,
 @moduleId int,
 @firstName nvarchar(255),
 @surname nvarchar (255),
 @email nvarchar (255)
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventAttendee] where attendeeId = @attendeeId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventAttendee] set moduleid = @moduleid,
																			firstName = @firstName,
																			surname = @surname,
																			email = @email
																																					  										 
																			where attendeeId = @attendeeId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventAttendee] (moduleId,firstName,surname,email)

	values (@moduleId,@firstName,@surname,@email)
	
	SELECT SCOPE_IDENTITY()

GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_get_all]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_get_all]
GO

create procedure {databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_get_all]
(
 @moduleId int
)

as

	select * from {databaseOwner}[{objectQualifier}tblNaDevEventAttendee] 
		where moduleId = @moduleId order by surname,firstname

return

GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_delete]
GO

create procedure {databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_delete]
(
 @attendeeId int
)

as

	delete from {databaseOwner}[{objectQualifier}tblNaDevEventAttendee] where attendeeId = @attendeeId

return

GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_get]
GO

create procedure {databaseOwner}[{objectQualifier}usp_nadev_Event_Attendee_get]
(
 @attendeeId int
)

as

	select * from {databaseOwner}[{objectQualifier}tblNaDevEventAttendee] 
		where attendeeId = @attendeeId

return

GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsUsersSignedUpToEvent' and column_name = 'sentRemindEmail')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] add sentRemindEmail bit null default 0
 end
GO

alter procedure {databaseOwner}{objectQualifier}usp_UpdateUserSignUpToEvent
(
 @bookingId int,
 @eventId int,
 @moduleId int,
 @userId int,
 @eventStartDate datetime,
 @eventEndDate datetime,
 @additionalInformation ntext,
 @billingAddressId int,
 @numberOfPlaces int,
 @dateBookingMade datetime,
 @paymentStatusId int,
 @tabModuleId int,
 @userSignUpAnswers ntext,
 @totalCost money,
 @numberOfChildPlaces int,
 @discountAmount money,
 @couponCode nvarchar(50),
 @tax money,
 @sentRemindEmail bit
)

as

set nocount on
  
update {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] set   eventId = @eventId,
																				  eventStartDate = @eventStartDate,
																				  eventEndDate = @eventEndDate,
																				  additionalInformation = @additionalInformation,
																				  billingAddressId = @billingAddressId,
																				  numberOfPlaces = @numberOfPlaces,
																				  userId=@userId,
																				  moduleId =@moduleId,
																				  dateBookingMade = @dateBookingMade,
																				  paymentStatusId = @paymentStatusId,
																				  tabModuleId = @tabModuleId,
																				  userSignUpAnswers = @userSignUpAnswers,
																				  totalCost = @totalCost,
																				  numberOfChildPlaces = @numberOfChildPlaces,
																				  discountAmount =@discountAmount,
																				  couponcode = @couponcode,
																				  tax =@tax,
																				  sentRemindEmail =@sentRemindEmail						 												 
									 
																				  where bookingId = @bookingId												

GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventCategories' and column_name = 'parentId')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventCategories] add parentId int null
 end
GO

alter procedure {databaseOwner}{objectQualifier}usp_nadevEventsInsertUpdateCategory
(
 @categoryId int,
 @moduleId int,
 @categoryName nvarchar(255),
 @isActive bit,
 @eventFontColor nvarchar(50),
 @eventColor nvarchar(50),
 @parentId int
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventCategories] where categoryId = @categoryId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventCategories] set moduleId = @moduleId,
																			 categoryName = @categoryName,
																			 isActive = @isActive,
																			 eventFontColor =@eventFontColor,
																			 eventColor =@eventColor,
																			 parentId = @parentId																		  										 
									 
																			where categoryId = @categoryId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventCategories] (moduleId,categoryName,isActive,eventFontColor,eventColor,parentId)

	values (@moduleId,@categoryName,@isActive,@eventFontColor,@eventColor,@parentId)
	
	SELECT SCOPE_IDENTITY()

GO
