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

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

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

alter procedure {databaseOwner}{objectQualifier}usp_insertUpdateEvent
(
 @eventId int,
 @eventName nvarchar(4000),
 @description ntext,
 @eventStartDate dateTime,
 @eventEndDate dateTime,
 @allDayEvent bit,
 @isRecurringEvent bit,
 @recurringEventObject ntext,
 @recurFrequency nvarchar(255),
 @portalId int,
 @spacesAvailable int,
 @dnnRoleId int,
 @isDeleted bit,
 @costPerPlace money,
 @thePortalId int,
 @maxNumberPlacesPerPerson int,
 @isActive bit,
 @applyRoleId int,
 @ApplyRoleExpiryDays int,
 @eventSummary ntext,
 @eventColor nvarchar(50),
 @childCostPerPlace money
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEvents] where eventId = @eventId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEvents] set   eventName = @eventName,
																	  description = @description,
																	  eventStartDate = @eventStartDate,
																	  eventEndDate = @eventEndDate,
																	  allDayEvent =@allDayEvent,
																	  isRecurringEvent = @isRecurringEvent,
																	  recurringEventObject = @recurringEventObject,
																	  recurFrequency = @recurFrequency,
																	  portalId = @portalId,
																	  spacesAvailable = @spacesAvailable,
																	  dnnRoleId = @dnnRoleId,
																	  isDeleted =@isDeleted,
																	  costPerPlace = @costPerPlace,
																	  thePortalId =@thePortalId,
																	  maxNumberPlacesPerPerson = @maxNumberPlacesPerPerson,
																	  isActive = @isActive,
																	  applyRoleId =@applyRoleId,
																	  ApplyRoleExpiryDays = @ApplyRoleExpiryDays,
																	  eventSummary = @eventSummary,
																	  eventColor = @eventColor,
																	  childCostPerPlace = @childCostPerPlace		 												 
									 
																	  where eventId = @eventId
																	  return @@identity
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEvents] (eventName,description,eventStartDate,eventEndDate,allDayEvent,isRecurringEvent,recurringEventObject,recurFrequency,portalId,spacesAvailable, dnnRoleId,isDeleted,costPerPlace,thePortalId,maxNumberPlacesPerPerson,isActive,applyRoleId,ApplyRoleExpiryDays,eventSummary,eventColor,childCostPerPlace)

	values (@eventName,@description,@eventStartDate,@eventEndDate,@allDayEvent,@isRecurringEvent,@recurringEventObject,@recurFrequency,@portalId,@spacesAvailable,@dnnRoleId,@isDeleted,@costPerPlace,@thePortalId,@maxNumberPlacesPerPerson,@isActive,@applyRoleId,@ApplyRoleExpiryDays,@eventSummary,@eventColor,@childCostPerPlace)
	
	SELECT SCOPE_IDENTITY()

GO

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

alter procedure {databaseOwner}{objectQualifier}usp_insertUserSignUpToEvent
(
 @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
)

as

set nocount on
  

	insert into {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] (eventId,moduleId,userId,eventStartDate,eventEndDate,additionalInformation,billingAddressId,numberOfPlaces,dateBookingMade,paymentStatusId,tabModuleId,userSignUpAnswers,totalCost,numberOfChildPlaces)

	values (@eventId,@moduleId,@userId,@eventStartDate,@eventEndDate,@additionalInformation,@billingAddressId,@numberOfPlaces,@dateBookingMade,@paymentStatusId,@tabModuleId,@userSignUpAnswers,@totalCost,@numberOfChildPlaces)
	
	SELECT SCOPE_IDENTITY()
			
	return

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
)

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									 												 
									 
																				  where bookingId = @bookingId												

GO
