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

alter procedure {databaseOwner}{objectQualifier}usp_nadev_Event_Price_Tier_Save
(
 @priceId int,
 @eventId int,
 @TierName nvarchar(255),
 @costPerPlace money,
 @dnnRoleId int,
 @sortOrder int,
 @additionalAttendeeCost money
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventPriceTier] where priceId = @priceId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventPriceTier] set eventId = @eventId,
																			TierName = @TierName,
																			costPerPlace = @costPerPlace,
																			dnnRoleId = @dnnRoleId,
																			sortOrder = @sortOrder,
																			additionalAttendeeCost = @additionalAttendeeCost
																																					  										 
																			where priceId = @priceId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventPriceTier] (eventId,TierName,costPerPlace,dnnRoleId,sortOrder,additionalAttendeeCost)

	values (@eventId,@TierName,@costPerPlace,@dnnRoleId,@sortOrder,@additionalAttendeeCost)
	
	SELECT SCOPE_IDENTITY()

GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsLocation' and column_name = 'state')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] add state nvarchar(255) null
 end
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),
 @address1 nvarchar(255),
 @address2 nvarchar(255),
 @city nvarchar(255),
 @postcode nvarchar(255),
 @country nvarchar(255),
 @state nvarchar (255)
)

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,
																			 address1 = @address1,
																			 address2 = @address2,
																			 city = @city,
																			 postcode = @postcode,
																			 country = @country,
																			 state =@state
																		  										 
																			where locationId = @locationId
																			return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventsLocation] (moduleId,locationName,isArchived,parentId,longitude,latitude,eventFontColor,eventColor,address1,address2,city,postcode,country,state)

	values (@moduleId,@locationName,@isArchived,@parentId,@longitude,@latitude,@eventFontColor,@eventColor,@address1,@address2,@city,@postcode,@country,@state)
	
	SELECT SCOPE_IDENTITY()

GO

if not exists (select column_name from INFORMATION_SCHEMA.columns where table_name = '{objectQualifier}tblNaDevEventsUsersSignedUpToEvent' and column_name = 'HeartLandTransactionInfo')
 begin
   alter table {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] add HeartLandTransactionInfo nvarchar(max) null
 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,
 @numberOfAttendeesString nvarchar(max),
 @isWaitList bit,
 @BookingSurcharge money,
 @HeartLandTransactionInfo nvarchar(max)
)

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,
																				  numberOfAttendeesString =@numberOfAttendeesString,
																				  isWaitList = @isWaitList,
																				  BookingSurcharge = @BookingSurcharge,
																				  HeartLandTransactionInfo = @HeartLandTransactionInfo	 												 
									 
																				  where bookingId = @bookingId												

GO

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


alter procedure {databaseOwner}{objectQualifier}usp_insertUserSignUpToEventAddress
(
 @address1 nvarchar(255),
 @address2 nvarchar(255),
 @city nvarchar(255),
 @region nvarchar(255),
 @country nvarchar(255),
 @postcode nvarchar(255),
 @phone nvarchar(255),
 @firstname nvarchar(255),
 @surname nvarchar(255),
 @emailAddress nvarchar(255),
 @companyName nvarchar(255),
 @mobileNumber nvarchar(255),
 @faxNumber nvarchar (255),
 @title nvarchar (50)
)

as

set nocount on
  
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpAddress] (address1,address2,city,region,country,postcode,phone,firstName,surname,emailAddress,companyName,mobileNumber,faxNumber,title)

	values (@address1,@address2,@city,@region,@country,@postcode,@phone,@firstName,@surname,@emailAddress,@companyName,@mobileNumber,@faxNumber,@title)
	
	SELECT SCOPE_IDENTITY()
			
	return

GO

alter procedure {databaseOwner}[{objectQualifier}usp_nadev_Events_User_Address_Update]
(
 @addressId int,
 @address1 nvarchar(255),
 @address2 nvarchar(255),
 @city nvarchar(255),
 @region nvarchar(255),
 @country nvarchar(255),
 @postcode nvarchar(255),
 @phone nvarchar(255),
 @firstname nvarchar(255),
 @surname nvarchar(255),
 @emailAddress nvarchar(255),
 @companyName nvarchar(255),
 @mobileNumber nvarchar(255),
 @faxNumber nvarchar (255),
 @title nvarchar(50)
)

as

	update {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpAddress] set address1 =@address1,
																					address2 = @address2,
																					city = @city,
																					region = @region,
																					country = @country,
																					postcode = @postcode,
																					phone =@phone,
																					firstname =@firstname,
																					surname =@surname,
																					emailaddress =@emailaddress,
																					companyname =@companyname,
																					mobilenumber=@mobilenumber,
																					faxnumber =@faxnumber,
																					title = @title

																					where addressid =@addressid

return

GO

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

alter procedure {databaseOwner}{objectQualifier}usp_insertEventSignUpQuestion
(
 @eventId int,
 @questionName nvarchar(255),
 @controlType nvarchar(50),
 @isRequired bit,
 @sortOrder int,
 @AskQuestionToId int
)

as

set nocount on
  
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventSignUpQuestion] (eventId,questionName,controlType,isRequired,sortOrder,AskQuestionToId)

	values (@eventId,@questionName,@controlType,@isRequired,@sortOrder,@AskQuestionToId)
	
	SELECT SCOPE_IDENTITY()
			
	return

GO


alter procedure {databaseOwner}{objectQualifier}usp_updateEventSignUpQuestion
(
 @signUpQuestionId int,
 @eventId int,
 @questionName nvarchar(255),
 @controlType nvarchar(50),
 @isRequired bit,
 @sortOrder int,
 @AskQuestionToId int
)

as

set nocount on
  
	update {databaseOwner}[{objectQualifier}tblNaDevEventSignUpQuestion] 
		set eventId =@eventId,
			questionName = @questionName,
			controlType = @controlType,
			isrequired = @isRequired,
			sortorder = @sortOrder,
			AskQuestionToId =@AskQuestionToId

			where signUpQuestionid = @signupquestionid

GO