diff --git a/.github/workflows/gtc-rg-subjects-api.yml b/.github/workflows/gtc-rg-subjects-api.yml index ee51b00b..50d253bd 100644 --- a/.github/workflows/gtc-rg-subjects-api.yml +++ b/.github/workflows/gtc-rg-subjects-api.yml @@ -44,13 +44,15 @@ jobs: RUNTIME_ENV: 'Development' SRC_PATH: './src/Subjects' SRC_SLN: 'Goodtocode.Subjects.sln' - API_PATH: 'Presentation/Api.WebApi' - API_PROJECT: 'Api.WebApi.csproj' + API_PATH: 'Presentation.Api.WebApi' + API_PROJECT: 'Presentation.Api.WebApi.csproj' APPI_NAME: 'appi-subjects-dev-001' - INFRA_PATH: 'Infrastructure/Persistence' - INFRA_PROJECT: 'Persistence.csproj' - UNIT_PATH: 'Specs/Application.Unit' - UNIT_PROJECT: 'Application.Unit.csproj' + INFRA_PATH: 'Infrastructure.Persistence' + INFRA_PROJECT: 'Infrastructure.Persistence.csproj' + INTEGRATION_PATH: 'Specs.Integration' + INTEGRATION_PROJECT: 'Specs.Integration.csproj' + UNIT_PATH: 'Specs.Unit' + UNIT_PROJECT: 'Specs.Unit.csproj' SCRIPTS_PATH: './.github/scripts' SQL_NAME: 'sql-entities-dev-001' SQLDB_NAME: 'sqldb-entities-dev-001' @@ -76,6 +78,7 @@ jobs: run: | dotnet build ${{ env.SRC_PATH }}/${{ env.SRC_SLN }} --configuration Release dotnet test ${{ env.SRC_PATH }}/${{ env.UNIT_PATH }}/${{ env.UNIT_PROJECT }} --verbosity normal + dotnet test ${{ env.SRC_PATH }}/${{ env.INTEGRATION_PATH }}/${{ env.INTEGRATION_PROJECT }} --verbosity normal dotnet publish ${{ env.SRC_PATH }}/${{ env.API_PATH }}/${{ env.API_PROJECT }} --configuration Release -o ${{ env.AZURE_WEBAPP_NAME }} shell: pwsh diff --git a/data/Entity.Database/Activity/Stored Procedures/ExceptionLogInsertByException.sql b/data/Entity.Database/Activity/Stored Procedures/ExceptionLogInsertByException.sql new file mode 100644 index 00000000..fcb5672b --- /dev/null +++ b/data/Entity.Database/Activity/Stored Procedures/ExceptionLogInsertByException.sql @@ -0,0 +1,11 @@ +CREATE PROCEDURE [Activity].[ExceptionLogInsertByException] +AS + -- Build data into message + Declare @CustomMessage nvarchar(max) + Select @CustomMessage = 'Number: ' + Cast(ERROR_NUMBER() As nvarchar(100)) + + ' Severity: ' + Cast(ERROR_SEVERITY() As nvarchar(100)) + + ' State: ' + Cast(ERROR_STATE() As nvarchar(100)) + + ' Procedure: ' + Cast(ERROR_PROCEDURE() As nvarchar(500)) + + ' Line: ' + Cast(ERROR_LINE() As nvarchar(100)) + INSERT INTO [Activity].[ExceptionLog] ([Message], [CustomMessage]) + SELECT ERROR_MESSAGE() AS [Message], IsNull(@CustomMessage, '') As [CustomMessage] diff --git a/data/Entity.Database/Activity/Tables/ExceptionLog.sql b/data/Entity.Database/Activity/Tables/ExceptionLog.sql new file mode 100644 index 00000000..193f2a36 --- /dev/null +++ b/data/Entity.Database/Activity/Tables/ExceptionLog.sql @@ -0,0 +1,21 @@ +CREATE TABLE [Activity].[ExceptionLog] ( + [ExceptionLogId] INT IDENTITY (1, 1) NOT NULL, + [ExceptionLogKey] UniqueIdentifier CONSTRAINT [DF_ExceptionLog_ExceptionLogKey] DEFAULT (NewID()) NOT NULL, + [AssemblyName] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_AssemblyName] DEFAULT ('') NOT NULL, + [Message] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_Message] DEFAULT ('') NOT NULL, + [InnerException] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_InnerException] DEFAULT ('') NOT NULL, + [StackTrace] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_StackTrace] DEFAULT ('') NOT NULL, + [ADDomainName] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_ExceptionADDomainName] DEFAULT ('') NOT NULL, + [ADUserName] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_ExceptionADUserName] DEFAULT ('') NOT NULL, + [DirectoryWorking] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_ExceptionDirectoryWorking] DEFAULT ('') NOT NULL, + [DirectoryAssembly] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_ExceptionDirectoryAssembly] DEFAULT ('') NOT NULL, + [URL] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_URL] DEFAULT ('') NOT NULL, + [CustomMessage] NVARCHAR (MAX) CONSTRAINT [DF_ExceptionLog_CustomMessage] DEFAULT ('') NOT NULL, + [Discriminator] NVARCHAR (128) CONSTRAINT [DF_ExceptionLog_Discriminator] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ExceptionLog_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Exception] PRIMARY KEY CLUSTERED ([ExceptionLogId] ASC) + ); +GO +CREATE NonCLUSTERED INDEX [IX_ExceptionLog_ExceptionLogKey] ON [Activity].[ExceptionLog] ([ExceptionLogKey] Asc) +GO + \ No newline at end of file diff --git a/data/Entity.Database/App_Data/PostBuild.Debug.bat b/data/Entity.Database/App_Data/PostBuild.Debug.bat new file mode 100644 index 00000000..3d9a44f4 --- /dev/null +++ b/data/Entity.Database/App_Data/PostBuild.Debug.bat @@ -0,0 +1,15 @@ +ECHO OFF +ECHO Starting PostBuild.bat %1 %2 %3 +REM Usage: Call "$(MSBuildProjectDirectory)\App_Data\PostBuild.$(ConfigurationName).bat" "$(MSBuildProjectDirectory)\$(OutDir)" "$(ConfigurationName)" "$(ProjectName)" +REM Vars: $(ProjectName) = MyCo.Framework. Models, $(TargetPath) = output file, $(TargetDir) = full bin path , $(OutDir) = bin\debug, $(ConfigurationName) = "Debug" + +REM Locals +SET FullPath=%1 +SET FullPath=%FullPath:"=% +ECHO FullPath: %FullPath% +SET Configuration=%2 +ECHO Configuration: %Configuration% +SET ProjectName=%3 +ECHO ProjectName: %ProjectName% + +Exit 0 \ No newline at end of file diff --git a/data/Entity.Database/App_Data/PostBuild.Release.bat b/data/Entity.Database/App_Data/PostBuild.Release.bat new file mode 100644 index 00000000..3d9a44f4 --- /dev/null +++ b/data/Entity.Database/App_Data/PostBuild.Release.bat @@ -0,0 +1,15 @@ +ECHO OFF +ECHO Starting PostBuild.bat %1 %2 %3 +REM Usage: Call "$(MSBuildProjectDirectory)\App_Data\PostBuild.$(ConfigurationName).bat" "$(MSBuildProjectDirectory)\$(OutDir)" "$(ConfigurationName)" "$(ProjectName)" +REM Vars: $(ProjectName) = MyCo.Framework. Models, $(TargetPath) = output file, $(TargetDir) = full bin path , $(OutDir) = bin\debug, $(ConfigurationName) = "Debug" + +REM Locals +SET FullPath=%1 +SET FullPath=%FullPath:"=% +ECHO FullPath: %FullPath% +SET Configuration=%2 +ECHO Configuration: %Configuration% +SET ProjectName=%3 +ECHO ProjectName: %ProjectName% + +Exit 0 \ No newline at end of file diff --git a/data/Entity.Database/App_Data/PreBuild.Debug.bat b/data/Entity.Database/App_Data/PreBuild.Debug.bat new file mode 100644 index 00000000..3b1677ec --- /dev/null +++ b/data/Entity.Database/App_Data/PreBuild.Debug.bat @@ -0,0 +1,15 @@ +ECHO OFF +ECHO Starting PreBuild.bat %1 %2 %3 +REM Usage: Call "$(MSBuildProjectDirectory)\App_Data\PreBuild.$(ConfigurationName).bat" "$(MSBuildProjectDirectory)" "$(ConfigurationName)" "$(ProjectName)" +REM Vars: $(ProjectName) = MyCo.Framework. Models, $(TargetPath) = output file, $(TargetDir) = full bin path , $(OutDir) = bin\debug, $(ConfigurationName) = "Debug" + +REM Locals +SET FullPath=%1 +SET FullPath=%FullPath:"=% +ECHO FullPath: %FullPath% +SET Configuration=%2 +ECHO Configuration: %Configuration% +SET ProjectName=%3 +ECHO ProjectName: %ProjectName% + +exit 0 diff --git a/data/Entity.Database/App_Data/PreBuild.Release.bat b/data/Entity.Database/App_Data/PreBuild.Release.bat new file mode 100644 index 00000000..3b1677ec --- /dev/null +++ b/data/Entity.Database/App_Data/PreBuild.Release.bat @@ -0,0 +1,15 @@ +ECHO OFF +ECHO Starting PreBuild.bat %1 %2 %3 +REM Usage: Call "$(MSBuildProjectDirectory)\App_Data\PreBuild.$(ConfigurationName).bat" "$(MSBuildProjectDirectory)" "$(ConfigurationName)" "$(ProjectName)" +REM Vars: $(ProjectName) = MyCo.Framework. Models, $(TargetPath) = output file, $(TargetDir) = full bin path , $(OutDir) = bin\debug, $(ConfigurationName) = "Debug" + +REM Locals +SET FullPath=%1 +SET FullPath=%FullPath:"=% +ECHO FullPath: %FullPath% +SET Configuration=%2 +ECHO Configuration: %Configuration% +SET ProjectName=%3 +ECHO ProjectName: %ProjectName% + +exit 0 diff --git a/data/Entity.Database/Entity/Tables/Application.sql b/data/Entity.Database/Entity/Tables/Application.sql new file mode 100644 index 00000000..e594d853 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Application.sql @@ -0,0 +1,19 @@ +CREATE TABLE [Entity].[Application] ( + [ApplicationId] INT IDENTITY (1, 1) CONSTRAINT [DF_Application_ApplicationId] NOT NULL, + [ApplicationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Application_ApplicationKey] DEFAULT (NewID()) NOT NULL, + [ApplicationName] NVARCHAR (50) CONSTRAINT [DF_Application_ApplicationName] DEFAULT ('') NOT NULL, + [ApplicationSlogan] NVARCHAR (50) CONSTRAINT [DF_Application_ApplicationSlogan] DEFAULT ('') NOT NULL, + [SharedApplicationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Application_SharedApplicationKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [SharedSecret] INT CONSTRAINT [DF_Application_SharedSecret] DEFAULT(-1) NOT NULL, + [BusinessEntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Application_BusinessEntity] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [PrivacyUrl] NVARCHAR (250) CONSTRAINT [DF_Application_PrivacyUrl] DEFAULT ('') NOT NULL, + [TermsUrl] NVARCHAR (250) CONSTRAINT [DF_Application_TermsUrl] DEFAULT ('') NOT NULL, + [TermsRevisedDate] DATETIME CONSTRAINT [DF_Application_TermsRevisedDate] DEFAULT (getutcdate()) NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Application_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Application_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Application] PRIMARY KEY CLUSTERED ([ApplicationId] ASC), + CONSTRAINT [FK_Application_BusinessEntity] FOREIGN KEY ([BusinessEntityKey]) REFERENCES [Entity].[Entity] ([EntityKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Application_Key] ON [Entity].[Application] ([ApplicationKey] Asc) +Go \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Appointment.sql b/data/Entity.Database/Entity/Tables/Appointment.sql new file mode 100644 index 00000000..5f2bf531 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Appointment.sql @@ -0,0 +1,22 @@ +CREATE TABLE [Entity].[Appointment] ( + [AppointmentId] INT IDENTITY (1, 1) CONSTRAINT [DF_Appointment_AppointmentId] NOT NULL, + [AppointmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Appointment_AppointmentKey] DEFAULT (NewID()) NOT NULL, + [AppointmentName] NVARCHAR (50) CONSTRAINT [DF_Appointment_AppointmentName] DEFAULT ('') NOT NULL, + [AppointmentDescription] NVARCHAR (2000) CONSTRAINT [DF_Appointment_AppointmentDescription] DEFAULT ('') NOT NULL, + [SlotLocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Appointment_SlotLocation] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [SlotResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Appointment_SlotResource] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [TimeRangeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Appointment_TimeRangeId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Appointment_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Appointment_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Appointment_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Appointment] PRIMARY KEY CLUSTERED ([AppointmentId] ASC), + CONSTRAINT [FK_Appointment_Location] FOREIGN KEY ([SlotLocationKey]) REFERENCES [Entity].[SlotLocation] ([SlotLocationKey]), + CONSTRAINT [FK_Appointment_Resource] FOREIGN KEY ([SlotResourceKey]) REFERENCES [Entity].[SlotResource] ([SlotResourceKey]), + CONSTRAINT [FK_Appointment_TimeRange] FOREIGN KEY ([TimeRangeKey]) REFERENCES [Entity].[TimeRange] ([TimeRangeKey]), + CONSTRAINT [FK_Appointment_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Appointment_Key] ON [Entity].[Appointment] ([AppointmentKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_LocationTime_All] ON [Entity].[Appointment] ([SlotLocationKey] Asc, [SlotResourceKey] Asc, [TimeRangeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Area.sql b/data/Entity.Database/Entity/Tables/Area.sql new file mode 100644 index 00000000..b21aa0fa --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Area.sql @@ -0,0 +1,10 @@ +CREATE TABLE [Entity].[Area] ( + [AreaId] INT IDENTITY (1, 1) CONSTRAINT [DF_Area_Id] NOT NULL, + [AreaKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Area_Key] NOT NULL DEFAULT(NewId()), + [Area] Geometry NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Area_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Area] PRIMARY KEY CLUSTERED ([AreaId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Area_Key] ON [Entity].[Area] ([AreaKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/Business.sql b/data/Entity.Database/Entity/Tables/Business.sql new file mode 100644 index 00000000..84090f96 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Business.sql @@ -0,0 +1,15 @@ +CREATE TABLE [Entity].[Business] ( + [BusinessId] INT IDENTITY (1, 1) CONSTRAINT [DF_Business_Business] NOT NULL, + [BusinessKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Business_Entity] DEFAULT(NewId()) NOT NULL, + [BusinessName] NVARCHAR (50) CONSTRAINT [DF_Business_BusinessName] DEFAULT ('') NOT NULL, + [TaxNumber] NVARCHAR (20) CONSTRAINT [DF_Business_TaxNumber] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Business_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Business_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Business_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Business] PRIMARY KEY CLUSTERED ([BusinessId] ASC), + CONSTRAINT [FK_Business_Entity] FOREIGN KEY ([BusinessKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_Business_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_BusinessEntity_Entity] ON [Entity].[Business] ([BusinessKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/Detail.sql b/data/Entity.Database/Entity/Tables/Detail.sql new file mode 100644 index 00000000..2a334c57 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Detail.sql @@ -0,0 +1,13 @@ +CREATE TABLE [Entity].[Detail] ( + [DetailId] INT IDENTITY (1, 1) CONSTRAINT [DF_Detail_Id] NOT NULL, + [DetailKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Detail_Key] DEFAULT (NewID()) NOT NULL, + [DetailTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Detail_DetailType] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [DetailData] NVARCHAR (2000) CONSTRAINT [DF_Detail_DetailData] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Detail_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Detail_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Detail] PRIMARY KEY CLUSTERED ([DetailId] ASC), + CONSTRAINT [FK_Detail_DetailType] FOREIGN KEY ([DetailTypeKey]) REFERENCES [Entity].[DetailType] ([DetailTypeKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Detail_Key] ON [Entity].[Detail] ([DetailKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/DetailType.sql b/data/Entity.Database/Entity/Tables/DetailType.sql new file mode 100644 index 00000000..f490f844 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/DetailType.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[DetailType] ( + [DetailTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_DetailType_DetailTypeId] NOT NULL, + [DetailTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_DetailType_DetailTypeKey] DEFAULT (NewId()) NOT NULL, + [DetailTypeName] NVARCHAR (50) CONSTRAINT [DF_DetailType_DetailTypeName] DEFAULT ('') NOT NULL, + [DetailTypeDescription] NVARCHAR (250) CONSTRAINT [DF_DetailType_DetailTypeDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_DetailType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_DetailType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_DetailType] PRIMARY KEY CLUSTERED ([DetailTypeId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_DetailType_Key] ON [Entity].[DetailType] ([DetailTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Entity.sql b/data/Entity.Database/Entity/Tables/Entity.sql new file mode 100644 index 00000000..3f5c2243 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Entity.sql @@ -0,0 +1,10 @@ +CREATE TABLE [Entity].[Entity] ( + [EntityId] INT IDENTITY (1, 1) CONSTRAINT [DF_Entity_EntityId] NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Entity_EntityKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Entity_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Entity_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Entity] PRIMARY KEY CLUSTERED ([EntityId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Entity_EntityKey] ON [Entity].[Entity] ([EntityKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EntityAppointment.sql b/data/Entity.Database/Entity/Tables/EntityAppointment.sql new file mode 100644 index 00000000..af1c074b --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EntityAppointment.sql @@ -0,0 +1,18 @@ +CREATE TABLE [Entity].[EntityAppointment] ( + [EntityAppointmentId] INT IDENTITY (1, 1) CONSTRAINT [DF_EntityAppointment_Id] NOT NULL, + [EntityAppointmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityAppointment_Key] DEFAULT(NewId()) NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityAppointment_EntityId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [AppointmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityAppointment_AppointmentId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityAppointment_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EntityAppointment_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EntityAppointment_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EntityAppointment] PRIMARY KEY CLUSTERED ([EntityAppointmentId] ASC), + CONSTRAINT [FK_EntityAppointment_Entity] FOREIGN KEY ([EntityKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_EntityAppointment_Appointment] FOREIGN KEY ([AppointmentKey]) REFERENCES [Entity].[Appointment] ([AppointmentKey]), + CONSTRAINT [FK_EntityAppointment_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityAppointment_Key] ON [Entity].[EntityAppointment] ([EntityAppointmentKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityAppointment_All] ON [Entity].[EntityAppointment] ([EntityKey] Asc, [AppointmentKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EntityDetail.sql b/data/Entity.Database/Entity/Tables/EntityDetail.sql new file mode 100644 index 00000000..09aa8a7f --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EntityDetail.sql @@ -0,0 +1,16 @@ +CREATE TABLE [Entity].[EntityDetail] ( + [EntityDetailId] INT IDENTITY (1, 1) CONSTRAINT [DF_EntityDetail_Id] NOT NULL, + [EntityDetailKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityDetail_Key] DEFAULT (NewID()) NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityDetail_Entity] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [DetailKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityDetail_Detail] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EntityDetail_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EntityDetail_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EntityDetail] PRIMARY KEY CLUSTERED ([EntityDetailId] ASC), + CONSTRAINT [FK_EntityDetail_Entity] FOREIGN KEY ([EntityKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_EntityDetail_Detail] FOREIGN KEY ([DetailKey]) REFERENCES [Entity].[Detail] ([DetailKey]), + CONSTRAINT [UQ_EntityDetail_EntityDetailId] UNIQUE NONCLUSTERED ([EntityKey] ASC, [EntityDetailKey] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityDetail_Key] ON [Entity].[EntityDetail] ([EntityDetailKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityDetail_All] ON [Entity].[EntityDetail] ([EntityKey] Asc, [EntityDetailKey] Asc) diff --git a/data/Entity.Database/Entity/Tables/EntityLocation.sql b/data/Entity.Database/Entity/Tables/EntityLocation.sql new file mode 100644 index 00000000..3be3e8ed --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EntityLocation.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[EntityLocation] ( + [EntityLocationId] INT IDENTITY (1, 1) CONSTRAINT [DF_EntityLocation_Entity] NOT NULL, + [EntityLocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityLocation_Entity] DEFAULT(NewId()) NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityLocation_EntityKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityLocation_LocationKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityLocation_LocationType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityLocation_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EntityLocation_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EntityLocation_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EntityLocation] PRIMARY KEY CLUSTERED ([EntityLocationId] ASC), + CONSTRAINT [FK_EntityLocation_Entity] FOREIGN KEY ([EntityKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_EntityLocation_Location] FOREIGN KEY ([LocationKey]) REFERENCES [Entity].[Location] ([LocationKey]), + CONSTRAINT [FK_EntityLocation_LocationType] FOREIGN KEY ([LocationTypeKey]) REFERENCES [Entity].[LocationType] ([LocationTypeKey]), + CONSTRAINT [FK_EntityLocation_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityLocation_Entity] ON [Entity].[Entity] ([EntityKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityLocation_All] ON [Entity].[EntityLocation] ([EntityKey] Asc, [LocationKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/EntityOption.sql b/data/Entity.Database/Entity/Tables/EntityOption.sql new file mode 100644 index 00000000..d5ee1c51 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EntityOption.sql @@ -0,0 +1,13 @@ +CREATE TABLE [Entity].[EntityOption] ( + [EntityOptionId] INT IDENTITY (1, 1) CONSTRAINT [DF_EntityOption_EntityOptionId] NOT NULL, + [EntityOptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityOption_EntityOptionKey] DEFAULT(NewId()) NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityOption_Entity] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [OptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityOption_Option] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EntityOption_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EntityOption_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EntityOption] PRIMARY KEY CLUSTERED ([EntityOptionId] ASC), + CONSTRAINT [FK_EntityOption_Option] FOREIGN KEY ([OptionKey]) REFERENCES [Entity].[Option] ([OptionKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityOption_All] ON [Entity].[EntityOption] ([EntityKey] Asc, [OptionKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EntityTimeRecurring.sql b/data/Entity.Database/Entity/Tables/EntityTimeRecurring.sql new file mode 100644 index 00000000..f983cdcb --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EntityTimeRecurring.sql @@ -0,0 +1,22 @@ +CREATE TABLE [Entity].[EntityTimeRecurring] ( + [EntityTimeRecurringId] INT IDENTITY (1, 1) CONSTRAINT [DF_EntityTimeRecurring_EntityTimeRecurringId] NOT NULL, + [EntityTimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityTimeRecurring_EntityTimeRecurringKey] DEFAULT(NewId()) NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityTimeRecurring_EntityId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [TimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityTimeRecurring_TimeRecurringId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [DayName] NVARCHAR (50) CONSTRAINT [DF_EntityTimeRecurring_DayName] DEFAULT ('') NOT NULL, + [TimeName] NVARCHAR (50) CONSTRAINT [DF_EntityTimeRecurring_TimeName] DEFAULT ('') NOT NULL, + [TimeTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityTimeRecurring_TimeType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EntityTimeRecurring_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EntityTimeRecurring_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EntityTimeRecurring_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EntityTimeRecurring] PRIMARY KEY CLUSTERED ([EntityTimeRecurringId] ASC), + CONSTRAINT [FK_EntityTimeRecurring_Entity] FOREIGN KEY ([EntityKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_EntityTimeRecurring_TimeRecurring] FOREIGN KEY ([TimeRecurringKey]) REFERENCES [Entity].[TimeRecurring] ([TimeRecurringKey]), + CONSTRAINT [FK_EntityAvailable_TimeType] FOREIGN KEY ([TimeTypeKey]) REFERENCES [Entity].[TimeType] ([TimeTypeKey]), + CONSTRAINT [FK_EntityTimeRecurring_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityTimeRecurring_Key] ON [Entity].[EntityTimeRecurring] ([EntityTimeRecurringKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EntityTimeRecurring_All] ON [Entity].[EntityTimeRecurring] ([EntityKey] Asc, [TimeRecurringKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Event.sql b/data/Entity.Database/Entity/Tables/Event.sql new file mode 100644 index 00000000..92b8d692 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Event.sql @@ -0,0 +1,23 @@ +CREATE TABLE [Entity].[Event] ( + [EventId] INT IDENTITY (1, 1) CONSTRAINT [DF_Event_EventId] NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Event_EventKey] DEFAULT (NewID()) NOT NULL, + [EventGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Event_EventGroup] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [EventTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Event_EventType] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [EventCreatorKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Event_EventCreator] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [EventName] NVARCHAR (50) CONSTRAINT [DF_Event_EventName] DEFAULT ('') NOT NULL, + [EventDescription] NVARCHAR (250) CONSTRAINT [DF_Event_EventDescription] DEFAULT ('') NOT NULL, + [EventSlogan] NVARCHAR (50) CONSTRAINT [DF_Event_EventSlogan] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Event_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Event_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Event_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([EventId] ASC), + CONSTRAINT [FK_Event_Entity] FOREIGN KEY ([EventCreatorKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_Event_EventGroup] FOREIGN KEY ([EventGroupKey]) REFERENCES [Entity].[EventGroup] ([EventGroupKey]), + CONSTRAINT [FK_Event_EventType] FOREIGN KEY ([EventTypeKey]) REFERENCES [Entity].[EventType] ([EventTypeKey]), + CONSTRAINT [FK_Event_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE NonCLUSTERED INDEX [IX_Event_All] ON [Entity].[Event] ([EventGroupKey] Asc, [EventCreatorKey] Asc, [EventName] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Event_EventKey] ON [Entity].[Event] ([EventKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/EventAppointment.sql b/data/Entity.Database/Entity/Tables/EventAppointment.sql new file mode 100644 index 00000000..9d35baca --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventAppointment.sql @@ -0,0 +1,18 @@ +CREATE TABLE [Entity].[EventAppointment] ( + [EventAppointmentId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventAppointment_Id] NOT NULL, + [EventAppointmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventAppointment_Key] DEFAULT(NewId()) NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventAppointment_EventId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [AppointmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventAppointment_AppointmentId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventAppointment_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventAppointment_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventAppointment_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventAppointment] PRIMARY KEY CLUSTERED ([EventAppointmentId] ASC), + CONSTRAINT [FK_EventAppointment_Event] FOREIGN KEY ([EventKey]) REFERENCES [Entity].[Event] ([EventKey]), + CONSTRAINT [FK_EventAppointment_Appointment] FOREIGN KEY ([AppointmentKey]) REFERENCES [Entity].[Appointment] ([AppointmentKey]), + CONSTRAINT [FK_EventAppointment_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventAppointment_Key] ON [Entity].[EventAppointment] ([EventAppointmentKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventAppointment_All] ON [Entity].[EventAppointment] ([EventKey] Asc, [AppointmentKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EventDetail.sql b/data/Entity.Database/Entity/Tables/EventDetail.sql new file mode 100644 index 00000000..de842c66 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventDetail.sql @@ -0,0 +1,16 @@ +CREATE TABLE [Entity].[EventDetail] ( + [EventDetailId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventDetail_Id] NOT NULL, + [EventDetailKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventDetail_Key] DEFAULT (NewID()) NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventDetail_Event] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [DetailKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventDetail_Detail] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventDetail_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventDetail_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventDetail] PRIMARY KEY CLUSTERED ([EventDetailId] ASC), + CONSTRAINT [FK_EventDetail_Event] FOREIGN KEY ([EventKey]) REFERENCES [Entity].[Event] ([EventKey]), + CONSTRAINT [FK_EventDetail_Detail] FOREIGN KEY ([DetailKey]) REFERENCES [Entity].[Detail] ([DetailKey]), + CONSTRAINT [UQ_EventDetail_EventDetailId] UNIQUE NONCLUSTERED ([EventKey] ASC, [EventDetailKey] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventDetail_Key] ON [Entity].[EventDetail] ([EventDetailKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventDetail_All] ON [Entity].[EventDetail] ([EventKey] Asc, [EventDetailKey] Asc) diff --git a/data/Entity.Database/Entity/Tables/EventEntityOption.sql b/data/Entity.Database/Entity/Tables/EventEntityOption.sql new file mode 100644 index 00000000..aaae45b7 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventEntityOption.sql @@ -0,0 +1,16 @@ +CREATE TABLE [Entity].[EventEntityOption] ( + [EventEntityOptionId] INT IDENTITY(1,1) CONSTRAINT [DF_EventEntityOption_Id] NOT NULL, + [EventEntityOptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventEntityOption_Key] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [OptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventEntityOption_Option] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventEntityOption_Event] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventEntityOption_Entity] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventEntityOption_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventEntityOption_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventEntityOption] PRIMARY KEY CLUSTERED ([EventEntityOptionId] ASC), + CONSTRAINT [FK_EventEntityOption_Option] FOREIGN KEY ([OptionKey]) REFERENCES [Entity].[Option] ([OptionKey]), + CONSTRAINT [FK_EventEntityOption_Event] FOREIGN KEY ([EventKey]) REFERENCES [Entity].[Event] ([EventKey]), + CONSTRAINT [FK_EventEntityOption_Entity] FOREIGN KEY ([EntityKey]) REFERENCES [Entity].[Entity] ([EntityKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventEntityOption_Key] ON [Entity].[EventEntityOption] ([EventEntityOptionKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/EventGroup.sql b/data/Entity.Database/Entity/Tables/EventGroup.sql new file mode 100644 index 00000000..3b43c16c --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventGroup.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[EventGroup] ( + [EventGroupId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventGroup_EventGroupId] NOT NULL, + [EventGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DC_EventGroup_EventGroupKey] DEFAULT (NewID()) NOT NULL, + [EventGroupName] NVARCHAR (50) CONSTRAINT [DF_EventGroup_EventGroupName] DEFAULT ('') NOT NULL, + [EventGroupDescription] NVARCHAR (250) CONSTRAINT [DF_EventGroup_EventGroupDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventGroup_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventGroup_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventGroup] PRIMARY KEY CLUSTERED ([EventGroupId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventGroup_Key] ON [Entity].[EventGroup] ([EventGroupKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/EventLocation.sql b/data/Entity.Database/Entity/Tables/EventLocation.sql new file mode 100644 index 00000000..9df4729d --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventLocation.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[EventLocation] ( + [EventLocationId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventLocation_Id] NOT NULL, + [EventLocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventLocation_Key] DEFAULT(NewId()) NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventLocation_EventId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventLocation_LocationId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventLocation_LocationType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventLocation_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventLocation_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventLocation_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventLocation] PRIMARY KEY CLUSTERED ([EventLocationId] ASC), + CONSTRAINT [FK_EventLocation_Event] FOREIGN KEY ([EventKey]) REFERENCES [Entity].[Event] ([EventKey]), + CONSTRAINT [FK_EventLocation_Location] FOREIGN KEY ([LocationKey]) REFERENCES [Entity].[Location] ([LocationKey]), + CONSTRAINT [FK_EventLocation_LocationType] FOREIGN KEY ([LocationTypeKey]) REFERENCES [Entity].[LocationType] ([LocationTypeKey]), + CONSTRAINT [FK_EventLocation_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventLocation_Key] ON [Entity].[EventLocation] ([EventLocationKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventLocation_All] ON [Entity].[EventLocation] ([EventKey] Asc, [LocationKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EventOption.sql b/data/Entity.Database/Entity/Tables/EventOption.sql new file mode 100644 index 00000000..1cc2df90 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventOption.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[EventOption] ( + [EventOptionId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventOption_EventOptionId] NOT NULL, + [EventOptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventOption_EventOptionKey] DEFAULT(NewId()) NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventOption_Entity] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [OptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventOption_Option] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventOption_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventOption_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventOption] PRIMARY KEY CLUSTERED ([EventOptionId] ASC), + CONSTRAINT [FK_EventOption_Event] FOREIGN KEY ([EventKey]) REFERENCES [Entity].[Event] ([EventKey]), + CONSTRAINT [FK_EventOption_Option] FOREIGN KEY ([OptionKey]) REFERENCES [Entity].[Option] ([OptionKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventOption_All] ON [Entity].[EventOption] ([EventKey] Asc, [OptionKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EventResource.sql b/data/Entity.Database/Entity/Tables/EventResource.sql new file mode 100644 index 00000000..9e2b83a3 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventResource.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[EventResource] ( + [EventResourceId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventResource_Id] NOT NULL, + [EventResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventResource_Key] DEFAULT(NewId()) NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventResource_EventId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventResource_ResourceId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ResourceTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventResource_ResourceTypeId] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventResource_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventResource_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventResource_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventResource] PRIMARY KEY CLUSTERED ([EventResourceId] ASC), + CONSTRAINT [FK_EventResource_Resource] FOREIGN KEY ([ResourceKey]) REFERENCES [Entity].[Resource] ([ResourceKey]), + CONSTRAINT [FK_EventResource_ResourceType] FOREIGN KEY ([ResourceTypeKey]) REFERENCES [Entity].[ResourceType] ([ResourceTypeKey]), + CONSTRAINT [FK_EventResource_Event] FOREIGN KEY ([EventKey]) REFERENCES [Entity].[Event] ([EventKey]), + CONSTRAINT [FK_EventResource_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventResource_Key] ON [Entity].[EventResource] ([EventResourceKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventResource_All] ON [Entity].[EventResource] ([EventKey] Asc, [ResourceKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EventSchedule.sql b/data/Entity.Database/Entity/Tables/EventSchedule.sql new file mode 100644 index 00000000..2c88397d --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventSchedule.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[EventSchedule] ( + [EventScheduleId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventSchedule_Id] NOT NULL, + [EventScheduleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventSchedule_Key] DEFAULT(NewId()) NOT NULL, + [EventKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventSchedule_EventId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ScheduleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventSchedule_ScheduleId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ScheduleTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventSchedule_ScheduleTypeId] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventSchedule_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventSchedule_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventSchedule_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventSchedule] PRIMARY KEY CLUSTERED ([EventScheduleId] ASC), + CONSTRAINT [FK_EventSchedule_Schedule] FOREIGN KEY ([ScheduleKey]) REFERENCES [Entity].[Schedule] ([ScheduleKey]), + CONSTRAINT [FK_EventSchedule_ScheduleType] FOREIGN KEY ([ScheduleTypeKey]) REFERENCES [Entity].[ScheduleType] ([ScheduleTypeKey]), + CONSTRAINT [FK_EventSchedule_Event] FOREIGN KEY ([EventKey]) REFERENCES [Entity].[Event] ([EventKey]), + CONSTRAINT [FK_EventSchedule_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventSchedule_Key] ON [Entity].[EventSchedule] ([EventScheduleKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventSchedule_All] ON [Entity].[EventSchedule] ([EventKey] Asc, [ScheduleKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/EventType.sql b/data/Entity.Database/Entity/Tables/EventType.sql new file mode 100644 index 00000000..e906402b --- /dev/null +++ b/data/Entity.Database/Entity/Tables/EventType.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[EventType] ( + [EventTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_EventType_EventTypeId] NOT NULL, + [EventTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DC_EventType_EventTypeKey] DEFAULT (NewID()) NOT NULL, + [EventGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DF_EventType_EventGroupId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [EventTypeName] NVARCHAR (50) CONSTRAINT [DF_EventType_EventTypeName] DEFAULT ('') NOT NULL, + [EventTypeDescription] NVARCHAR (250) CONSTRAINT [DF_EventType_EventTypeDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_EventType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_EventType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_EventType] PRIMARY KEY CLUSTERED ([EventTypeId] ASC), + CONSTRAINT [FK_EventType_EventGroup] FOREIGN KEY ([EventGroupKey]) REFERENCES [Entity].[EventGroup] ([EventGroupKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_EventType_Key] ON [Entity].[EventType] ([EventTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Flow.sql b/data/Entity.Database/Entity/Tables/Flow.sql new file mode 100644 index 00000000..4cf0367a --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Flow.sql @@ -0,0 +1,19 @@ +CREATE TABLE [Entity].[Flow] ( + [FlowId] INT IDENTITY (1, 1) CONSTRAINT [DF_Flow_Id] NOT NULL, + [FlowKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Flow_Key] DEFAULT(NewId()) NOT NULL, + [FlowTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Flow_FlowType] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ModuleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Flow_ModuleId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [FlowName] NVARCHAR (50) CONSTRAINT [DF_Flow_FlowName] DEFAULT ('') NOT NULL, + [FlowDescription] NVARCHAR (250) CONSTRAINT [DF_Flow_FlowDescription] DEFAULT ('') NOT NULL, + [NonRepeatable] BIT CONSTRAINT [DF_Flow_NonRepeatable] DEFAULT ((0)) NOT NULL, + [TimeoutInSeconds] INT CONSTRAINT [DF_Flow_TimeoutInSeconds] DEFAULT (-1) NOT NULL, + [RecordDeleteInMinutes] INT CONSTRAINT [DF_Flow_RecordDeleteInMinutes] DEFAULT (-1) NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Flow_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Flow_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Flow] PRIMARY KEY CLUSTERED ([FlowId] ASC), + CONSTRAINT [FK_Flow_FlowType] FOREIGN KEY ([FlowTypeKey]) REFERENCES [Entity].[FlowType] ([FlowTypeKey]), + CONSTRAINT [FK_Flow_Module] FOREIGN KEY ([ModuleKey]) REFERENCES [Entity].[Module] ([ModuleKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Flow_Key] ON [Entity].[Flow] ([FlowKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/FlowSequence.sql b/data/Entity.Database/Entity/Tables/FlowSequence.sql new file mode 100644 index 00000000..4b6e3144 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/FlowSequence.sql @@ -0,0 +1,18 @@ +CREATE TABLE [Entity].[FlowSequence] ( + [FlowSequenceId] INT IDENTITY (1, 1) CONSTRAINT [DF_FlowSequence_FlowSequenceId] NOT NULL, + [FlowSequenceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_FlowSequence_FlowSequenceKey] DEFAULT(NewId()) NOT NULL, + [FlowKey] UNIQUEIDENTIFIER CONSTRAINT [DF_FlowSequencey_Flow] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [FlowStepKey] UNIQUEIDENTIFIER CONSTRAINT [DF_FlowSequence_FlowStep] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [FlowSequenceApplicationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_FlowSequence_FlowSequenceApplication] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [FlowSequenceRoute] NVARCHAR (250) CONSTRAINT [DF_FlowSequence_FlowSequenceRoute] DEFAULT ('') NOT NULL, + [SortOrder] INT CONSTRAINT [DF_FlowSequence_SortOrder] DEFAULT (-1) NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_FlowSequence_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_FlowSequence_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_FlowSequence] PRIMARY KEY CLUSTERED ([FlowSequenceId] ASC), + CONSTRAINT [FK_FlowSequence_Flow] FOREIGN KEY ([FlowKey]) REFERENCES [Entity].[Flow] ([FlowKey]), + CONSTRAINT [FK_FlowSequence_FlowStep] FOREIGN KEY ([FlowStepKey]) REFERENCES [Entity].[FlowStep] ([FlowStepKey]), + CONSTRAINT [FK_FlowSequence_Application] FOREIGN KEY ([FlowSequenceApplicationKey]) REFERENCES [Entity].[Application] ([ApplicationKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_FlowSequence_Key] ON [Entity].[FlowSequence] ([FlowSequenceKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/FlowStep.sql b/data/Entity.Database/Entity/Tables/FlowStep.sql new file mode 100644 index 00000000..9c696d74 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/FlowStep.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[FlowStep] ( + [FlowStepId] INT IDENTITY (1, 1) CONSTRAINT [DF_FlowStep_FlowStepId] NOT NULL, + [FlowStepKey] UNIQUEIDENTIFIER CONSTRAINT [DF_FlowStep_FlowStepKey] DEFAULT(NewId()) NOT NULL, + [FlowStepName] NVARCHAR (50) CONSTRAINT [DF_FlowStep_FlowStepName] DEFAULT ('') NOT NULL, + [FlowStepDescription] NVARCHAR (250) CONSTRAINT [DF_FlowStep_FlowStepDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_FlowStep_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_FlowStep_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_FlowStep] PRIMARY KEY CLUSTERED ([FlowStepId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_FlowStep_Key] ON [Entity].[FlowStep] ([FlowStepKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/FlowType.sql b/data/Entity.Database/Entity/Tables/FlowType.sql new file mode 100644 index 00000000..d30b6e3d --- /dev/null +++ b/data/Entity.Database/Entity/Tables/FlowType.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[FlowType] ( + [FlowTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_FlowType_FlowTypeId] NOT NULL, + [FlowTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_FlowType_FlowTypeKey] DEFAULT(NewId()) NOT NULL, + [FlowTypeName] NVARCHAR (50) CONSTRAINT [DF_FlowType_FlowTypeName] DEFAULT ('') NOT NULL, + [FlowTypeDescription] NVARCHAR (250) CONSTRAINT [DF_FlowType_FlowTypeDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_FlowType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_FlowType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_FlowType] PRIMARY KEY CLUSTERED ([FlowTypeId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_FlowType_Key] ON [Entity].[FlowType] ([FlowTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Gender.sql b/data/Entity.Database/Entity/Tables/Gender.sql new file mode 100644 index 00000000..f963cd4c --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Gender.sql @@ -0,0 +1,15 @@ +CREATE TABLE [Entity].[Gender] ( + [GenderId] INT CONSTRAINT [DF_Gender_GenderId] NOT NULL, + [GenderKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Gender_GenderKey] DEFAULT(NewId()) NOT NULL, + [GenderName] NVARCHAR (50) CONSTRAINT [DF_Gender_GenderName] DEFAULT ('') NOT NULL, + [GenderCode] NVARCHAR(10) CONSTRAINT [DF_Gender_GenderCode] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Gender_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Gender_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Gender] PRIMARY KEY CLUSTERED ([GenderId] ASC), + CONSTRAINT [CC_Gender_Id] CHECK ([GenderId] BETWEEN -1 AND 9) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Gender_Key] ON [Entity].[Gender] ([GenderKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Gender_Code] ON [Entity].[Gender] ([GenderCode] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Government.sql b/data/Entity.Database/Entity/Tables/Government.sql new file mode 100644 index 00000000..5e5df0b1 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Government.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[Government] ( + [GovernmentId] INT IDENTITY (1, 1) CONSTRAINT [DF_Government_Government] NOT NULL, + [GovernmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Government_EntityKey] DEFAULT(NewId()) NOT NULL, + [GovernmentName] NVARCHAR (50) CONSTRAINT [DF_Government_GovernmentName] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Government_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Government_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Government_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Government] PRIMARY KEY CLUSTERED ([GovernmentId] ASC), + CONSTRAINT [FK_Government_Entity] FOREIGN KEY ([GovernmentKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_Government_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Government_Entity] ON [Entity].[Government] ([GovernmentKey] Asc) +Go diff --git a/data/Entity.Database/Entity/Tables/Item.sql b/data/Entity.Database/Entity/Tables/Item.sql new file mode 100644 index 00000000..d56a90bf --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Item.sql @@ -0,0 +1,15 @@ +CREATE TABLE [Entity].[Item] ( + [ItemId] INT IDENTITY (1, 1) CONSTRAINT [DF_Item_ItemId] NOT NULL, + [ItemKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Item_ItemKey] DEFAULT(NewId()) NOT NULL, + [ItemName] NVARCHAR (50) CONSTRAINT [DF_Item_ItemName] DEFAULT ('') NOT NULL, + [ItemDescription] NVARCHAR (2000) CONSTRAINT [DF_Item_ItemDescription] DEFAULT ('') NOT NULL, + [ItemTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Item_ItemType] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Item_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Item_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Item_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Item] PRIMARY KEY CLUSTERED ([ItemId] ASC), + CONSTRAINT [FK_Item_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Item_ItemKey] ON [Entity].[Item] ([ItemKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ItemGroup.sql b/data/Entity.Database/Entity/Tables/ItemGroup.sql new file mode 100644 index 00000000..44c1b07a --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ItemGroup.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[ItemGroup] ( + [ItemGroupId] INT IDENTITY (1, 1) CONSTRAINT [DF_ItemGroup_ItemGroupId] NOT NULL, + [ItemGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DC_ItemGroup_ItemGroupKey] DEFAULT (NewID()) NOT NULL, + [ItemGroupName] NVARCHAR (50) CONSTRAINT [DF_ItemGroup_ItemGroupName] DEFAULT ('') NOT NULL, + [ItemGroupDescription] NVARCHAR (250) CONSTRAINT [DF_ItemGroup_ItemGroupDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ItemGroup_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ItemGroup_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ItemGroup] PRIMARY KEY CLUSTERED ([ItemGroupId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ItemGroup_Key] ON [Entity].[ItemGroup] ([ItemGroupKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ItemType.sql b/data/Entity.Database/Entity/Tables/ItemType.sql new file mode 100644 index 00000000..3dd3a8d6 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ItemType.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[ItemType] ( + [ItemTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_ItemType_ItemTypeId] NOT NULL, + [ItemTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DC_ItemType_ItemTypeKey] DEFAULT (NewID()) NOT NULL, + [ItemGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ItemType_ItemGroupId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ItemTypeName] NVARCHAR (50) CONSTRAINT [DF_ItemType_ItemTypeName] DEFAULT ('') NOT NULL, + [ItemTypeDescription] NVARCHAR (250) CONSTRAINT [DF_ItemType_ItemTypeDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ItemType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ItemType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ItemType] PRIMARY KEY CLUSTERED ([ItemTypeId] ASC), + CONSTRAINT [FK_ItemType_ItemGroup] FOREIGN KEY ([ItemGroupKey]) REFERENCES [Entity].[ItemGroup] ([ItemGroupKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ItemType_Key] ON [Entity].[ItemType] ([ItemTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Location.sql b/data/Entity.Database/Entity/Tables/Location.sql new file mode 100644 index 00000000..f31ec784 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Location.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[Location] ( + [LocationId] INT IDENTITY (1, 1) CONSTRAINT [DF_Location_LocationId] NOT NULL, + [LocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Location_LocationKey] DEFAULT(NewId()) NOT NULL, + [LocationName] NVARCHAR (50) CONSTRAINT [DF_Location_LocationName] DEFAULT ('') NOT NULL, + [LocationDescription] NVARCHAR (2000) CONSTRAINT [DF_Location_LocationDescription] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Location_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Location_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Location_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Location] PRIMARY KEY CLUSTERED ([LocationId] ASC), + CONSTRAINT [FK_Location_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Location_LocationKey] ON [Entity].[Location] ([LocationKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/LocationArea.sql b/data/Entity.Database/Entity/Tables/LocationArea.sql new file mode 100644 index 00000000..4e2d25fa --- /dev/null +++ b/data/Entity.Database/Entity/Tables/LocationArea.sql @@ -0,0 +1,17 @@ +CREATE TABLE [Entity].[LocationArea] ( + [LocationAreaId] INT IDENTITY (1, 1) CONSTRAINT [DF_LocationArea_Id] NOT NULL, + [LocationAreaKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LLocationArea_Key] DEFAULT(NewId()) NOT NULL, + [LocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LocationArea_Location] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [AreaKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LocationArea_Area] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_LocationArea_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_LocationArea_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_LocationArea] PRIMARY KEY CLUSTERED ([LocationAreaId] ASC), + CONSTRAINT [FK_LocationArea_Location] FOREIGN KEY ([LocationKey]) REFERENCES [Entity].[Location] ([LocationKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_LocationArea_Key] ON [Entity].[LocationArea] ([LocationAreaKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_LocationArea_LocationId] ON [Entity].[LocationArea] ([LocationKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_LocationArea_All] ON [Entity].[LocationArea] ([LocationKey] Asc, [AreaKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/LocationTimeRecurring.sql b/data/Entity.Database/Entity/Tables/LocationTimeRecurring.sql new file mode 100644 index 00000000..9d01de59 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/LocationTimeRecurring.sql @@ -0,0 +1,22 @@ +CREATE TABLE [Entity].[LocationTimeRecurring] ( + [LocationTimeRecurringId] INT IDENTITY (1, 1) CONSTRAINT [DF_LocationTimeRecurring_Id] NOT NULL, + [LocationTimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LocationTimeRecurring_Key] DEFAULT(NewId()) NOT NULL, + [LocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LocationTimeRecurring_Location] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [TimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LocationTimeRecurring_TimeRecurring] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [DayName] NVARCHAR (50) CONSTRAINT [DF_LocationTimeRecurring_DayName] DEFAULT ('') NOT NULL, + [TimeName] NVARCHAR (50) CONSTRAINT [DF_LocationTimeRecurring_TimeName] DEFAULT ('') NOT NULL, + [TimeTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LocationTimeRecurring_TimeType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_LocationTimeRecurring_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_LocationTimeRecurring_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_LocationTimeRecurring_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_LocationTimeRecurring] PRIMARY KEY CLUSTERED ([LocationTimeRecurringId] ASC), + CONSTRAINT [FK_LocationTimeRecurring_Location] FOREIGN KEY ([LocationKey]) REFERENCES [Entity].[Location] ([LocationKey]), + CONSTRAINT [FK_LocationTimeRecurring_TimeRecurring] FOREIGN KEY ([TimeRecurringKey]) REFERENCES [Entity].[TimeRecurring] ([TimeRecurringKey]), + CONSTRAINT [FK_LocationAvailable_TimeType] FOREIGN KEY ([TimeTypeKey]) REFERENCES [Entity].[TimeType] ([TimeTypeKey]), + CONSTRAINT [FK_LocationTimeRecurring_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_LocationTimeRecurring_Key] ON [Entity].[LocationTimeRecurring] ([LocationTimeRecurringKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_LocationTimeRecurring_All] ON [Entity].[LocationTimeRecurring] ([LocationKey] Asc, [TimeRecurringKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/LocationType.sql b/data/Entity.Database/Entity/Tables/LocationType.sql new file mode 100644 index 00000000..a36f5043 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/LocationType.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[LocationType] ( + [LocationTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_LocationType_LocationTypeId] NOT NULL, + [LocationTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DC_LocationType_LocationTypeKey] DEFAULT (NewID()) NOT NULL, + [LocationTypeName] NVARCHAR (50) CONSTRAINT [DF_LocationType_LocationTypeName] DEFAULT ('') NOT NULL, + [LocationTypeDescription] NVARCHAR (250) CONSTRAINT [DF_LocationType_LocationTypeDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_LocationType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_LocationType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_LocationType] PRIMARY KEY CLUSTERED ([LocationTypeId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_LocationType_Key] ON [Entity].[LocationType] ([LocationTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Module.sql b/data/Entity.Database/Entity/Tables/Module.sql new file mode 100644 index 00000000..ef17d745 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Module.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[Module] ( + [ModuleId] INT IDENTITY (1, 1) CONSTRAINT [DF_Module_ModuleId] NOT NULL, + [ModuleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Module_ModuleKey] DEFAULT(NewId()) NOT NULL, + [ModuleName] NVARCHAR (50) CONSTRAINT [DF_Module_ModuleName] DEFAULT ('') NOT NULL, + [ModuleDescription] NVARCHAR (250) CONSTRAINT [DF_Module_ModuleDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Module_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Module_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Module] PRIMARY KEY CLUSTERED ([ModuleId] ASC), +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Module_ModuleKey] ON [Entity].[Module] ([ModuleKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/Option.sql b/data/Entity.Database/Entity/Tables/Option.sql new file mode 100644 index 00000000..a88157f9 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Option.sql @@ -0,0 +1,18 @@ +CREATE TABLE [Entity].[Option] ( + [OptionId] INT IDENTITY (1, 1) CONSTRAINT [DF_Option_OptionId] NOT NULL, + [OptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Option_OptionKey] DEFAULT(NewId()) NOT NULL, + [OptionGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Option_OptionGroup] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [OptionName] NVARCHAR (50) CONSTRAINT [DF_Option_OptionName] DEFAULT ('') NOT NULL, + [OptionDescription] NVARCHAR (250) CONSTRAINT [DF_Option_OptionDescription] DEFAULT ('') NOT NULL, + [OptionCode] NVARCHAR (10) CONSTRAINT [DF_Option_OptionCode] DEFAULT ('') NOT NULL, + [SortOrder] INT CONSTRAINT [DF_Option_SortOrder] DEFAULT ((-1)) NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Option_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Option_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Option] PRIMARY KEY CLUSTERED ([OptionId] ASC), + CONSTRAINT [FK_Option_OptionGroup] FOREIGN KEY ([OptionGroupKey]) REFERENCES [Entity].[OptionGroup] ([OptionGroupKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Option_OptionKey] ON [Entity].[Option] ([OptionKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Option_OptionCode] ON [Entity].[Option] ([OptionGroupKey] Asc, [OptionCode] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/OptionGroup.sql b/data/Entity.Database/Entity/Tables/OptionGroup.sql new file mode 100644 index 00000000..60746c26 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/OptionGroup.sql @@ -0,0 +1,15 @@ +CREATE TABLE [Entity].[OptionGroup] ( + [OptionGroupId] INT IDENTITY (1, 1) CONSTRAINT [DF_OptionGroup_OptionGroupId] NOT NULL, + [OptionGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DF_OptionGroup_OptionGroupKey] DEFAULT(NewId()) NOT NULL, + [OptionGroupName] NVARCHAR (50) CONSTRAINT [DF_OptionGroup_OptionGroupName] DEFAULT ('') NOT NULL, + [OptionGroupDescription] NVARCHAR (250) CONSTRAINT [DF_OptionGroup_OptionGroupDescription] DEFAULT ('') NOT NULL, + [OptionGroupCode] NVARCHAR (10) CONSTRAINT [DF_OptionGroup_OptionGroupCode] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_OptionGroup_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_OptionGroup_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_OptionGroup] PRIMARY KEY CLUSTERED ([OptionGroupId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Option_OptionGroupKey] ON [Entity].[OptionGroup] ([OptionGroupKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Option_OptionGroupCode] ON [Entity].[OptionGroup] ([OptionGroupCode] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Person.sql b/data/Entity.Database/Entity/Tables/Person.sql new file mode 100644 index 00000000..8a05f39c --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Person.sql @@ -0,0 +1,21 @@ +CREATE TABLE [Entity].[Person] ( + [PersonId] INT IDENTITY (1, 1) CONSTRAINT [DF_Person_PersonId] NOT NULL, + [PersonKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Person_Entity] DEFAULT(NewId()) NOT NULL, + [FirstName] NVARCHAR (50) CONSTRAINT [DF_Person_FirstName] DEFAULT ('') NOT NULL, + [MiddleName] NVARCHAR (50) CONSTRAINT [DF_Person_MiddleName] DEFAULT ('') NOT NULL, + [LastName] NVARCHAR (50) CONSTRAINT [DF_Person_LastName] DEFAULT ('') NOT NULL, + [BirthDate] DATETIME CONSTRAINT [DF_Person_BirthDate] DEFAULT ('01-01-1900') NOT NULL, + [GenderId] INT CONSTRAINT [DF_Person_GenderId] DEFAULT(-1) NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Person_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Person_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Person_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED ([PersonId] ASC), + CONSTRAINT [FK_Person_Entity] FOREIGN KEY ([PersonKey]) REFERENCES [Entity].[Entity] ([EntityKey]), + CONSTRAINT [FK_Person_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]), + CONSTRAINT [FK_Person_Gender] FOREIGN KEY ([GenderId]) REFERENCES [Entity].[Gender] ([GenderId]) +); +GO +CREATE NonCLUSTERED INDEX [IX_Person_All] ON [Entity].[Person] ([FirstName] Asc, [MiddleName] Asc, [LastName] Asc, [BirthDate] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Person_Entity] ON [Entity].[Person] ([PersonKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/RecordState.sql b/data/Entity.Database/Entity/Tables/RecordState.sql new file mode 100644 index 00000000..c8c62764 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/RecordState.sql @@ -0,0 +1,11 @@ +CREATE TABLE [Entity].[RecordState] ( + [RecordStateId] INT CONSTRAINT [DF_RecordState_RecordStateId] NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_RecordState_RecordStateKey] DEFAULT(NewId()) NOT NULL, + [RecordStateName] NVARCHAR (50) CONSTRAINT [DF_RecordState_RecordStateName] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_RecordState_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_RecordState_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_RecordState] PRIMARY KEY CLUSTERED ([RecordStateId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_RecordState_Key] ON [Entity].[RecordState] ([RecordStateKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Resource.sql b/data/Entity.Database/Entity/Tables/Resource.sql new file mode 100644 index 00000000..8b37f8a9 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Resource.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[Resource] ( + [ResourceId] INT IDENTITY (1, 1) CONSTRAINT [DF_Resource_ResourceId] NOT NULL, + [ResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Resource_ResourceKey] DEFAULT(NewId()) NOT NULL, + [ResourceName] NVARCHAR (50) CONSTRAINT [DF_Resource_ResourceName] DEFAULT ('') NOT NULL, + [ResourceDescription] NVARCHAR (250) CONSTRAINT [DF_Resource_ResourceDescription] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Resource_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Resource_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Resource_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Resource] PRIMARY KEY CLUSTERED ([ResourceId] ASC), + CONSTRAINT [FK_Resource_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Resource_ResourceKey] ON [Entity].[Resource] ([ResourceKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ResourceItem.sql b/data/Entity.Database/Entity/Tables/ResourceItem.sql new file mode 100644 index 00000000..d94ac831 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ResourceItem.sql @@ -0,0 +1,22 @@ +CREATE TABLE [Entity].[ResourceItem] ( + [ResourceItemId] INT IDENTITY (1, 1) CONSTRAINT [DF_ResourceItem_ResourceItemId] NOT NULL, + [ResourceItemKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceItem_ResourceItemKey] DEFAULT(NewId()) NOT NULL, + [ResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceItem_Resource] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ItemKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceItem_Item] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceItem_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ResourceItem_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ResourceItem_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ResourceItem] PRIMARY KEY CLUSTERED ([ResourceItemId] ASC), + CONSTRAINT [FK_ResourceItem_Resource] FOREIGN KEY ([ResourceKey]) REFERENCES [Entity].[Resource] ([ResourceKey]), + CONSTRAINT [FK_ResourceItem_Item] FOREIGN KEY ([ItemKey]) REFERENCES [Entity].[Item] ([ItemKey]), + CONSTRAINT [FK_ResourceItem_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ResourceItem_Key] ON [Entity].[ResourceItem] ([ResourceItemKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_ResourceItem_Resource] ON [Entity].[ResourceItem] ([ResourceKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_ResourceItem_Item] ON [Entity].[ResourceItem] ([ItemKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ResourceItem_All] ON [Entity].[ResourceItem] ([ResourceKey] Asc, [ItemKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ResourcePerson.sql b/data/Entity.Database/Entity/Tables/ResourcePerson.sql new file mode 100644 index 00000000..d25ebd1c --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ResourcePerson.sql @@ -0,0 +1,22 @@ +CREATE TABLE [Entity].[ResourcePerson] ( + [ResourcePersonId] INT IDENTITY (1, 1) CONSTRAINT [DF_ResourcePerson_ResourcePersonId] NOT NULL, + [ResourcePersonKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourcePerson_ResourcePersonKey] DEFAULT(NewId()) NOT NULL, + [ResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceResource_Resource] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [PersonKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourcePerson_Person] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourcePerson_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ResourcePerson_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ResourcePerson_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ResourcePerson] PRIMARY KEY CLUSTERED ([ResourcePersonId] ASC), + CONSTRAINT [FK_ResourceResource_Resource] FOREIGN KEY ([ResourceKey]) REFERENCES [Entity].[Resource] ([ResourceKey]), + CONSTRAINT [FK_ResourcePerson_Person] FOREIGN KEY ([PersonKey]) REFERENCES [Entity].[Person] ([PersonKey]), + CONSTRAINT [FK_ResourcePerson_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ResourcePerson_Key] ON [Entity].[ResourcePerson] ([ResourcePersonKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_ResourcePerson_Resource] ON [Entity].[ResourcePerson] ([ResourceKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_ResourcePerson_Person] ON [Entity].[ResourcePerson] ([PersonKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ResourcePerson_All] ON [Entity].[ResourcePerson] ([ResourceKey] Asc, [PersonKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ResourceTimeRecurring.sql b/data/Entity.Database/Entity/Tables/ResourceTimeRecurring.sql new file mode 100644 index 00000000..0602ef4e --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ResourceTimeRecurring.sql @@ -0,0 +1,24 @@ +CREATE TABLE [Entity].[ResourceTimeRecurring] ( + [ResourceTimeRecurringId] INT IDENTITY (1, 1) CONSTRAINT [DF_ResourceTimeRecurring_ResourceTimeRecurringId] NOT NULL, + [ResourceTimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceTimeRecurring_ResourceTimeRecurringKey] DEFAULT(NewId()) NOT NULL, + [ResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceTimeRecurring_Resource] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [TimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceTimeRecurring_TimeRecurring] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [DayName] NVARCHAR (50) CONSTRAINT [DF_ResourceTimeRecurring_DayName] DEFAULT ('') NOT NULL, + [TimeName] NVARCHAR (50) CONSTRAINT [DF_ResourceTimeRecurring_TimeName] DEFAULT ('') NOT NULL, + [TimeTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceTimeRecurring_TimeType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ResourceTimeRecurring_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ResourceTimeRecurring_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ResourceTimeRecurring_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ResourceTimeRecurring] PRIMARY KEY CLUSTERED ([ResourceTimeRecurringId] ASC), + CONSTRAINT [FK_ResourceTimeRecurring_Resource] FOREIGN KEY ([ResourceKey]) REFERENCES [Entity].[Resource] ([ResourceKey]), + CONSTRAINT [FK_ResourceTimeRecurring_TimeRecurring] FOREIGN KEY ([TimeRecurringKey]) REFERENCES [Entity].[TimeRecurring] ([TimeRecurringKey]), + CONSTRAINT [FK_ResourceTimeRecurring_TimeType] FOREIGN KEY ([TimeTypeKey]) REFERENCES [Entity].[TimeType] ([TimeTypeKey]), + CONSTRAINT [FK_ResourceTimeRecurring_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ResourceTimeRecurring_Resource] ON [Entity].[ResourceTimeRecurring] ([ResourceTimeRecurringKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_ResourceTimeRecurring_Resource] ON [Entity].[SlotResource] ([ResourceKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ResourceTimeRecurring_All] ON [Entity].[ResourceTimeRecurring] ([ResourceKey] Asc, [TimeRecurringKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ResourceType.sql b/data/Entity.Database/Entity/Tables/ResourceType.sql new file mode 100644 index 00000000..ec5aec39 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ResourceType.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[ResourceType] ( + [ResourceTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_ResourceType_ResourceTypeId] NOT NULL, + [ResourceTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DC_ResourceType_ResourceTypeKey] DEFAULT (NewID()) NOT NULL, + [ResourceTypeName] NVARCHAR (50) CONSTRAINT [DF_ResourceType_ResourceTypeName] DEFAULT ('') NOT NULL, + [ResourceTypeDescription] NVARCHAR (250) CONSTRAINT [DF_ResourceType_ResourceTypeDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ResourceType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ResourceType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ResourceType] PRIMARY KEY CLUSTERED ([ResourceTypeId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ResourceType_Key] ON [Entity].[ResourceType] ([ResourceTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Schedule.sql b/data/Entity.Database/Entity/Tables/Schedule.sql new file mode 100644 index 00000000..466e3a45 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Schedule.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[Schedule] ( + [ScheduleId] INT IDENTITY (1, 1) CONSTRAINT [DF_Schedule_ScheduleId] NOT NULL, + [ScheduleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Schedule_ScheduleKey] DEFAULT(NewId()) NOT NULL, + [ScheduleName] NVARCHAR (50) CONSTRAINT [DF_Schedule_ScheduleName] DEFAULT ('') NOT NULL, + [ScheduleDescription] NVARCHAR (2000) CONSTRAINT [DF_Schedule_ScheduleDescription] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Schedule_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Schedule_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Schedule_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Schedule] PRIMARY KEY CLUSTERED ([ScheduleId] ASC), + CONSTRAINT [FK_Schedule_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Schedule_ScheduleKey] ON [Entity].[Schedule] ([ScheduleKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ScheduleSlot.sql b/data/Entity.Database/Entity/Tables/ScheduleSlot.sql new file mode 100644 index 00000000..f50c43aa --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ScheduleSlot.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[ScheduleSlot] ( + [ScheduleSlotId] INT IDENTITY (1, 1) CONSTRAINT [DF_ScheduleSlot_ScheduleSlotId] NOT NULL, + [ScheduleSlotKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ScheduleSlot_ScheduleSlotKey] DEFAULT(NewId()) NOT NULL, + [ScheduleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ScheduleSlot_ScheduleKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [SlotKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ScheduleSlot_SlotKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ScheduleSlot_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ScheduleSlot_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ScheduleSlot] PRIMARY KEY CLUSTERED ([ScheduleSlotId] ASC), + CONSTRAINT [FK_ScheduleSlot_Slot] FOREIGN KEY ([SlotKey]) REFERENCES [Entity].[Slot] ([SlotKey]), + CONSTRAINT [FK_ScheduleSlot_Schedule] FOREIGN KEY ([ScheduleKey]) REFERENCES [Entity].[Schedule] ([ScheduleKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ScheduleSlot_Key] ON [Entity].[ScheduleSlot] ([ScheduleSlotKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_ScheduleSlot_Schedule] ON [Entity].[ScheduleSlot] ([ScheduleKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_ScheduleSlot_Slot] ON [Entity].[ScheduleSlot] ([SlotKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ScheduleSlot_All] ON [Entity].[ScheduleSlot] ([SlotKey] Asc, [ScheduleKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/ScheduleType.sql b/data/Entity.Database/Entity/Tables/ScheduleType.sql new file mode 100644 index 00000000..f8780107 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/ScheduleType.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Entity].[ScheduleType] ( + [ScheduleTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_ScheduleType_ScheduleTypeId] NOT NULL, + [ScheduleTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DC_ScheduleType_ScheduleTypeKey] DEFAULT (NewID()) NOT NULL, + [ScheduleTypeName] NVARCHAR (50) CONSTRAINT [DF_ScheduleType_ScheduleTypeName] DEFAULT ('') NOT NULL, + [ScheduleTypeDescription] NVARCHAR (250) CONSTRAINT [DF_ScheduleType_ScheduleTypeDescription] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ScheduleType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_ScheduleType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ScheduleType] PRIMARY KEY CLUSTERED ([ScheduleTypeId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ScheduleType_Key] ON [Entity].[ScheduleType] ([ScheduleTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Slot.sql b/data/Entity.Database/Entity/Tables/Slot.sql new file mode 100644 index 00000000..a3ce2c57 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Slot.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[Slot] ( + [SlotId] INT IDENTITY (1, 1) CONSTRAINT [DF_Slot_SlotId] NOT NULL, + [SlotKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Slot_SlotKey] DEFAULT(NewId()) NOT NULL, + [SlotName] NVARCHAR (50) CONSTRAINT [DF_Slot_SlotName] DEFAULT ('') NOT NULL, + [SlotDescription] NVARCHAR (2000) CONSTRAINT [DF_Slot_SlotDescription] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Slot_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Slot_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Slot_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Slot] PRIMARY KEY CLUSTERED ([SlotId] ASC), + CONSTRAINT [FK_Slot_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Slot_SlotKey] ON [Entity].[Slot] ([SlotKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/SlotLocation.sql b/data/Entity.Database/Entity/Tables/SlotLocation.sql new file mode 100644 index 00000000..3bdc73c2 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/SlotLocation.sql @@ -0,0 +1,22 @@ +CREATE TABLE [Entity].[SlotLocation] ( + [SlotLocationId] INT IDENTITY (1, 1) CONSTRAINT [DF_SlotLocation_SlotLocationId] NOT NULL, + [SlotLocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotLocation_SlotLocationKey] DEFAULT(NewId()) NOT NULL, + [SlotKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotLocation_SlotKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotLocation_LocationKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotLocation_LocationType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotLocation_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_SlotLocation_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_SlotLocation_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_SlotLocation] PRIMARY KEY CLUSTERED ([SlotLocationId] ASC), + CONSTRAINT [FK_SlotLocation_Slot] FOREIGN KEY ([SlotKey]) REFERENCES [Entity].[Slot] ([SlotKey]), + CONSTRAINT [FK_SlotLocation_Location] FOREIGN KEY ([LocationKey]) REFERENCES [Entity].[Location] ([LocationKey]), + CONSTRAINT [FK_SlotLocation_LocationType] FOREIGN KEY ([LocationTypeKey]) REFERENCES [Entity].[LocationType] ([LocationTypeKey]), + CONSTRAINT [FK_SlotLocation_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_SlotLocation_Key] ON [Entity].[SlotLocation] ([SlotLocationKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_SlotLocation_Slot] ON [Entity].[SlotLocation] ([SlotKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_SlotLocation_All] ON [Entity].[SlotLocation] ([SlotKey] Asc, [LocationKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/SlotResource.sql b/data/Entity.Database/Entity/Tables/SlotResource.sql new file mode 100644 index 00000000..bf071546 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/SlotResource.sql @@ -0,0 +1,24 @@ +CREATE TABLE [Entity].[SlotResource] ( + [SlotResourceId] INT IDENTITY (1, 1) CONSTRAINT [DF_SlotResource_SlotResourceId] NOT NULL, + [SlotResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotResource_SlotResourceKey] DEFAULT(NewId()) NOT NULL, + [SlotKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotResource_SlotId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotResource_ResourceId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ResourceTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotResource_ResourceType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotResource_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_SlotResource_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_SlotResource_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_SlotResource] PRIMARY KEY CLUSTERED ([SlotResourceId] ASC), + CONSTRAINT [FK_SlotResource_Slot] FOREIGN KEY ([SlotKey]) REFERENCES [Entity].[Slot] ([SlotKey]), + CONSTRAINT [FK_SlotResource_Resource] FOREIGN KEY ([ResourceKey]) REFERENCES [Entity].[Resource] ([ResourceKey]), + CONSTRAINT [FK_SlotResource_ResourceType] FOREIGN KEY ([ResourceTypeKey]) REFERENCES [Entity].[ResourceType] ([ResourceTypeKey]), + CONSTRAINT [FK_SlotResource_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE NonCLUSTERED INDEX [IX_SlotResource_Slot] ON [Entity].[SlotResource] ([SlotKey] Asc) +GO +CREATE NonCLUSTERED INDEX [IX_SlotResource_Resource] ON [Entity].[SlotResource] ([ResourceKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_SlotResource_All] ON [Entity].[SlotResource] ([ResourceKey] Asc, [SlotKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_SlotResource_SlotResourceKey] ON [Entity].[SlotResource] ([SlotResourceKey] Asc) +Go \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/SlotTimeRange.sql b/data/Entity.Database/Entity/Tables/SlotTimeRange.sql new file mode 100644 index 00000000..200d22bb --- /dev/null +++ b/data/Entity.Database/Entity/Tables/SlotTimeRange.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[SlotTimeRange] ( + [SlotTimeRangeId] INT IDENTITY (1, 1) CONSTRAINT [DF_SlotTimeRange_SlotTimeRangeId] NOT NULL, + [SlotTimeRangeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Application_SlotTimeRangeKey] DEFAULT (NewId()) NOT NULL, + [SlotKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRange_SlotId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [TimeRangeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRange_TimeRangeId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [TimeTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRange_TimeType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRange_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_SlotTimeRange_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_SlotTimeRange_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_SlotTimeRange] PRIMARY KEY CLUSTERED ([SlotTimeRangeId] ASC), + CONSTRAINT [FK_SlotTimeRange_Slot] FOREIGN KEY ([SlotKey]) REFERENCES [Entity].[Slot] ([SlotKey]), + CONSTRAINT [FK_SlotTimeRange_TimeRange] FOREIGN KEY ([TimeRangeKey]) REFERENCES [Entity].[TimeRange] ([TimeRangeKey]), + CONSTRAINT [FK_SlotTimeRange_TimeType] FOREIGN KEY ([TimeTypeKey]) REFERENCES [Entity].[TimeType] ([TimeTypeKey]), + CONSTRAINT [FK_SlotTimeRange_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE NonCLUSTERED INDEX [IX_SlotTimeRange_Slot] ON [Entity].[SlotTimeRange] ([SlotKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_SlotTime_All] ON [Entity].[SlotTimeRange] ([SlotKey] Asc, [TimeRangeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/SlotTimeRecurring.sql b/data/Entity.Database/Entity/Tables/SlotTimeRecurring.sql new file mode 100644 index 00000000..a34d2f0f --- /dev/null +++ b/data/Entity.Database/Entity/Tables/SlotTimeRecurring.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[SlotTimeRecurring] ( + [SlotTimeRecurringId] INT IDENTITY (1, 1) CONSTRAINT [DF_SlotTimeRecurring_SlotTimeRecurringId] NOT NULL, + [SlotTimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Application_SlotTimeRecurringKey] DEFAULT (NewId()) NOT NULL, + [SlotKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRecurring_SlotId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [TimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRecurring_TimeRecurringId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [TimeTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRecurring_TimeType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SlotTimeRecurring_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_SlotTimeRecurring_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_SlotTimeRecurring_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_SlotTimeRecurring] PRIMARY KEY CLUSTERED ([SlotTimeRecurringId] ASC), + CONSTRAINT [FK_SlotTimeRecurring_Slot] FOREIGN KEY ([SlotKey]) REFERENCES [Entity].[Slot] ([SlotKey]), + CONSTRAINT [FK_SlotTimeRecurring_TimeRecurring] FOREIGN KEY ([TimeRecurringKey]) REFERENCES [Entity].[TimeRecurring] ([TimeRecurringKey]), + CONSTRAINT [FK_SlotTimeRecurring_TimeType] FOREIGN KEY ([TimeTypeKey]) REFERENCES [Entity].[TimeType] ([TimeTypeKey]), + CONSTRAINT [FK_SlotTimeRecurring_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE NonCLUSTERED INDEX [IX_SlotTimeRecurring_Slot] ON [Entity].[SlotTimeRecurring] ([SlotKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_SlotTime_All] ON [Entity].[SlotTimeRecurring] ([SlotKey] Asc, [TimeRecurringKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/TimeCycle.sql b/data/Entity.Database/Entity/Tables/TimeCycle.sql new file mode 100644 index 00000000..91b6e60a --- /dev/null +++ b/data/Entity.Database/Entity/Tables/TimeCycle.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[TimeCycle] ( + [TimeCycleId] INT IDENTITY (1, 1) CONSTRAINT [DF_TimeCycle_TimeCycleId] NOT NULL, + [TimeCycleKey] UNIQUEIDENTIFIER CONSTRAINT [DC_TimeCycle_TimeCycleKey] DEFAULT (NewID()) NOT NULL, + [TimeCycleName] NVARCHAR (50) CONSTRAINT [DF_TimeCycle_TimeCycleName] DEFAULT ('') NOT NULL, + [TimeCycleDescription] NVARCHAR (250) CONSTRAINT [DF_TimeCycle_TimeCycleDescription] DEFAULT ('') NOT NULL, + [Days] INT CONSTRAINT [DF_TimeCycle_Days] DEFAULT (-1) NOT NULL, + [Interval] INT CONSTRAINT [DF_TimeCycle_Interval] DEFAULT (-1) NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_TimeCycle_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_TimeCycle_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_TimeCycle] PRIMARY KEY CLUSTERED ([TimeCycleId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_TimeCycle_Key] ON [Entity].[TimeCycle] ([TimeCycleKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/TimeRange.sql b/data/Entity.Database/Entity/Tables/TimeRange.sql new file mode 100644 index 00000000..f5c8fdc5 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/TimeRange.sql @@ -0,0 +1,13 @@ +CREATE TABLE [Entity].[TimeRange] ( + [TimeRangeId] INT IDENTITY (1, 1) CONSTRAINT [DF_TimeRange_TimeRangeId] NOT NULL, + [TimeRangeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Event_TimeRangeKey] DEFAULT (NewId()) NOT NULL, + [BeginDate] DATETIME CONSTRAINT [DF_TimeRange_BeginDate] DEFAULT (getutcdate()) NOT NULL, + [EndDate] DATETIME CONSTRAINT [DF_TimeRange_EndDate] DEFAULT (getutcdate()) NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_TimeRange_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_TimeRange] PRIMARY KEY CLUSTERED ([TimeRangeId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_TimeRange_All] ON [Entity].[TimeRange] ([BeginDate] Asc, [EndDate] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_TimeRange_TimeRangeKey] ON [Entity].[TimeRange] ([TimeRangeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/TimeRecurring.sql b/data/Entity.Database/Entity/Tables/TimeRecurring.sql new file mode 100644 index 00000000..b622ef6e --- /dev/null +++ b/data/Entity.Database/Entity/Tables/TimeRecurring.sql @@ -0,0 +1,19 @@ +CREATE TABLE [Entity].[TimeRecurring] ( + [TimeRecurringId] INT IDENTITY (1, 1) CONSTRAINT [DF_TimeRecurring_TimeRecurringId] NOT NULL, + [TimeRecurringKey] UNIQUEIDENTIFIER CONSTRAINT [DF_TimeRecurring_TimeRecurringKey] DEFAULT ('00000000-0000-0000-0000-000000000000') NOT NULL, + [BeginDay] INT CONSTRAINT [DF_TimeRecurring_BeginDate] DEFAULT (-1) NOT NULL, + [EndDay] INT CONSTRAINT [DF_TimeRecurring_EndDate] DEFAULT (-1) NOT NULL, + [BeginTime] DATETIME CONSTRAINT [DF_TimeRecurring_BeginTime] DEFAULT ('01/01/1900') NOT NULL, + [EndTime] DATETIME CONSTRAINT [DF_TimeRecurring_EndTime] DEFAULT ('01/01/1900') NOT NULL, + [Interval] INT CONSTRAINT [DF_TimeRecurring_Interval] DEFAULT (1) NOT NULL, + [TimeCycleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_TimeRecurring_TimeCycle] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_TimeRecurring_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_TimeRecurring] PRIMARY KEY CLUSTERED ([TimeRecurringId] ASC), + CONSTRAINT [FK_TimeRecurring_TimeCycle] FOREIGN KEY ([TimeCycleKey]) REFERENCES [Entity].[TimeCycle] ([TimeCycleKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_TimeRecurring_All] ON [Entity].[TimeRecurring] + ([BeginDay] Asc, [EndDay] Asc, [BeginTime] Asc, [EndTime] Asc, [Interval] Asc, [TimeCycleKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_TimeRecurring_TimeRecurringKey] ON [Entity].[TimeRecurring] ([TimeRecurringKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/TimeType.sql b/data/Entity.Database/Entity/Tables/TimeType.sql new file mode 100644 index 00000000..a6c05384 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/TimeType.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[TimeType] ( + [TimeTypeId] INT IDENTITY (1, 1) CONSTRAINT [DF_TimeType_TimeTypeId] NOT NULL, + [TimeTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DC_TimeType_TimeTypeKey] DEFAULT (NewID()) NOT NULL, + [TimeTypeName] NVARCHAR (50) CONSTRAINT [DF_TimeType_TimeTypeName] DEFAULT ('') NOT NULL, + [TimeTypeDescription] NVARCHAR (250) CONSTRAINT [DF_TimeType_TimeTypeDescription] DEFAULT ('') NOT NULL, + [TimeBehavior] INT CONSTRAINT [DF_TimeType_TimeBehavior] DEFAULT (1) NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_TimeType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_TimeType_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_TimeType] PRIMARY KEY CLUSTERED ([TimeTypeId] ASC), + CONSTRAINT [CC_TimeType_TimeBehavior] CHECK ([TimeBehavior] BETWEEN -1 AND 1) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_TimeType_Key] ON [Entity].[TimeType] ([TimeTypeKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/Venture.sql b/data/Entity.Database/Entity/Tables/Venture.sql new file mode 100644 index 00000000..0673675f --- /dev/null +++ b/data/Entity.Database/Entity/Tables/Venture.sql @@ -0,0 +1,17 @@ +CREATE TABLE [Entity].[Venture] ( + [VentureId] INT IDENTITY (1, 1) CONSTRAINT [DF_Venture_VentureId] NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Venture_VentureKey] DEFAULT (NewID()) NOT NULL, + [VentureGroupKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Venture_VentureGroup] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [VentureTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Venture_VentureType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [VentureName] NVARCHAR (50) CONSTRAINT [DF_Venture_VentureName] DEFAULT ('') NOT NULL, + [VentureDescription] NVARCHAR (250) CONSTRAINT [DF_Venture_VentureDescription] DEFAULT ('') NOT NULL, + [VentureSlogan] NVARCHAR (50) CONSTRAINT [DF_Venture_VentureSlogan] DEFAULT ('') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Venture_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Venture_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Venture_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Venture] PRIMARY KEY CLUSTERED ([VentureId] ASC), + CONSTRAINT [FK_Venture_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Venture_VentureKey] ON [Entity].[Venture] ([VentureKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/VentureAppointment.sql b/data/Entity.Database/Entity/Tables/VentureAppointment.sql new file mode 100644 index 00000000..8df1eca8 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/VentureAppointment.sql @@ -0,0 +1,18 @@ +CREATE TABLE [Entity].[VentureAppointment] ( + [VentureAppointmentId] INT IDENTITY (1, 1) CONSTRAINT [DF_VentureAppointment_Id] NOT NULL, + [VentureAppointmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureAppointment_Key] DEFAULT(NewId()) NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureAppointment_VentureId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [AppointmentKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureAppointment_AppointmentId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureAppointment_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_VentureAppointment_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_VentureAppointment_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_VentureAppointment] PRIMARY KEY CLUSTERED ([VentureAppointmentId] ASC), + CONSTRAINT [FK_VentureAppointment_Venture] FOREIGN KEY ([VentureKey]) REFERENCES [Entity].[Venture] ([VentureKey]), + CONSTRAINT [FK_VentureAppointment_Appointment] FOREIGN KEY ([AppointmentKey]) REFERENCES [Entity].[Appointment] ([AppointmentKey]), + CONSTRAINT [FK_VentureAppointment_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureAppointment_Key] ON [Entity].[VentureAppointment] ([VentureAppointmentKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureAppointment_All] ON [Entity].[VentureAppointment] ([VentureKey] Asc, [AppointmentKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/VentureDetail.sql b/data/Entity.Database/Entity/Tables/VentureDetail.sql new file mode 100644 index 00000000..895da215 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/VentureDetail.sql @@ -0,0 +1,16 @@ +CREATE TABLE [Entity].[VentureDetail] ( + [VentureDetailId] INT IDENTITY (1, 1) CONSTRAINT [DF_VentureDetail_Id] NOT NULL, + [VentureDetailKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureDetail_Key] DEFAULT (NewID()) NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureDetail_Venture] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [DetailKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureDetail_Detail] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_VentureDetail_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_VentureDetail_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_VentureDetail] PRIMARY KEY CLUSTERED ([VentureDetailId] ASC), + CONSTRAINT [FK_VentureDetail_Venture] FOREIGN KEY ([VentureKey]) REFERENCES [Entity].[Venture] ([VentureKey]), + CONSTRAINT [FK_VentureDetail_Detail] FOREIGN KEY ([DetailKey]) REFERENCES [Entity].[Detail] ([DetailKey]), + CONSTRAINT [UQ_VentureDetail_VentureDetailId] UNIQUE NONCLUSTERED ([VentureKey] ASC, [VentureDetailKey] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureDetail_Key] ON [Entity].[VentureDetail] ([VentureDetailKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureDetail_All] ON [Entity].[VentureDetail] ([VentureKey] Asc, [VentureDetailKey] Asc) diff --git a/data/Entity.Database/Entity/Tables/VentureEntityOption.sql b/data/Entity.Database/Entity/Tables/VentureEntityOption.sql new file mode 100644 index 00000000..84a28393 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/VentureEntityOption.sql @@ -0,0 +1,16 @@ +CREATE TABLE [Entity].[VentureEntityOption] ( + [VentureEntityOptionId] INT IDENTITY(1,1) CONSTRAINT [DF_VentureEntityOption_Id] NOT NULL, + [VentureEntityOptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureEntityOption_Key] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [OptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureEntityOption_Option] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureEntityOption_Venture] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [EntityKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureEntityOption_Entity] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_VentureEntityOption_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_VentureEntityOption_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_VentureEntityOption] PRIMARY KEY CLUSTERED ([VentureEntityOptionId] ASC), + CONSTRAINT [FK_VentureEntityOption_Option] FOREIGN KEY ([OptionKey]) REFERENCES [Entity].[Option] ([OptionKey]), + CONSTRAINT [FK_VentureEntityOption_Venture] FOREIGN KEY ([VentureKey]) REFERENCES [Entity].[Venture] ([VentureKey]), + CONSTRAINT [FK_VentureEntityOption_Entity] FOREIGN KEY ([EntityKey]) REFERENCES [Entity].[Entity] ([EntityKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureEntityOption_Key] ON [Entity].[VentureEntityOption] ([VentureEntityOptionKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Entity/Tables/VentureLocation.sql b/data/Entity.Database/Entity/Tables/VentureLocation.sql new file mode 100644 index 00000000..3ed939ca --- /dev/null +++ b/data/Entity.Database/Entity/Tables/VentureLocation.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[VentureLocation] ( + [VentureLocationId] INT IDENTITY (1, 1) CONSTRAINT [DF_VentureLocation_Id] NOT NULL, + [VentureLocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureLocation_Key] DEFAULT(NewId()) NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureLocation_VentureId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureLocation_LocationId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [LocationTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureLocation_LocationType] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureLocation_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_VentureLocation_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_VentureLocation_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_VentureLocation] PRIMARY KEY CLUSTERED ([VentureLocationId] ASC), + CONSTRAINT [FK_VentureLocation_Venture] FOREIGN KEY ([VentureKey]) REFERENCES [Entity].[Venture] ([VentureKey]), + CONSTRAINT [FK_VentureLocation_Location] FOREIGN KEY ([LocationKey]) REFERENCES [Entity].[Location] ([LocationKey]), + CONSTRAINT [FK_VentureLocation_LocationType] FOREIGN KEY ([LocationTypeKey]) REFERENCES [Entity].[LocationType] ([LocationTypeKey]), + CONSTRAINT [FK_VentureLocation_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureLocation_Key] ON [Entity].[VentureLocation] ([VentureLocationKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureLocation_All] ON [Entity].[VentureLocation] ([VentureKey] Asc, [LocationKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/VentureOption.sql b/data/Entity.Database/Entity/Tables/VentureOption.sql new file mode 100644 index 00000000..b7433ea4 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/VentureOption.sql @@ -0,0 +1,14 @@ +CREATE TABLE [Entity].[VentureOption] ( + [VentureOptionId] INT IDENTITY (1, 1) CONSTRAINT [DF_VentureOption_VentureOptionId] NOT NULL, + [VentureOptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureOption_VentureOptionKey] DEFAULT(NewId()) NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureOption_Entity] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [OptionKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureOption_Option] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_VentureOption_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_VentureOption_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_VentureOption] PRIMARY KEY CLUSTERED ([VentureOptionId] ASC), + CONSTRAINT [FK_VentureOption_Venture] FOREIGN KEY ([VentureKey]) REFERENCES [Entity].[Venture] ([VentureKey]), + CONSTRAINT [FK_VentureOption_Option] FOREIGN KEY ([OptionKey]) REFERENCES [Entity].[Option] ([OptionKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureOption_All] ON [Entity].[VentureOption] ([VentureKey] Asc, [OptionKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/VentureResource.sql b/data/Entity.Database/Entity/Tables/VentureResource.sql new file mode 100644 index 00000000..1e47a103 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/VentureResource.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[VentureResource] ( + [VentureResourceId] INT IDENTITY (1, 1) CONSTRAINT [DF_VentureResource_Id] NOT NULL, + [VentureResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureResource_Key] DEFAULT(NewId()) NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureResource_VentureId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ResourceKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureResource_ResourceId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ResourceTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureResource_ResourceTypeId] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureResource_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_VentureResource_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_VentureResource_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_VentureResource] PRIMARY KEY CLUSTERED ([VentureResourceId] ASC), + CONSTRAINT [FK_VentureResource_Resource] FOREIGN KEY ([ResourceKey]) REFERENCES [Entity].[Resource] ([ResourceKey]), + CONSTRAINT [FK_VentureResource_ResourceType] FOREIGN KEY ([ResourceTypeKey]) REFERENCES [Entity].[ResourceType] ([ResourceTypeKey]), + CONSTRAINT [FK_VentureResource_Venture] FOREIGN KEY ([VentureKey]) REFERENCES [Entity].[Venture] ([VentureKey]), + CONSTRAINT [FK_VentureResource_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureResource_Key] ON [Entity].[VentureResource] ([VentureResourceKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureResource_All] ON [Entity].[VentureResource] ([VentureKey] Asc, [ResourceKey] Asc) +GO diff --git a/data/Entity.Database/Entity/Tables/VentureSchedule.sql b/data/Entity.Database/Entity/Tables/VentureSchedule.sql new file mode 100644 index 00000000..2f6ded51 --- /dev/null +++ b/data/Entity.Database/Entity/Tables/VentureSchedule.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Entity].[VentureSchedule] ( + [VentureScheduleId] INT IDENTITY (1, 1) CONSTRAINT [DF_VentureSchedule_Id] NOT NULL, + [VentureScheduleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureSchedule_Key] DEFAULT(NewId()) NOT NULL, + [VentureKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureSchedule_VentureId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ScheduleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureSchedule_ScheduleId] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ScheduleTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureSchedule_ScheduleTypeId] DEFAULT('00000000-0000-0000-0000-000000000000') NULL, + [RecordStateKey] UNIQUEIDENTIFIER CONSTRAINT [DF_VentureSchedule_RecordState] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_VentureSchedule_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_VentureSchedule_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_VentureSchedule] PRIMARY KEY CLUSTERED ([VentureScheduleId] ASC), + CONSTRAINT [FK_VentureSchedule_Schedule] FOREIGN KEY ([ScheduleKey]) REFERENCES [Entity].[Schedule] ([ScheduleKey]), + CONSTRAINT [FK_VentureSchedule_ScheduleType] FOREIGN KEY ([ScheduleTypeKey]) REFERENCES [Entity].[ScheduleType] ([ScheduleTypeKey]), + CONSTRAINT [FK_VentureSchedule_Venture] FOREIGN KEY ([VentureKey]) REFERENCES [Entity].[Venture] ([VentureKey]), + CONSTRAINT [FK_VentureSchedule_RecordState] FOREIGN KEY ([RecordStateKey]) REFERENCES [Entity].[RecordState] ([RecordStateKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureSchedule_Key] ON [Entity].[VentureSchedule] ([VentureScheduleKey] Asc) +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_VentureSchedule_All] ON [Entity].[VentureSchedule] ([VentureKey] Asc, [ScheduleKey] Asc) +GO diff --git a/data/Entity.Database/EntityCode/Stored Procedures/AppointmentInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/AppointmentInfoDelete.sql new file mode 100644 index 00000000..912374c0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/AppointmentInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[AppointmentInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(AppointmentId, -1) From [Entity].[Appointment] P Where [AppointmentKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Appointment] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where AppointmentId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/AppointmentInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/AppointmentInfoSave.sql new file mode 100644 index 00000000..c4a587e0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/AppointmentInfoSave.sql @@ -0,0 +1,52 @@ +Create PROCEDURE [EntityCode].[AppointmentInfoSave] + @Id int, + @Key Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(200), + @SlotLocationKey Uniqueidentifier, + @SlotResourceKey Uniqueidentifier, + @BeginDate datetime, + @EndDate datetime +AS + -- Local variables + Declare @TimeRangeId As Int = -1 + Declare @TimeRangeKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + + -- Save Time + Select Top 1 @TimeRangeId = IsNull(TimeRangeId, @TimeRangeId), @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), [TimeRangeKey]) From [Entity].[TimeRange] TR Where BeginDate = @BeginDate And EndDate = @EndDate + -- Insert-only table + If (@TimeRangeId Is Null) Or (@TimeRangeId = -1) + Begin + Select @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRange] (TimeRangeKey, BeginDate, EndDate) + Values (@TimeRangeKey, @BeginDate, @EndDate) + Select @TimeRangeId = SCOPE_IDENTITY() + End + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(AppointmentKey, @Key) From [Entity].[Appointment] P Where P.[AppointmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(AppointmentId, -1) From [Entity].[Appointment] P Where [AppointmentKey] = @Key + -- Insert vs. Do Nothing + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert Appointment + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Appointment] (AppointmentKey, AppointmentName, AppointmentDescription, SlotLocationKey, SlotResourceKey, TimeRangeKey, RecordStateKey) + Values (@Key, @Name, @Description, NullIf(@SlotLocationKey, '00000000-0000-0000-0000-000000000000'), NullIf(@SlotResourceKey, '00000000-0000-0000-0000-000000000000'), + @TimeRangeKey, '00000000-0000-0000-0000-000000000000') + Select @Id = Scope_Identity() + End + Else + Begin + Update [Entity].[Appointment] + Set AppointmentName = @Name, + AppointmentDescription = @Description, + SlotLocationKey = NullIf(@SlotLocationKey, '00000000-0000-0000-0000-000000000000'), + SlotResourceKey = NullIf(@SlotResourceKey, '00000000-0000-0000-0000-000000000000'), + TimeRangeKey = @TimeRangeKey, + ModifiedDate = GETUTCDATE() + Where AppointmentId = @Id + End + + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/BusinessInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/BusinessInfoDelete.sql new file mode 100644 index 00000000..4e153788 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/BusinessInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[BusinessInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(BusinessId, -1) From [Entity].[Business] P Where [BusinessKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].Business + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where BusinessId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/BusinessInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/BusinessInfoSave.sql new file mode 100644 index 00000000..b8642dcc --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/BusinessInfoSave.sql @@ -0,0 +1,48 @@ +Create Procedure [EntityCode].[BusinessInfoSave] + @Id int, + @Key uniqueidentifier, + @Name nvarchar(50), + @TaxNumber nvarchar(50) +AS + -- Local variables + -- Initialize + Select @Key = IsNull(@Key, '00000000-0000-0000-0000-000000000000') + Select @Name = RTRIM(LTRIM(@Name)) + Select @TaxNumber = RTRIM(LTRIM(@TaxNumber)) + + -- Validate data that will be inserted/updated, and ensure basic values exist + If ((@Name <> '') Or (@TaxNumber <> '')) + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(BusinessKey, @Key) From [Entity].[Business] P Where P.[BusinessId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(BusinessId, -1) From [Entity].[Business] P Where [BusinessKey] = @Key + -- Insert vs Update + Begin Try + If (@Id Is Null) Or (@Id = -1) + Begin + -- Create main entity record + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Entity] (EntityKey) Values (@Key) + -- Create Business record + Insert Into [Entity].[Business] (BusinessKey, BusinessName, TaxNumber, RecordStateKey) + Values (@Key, @Name, @TaxNumber, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Create main entity record + Update P + Set P.BusinessName = @Name, + P.TaxNumber = @TaxNumber, + P.ModifiedDate = GetUTCDate() + From [Entity].[Business] P + Where P.BusinessId = @Id + End + End Try + Begin Catch + Exec [Activity].[ExceptionLogInsertByException]; + End Catch + End + + -- Return data + Select IsNull(@Id, -1) As [Id], IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityAppointmentDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityAppointmentDelete.sql new file mode 100644 index 00000000..f9429035 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityAppointmentDelete.sql @@ -0,0 +1,23 @@ +Create Procedure [EntityCode].[EntityAppointmentDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EntityAppointmentKey], @Key) From [Entity].[EntityAppointment] Where [EntityAppointmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EntityAppointmentId], -1) From [Entity].[EntityAppointment] Where [EntityAppointmentKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[EntityAppointment] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EntityAppointmentId = @Id + End + + End Try + Begin Catch + Exec [Activity].[ExceptionLogInsertByException]; + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityAppointmentSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityAppointmentSave.sql new file mode 100644 index 00000000..89a366a4 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityAppointmentSave.sql @@ -0,0 +1,71 @@ +Create PROCEDURE [EntityCode].[EntityAppointmentSave] + @Id Int, + @Key Uniqueidentifier, + @EntityKey Uniqueidentifier, + @AppointmentKey Uniqueidentifier, + @AppointmentName nvarchar(50), + @AppointmentDescription nvarchar(2000), + @BeginDate datetime, + @EndDate datetime +AS + -- Local variables + Declare @TimeRangeId As Int = -1 + Declare @TimeRangeKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + -- Initialize + Select @AppointmentName = RTRIM(LTRIM(@AppointmentName)) + Select @AppointmentDescription = RTRIM(LTRIM(@AppointmentDescription)) + -- Validate Data + If (@EntityKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Save Time + Select Top 1 @TimeRangeId = IsNull(TimeRangeId, @TimeRangeId), @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), [TimeRangeKey]) From [Entity].[TimeRange] TR Where BeginDate = @BeginDate And EndDate = @EndDate + -- Insert-only table + If (@TimeRangeId Is Null) Or (@TimeRangeId = -1) + Begin + Select @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRange] (TimeRangeKey, BeginDate, EndDate) + Values (@TimeRangeKey, @BeginDate, @EndDate) + Select @TimeRangeId = SCOPE_IDENTITY() + End + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EntityAppointmentKey], @Key), @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), AppointmentKey), + @EntityKey = IsNull(NullIf(@EntityKey, '00000000-0000-0000-0000-000000000000'), EntityKey) From [Entity].[EntityAppointment] Where [EntityAppointmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EntityAppointmentId], -1), @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), AppointmentKey), @EntityKey = IsNull(NullIf(@EntityKey, '00000000-0000-0000-0000-000000000000'), EntityKey) From [Entity].[EntityAppointment] Where [EntityAppointmentKey] = @Key + -- Appointment: Insert vs. Update + If (@AppointmentKey Is Null) Or (@AppointmentKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EntityAppointment + Select @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Appointment] (AppointmentKey, AppointmentName, AppointmentDescription, TimeRangeKey, SlotLocationKey, SlotResourceKey, RecordStateKey) + Values (@AppointmentKey, @AppointmentName, @AppointmentDescription, @TimeRangeKey, NULL, NULL, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Appointment + Update [Entity].[Appointment] + Set AppointmentName = IsNull(@AppointmentName, AppointmentName), + AppointmentDescription = IsNull(@AppointmentDescription, AppointmentDescription), + TimeRangeKey = IsNull(@TimeRangeKey, TimeRangeKey), + ModifiedDate = GetUtcDate() + Where AppointmentKey = @AppointmentKey + End + -- EntityAppointment: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert EntityAppointment + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EntityAppointment] (EntityAppointmentKey, EntityKey, AppointmentKey, RecordStateKey) + Values (@Key, @EntityKey, @AppointmentKey, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Appointment + Update [Entity].[EntityAppointment] + Set ModifiedDate = GetUtcDate() + Where EntityAppointmentKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityDetailDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityDetailDelete.sql new file mode 100644 index 00000000..08974cf1 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityDetailDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[EntityDetailDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(EntityDetailId, -1) From [Entity].[EntityDetail] P Where [EntityDetailKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[EntityDetail] + Where EntityDetailId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityDetailSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityDetailSave.sql new file mode 100644 index 00000000..bb6c7ac3 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityDetailSave.sql @@ -0,0 +1,41 @@ +Create PROCEDURE [EntityCode].[EntityDetailSave] + @Id Int, + @Key Uniqueidentifier, + @EntityKey Uniqueidentifier, + @DetailTypeKey Uniqueidentifier, + @DetailData nvarchar(1000) +AS + -- Initialize + Declare @DetailKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + -- First find match to flip to update if necessary + Select @Id = IsNull(ED.EntityDetailId, @Id), @Key = IsNull(ED.EntityDetailKey, @Key), @DetailKey = IsNull(ED.DetailKey, @DetailKey) + From [Entity].[EntityDetail] ED Join [Entity].[Detail] D On ED.DetailKey = D.DetailKey + Where ED.EntityKey = @EntityKey And D.DetailTypeKey = @DetailTypeKey + + -- Do nothing if bad data + If (@DetailTypeKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Insert vs Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Detail + Select @DetailKey = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Detail] (DetailKey, DetailTypeKey, DetailData) + Values (@DetailKey, @DetailTypeKey, @DetailData) + -- EntityDetail + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EntityDetail] (EntityDetailKey, EntityKey, DetailKey) + Values (@Key, @EntityKey, @DetailKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + Update [Entity].[Detail] + Set DetailData = @DetailData, + ModifiedDate = GetUTCDate() + Where DetailKey = @DetailKey + End + End + + -- Return ID + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityLocationDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityLocationDelete.sql new file mode 100644 index 00000000..9d97a748 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityLocationDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[EntityLocationDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EntityLocationKey], @Key) From [Entity].[EntityLocation] Where [EntityLocationId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EntityLocationId], -1) From [Entity].[EntityLocation] Where [EntityLocationKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[EntityLocation] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EntityLocationId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityLocationSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityLocationSave.sql new file mode 100644 index 00000000..ace108f0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityLocationSave.sql @@ -0,0 +1,26 @@ +Create PROCEDURE [EntityCode].[EntityLocationSave] + @Id Int, + @Key Uniqueidentifier, + @EntityKey Uniqueidentifier, + @LocationKey Uniqueidentifier, + @LocationTypeKey Uniqueidentifier = null +AS + -- Initialize + Select @LocationTypeKey = NullIf(@LocationTypeKey, '00000000-0000-0000-0000-000000000000') + -- Validate Data + If (@EntityKey <> '00000000-0000-0000-0000-000000000000' AND @LocationKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + Select Top 1 @Id = IsNull([EntityLocationId], -1), @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), [EntityLocationKey]) + From [Entity].[EntityLocation] Where [EntityKey] = @EntityKey AND [LocationKey] = @LocationKey + -- EntityLocation + If (@Id Is Null) Or (@Id = -1) + Begin + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EntityLocation] (EntityLocationKey, EntityKey, LocationKey, LocationTypeKey, RecordStateKey) + Values (@Key, @EntityKey, @LocationKey, @LocationTypeKey, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityOptionDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityOptionDelete.sql new file mode 100644 index 00000000..9053d4d6 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityOptionDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[EntityOptionDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(EntityOptionId, -1) From [Entity].[EntityOption] P Where [EntityOptionKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[EntityOption] + Where EntityOptionId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityOptionSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityOptionSave.sql new file mode 100644 index 00000000..b82085ae --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityOptionSave.sql @@ -0,0 +1,28 @@ +Create PROCEDURE [EntityCode].[EntityOptionSave] + @Id Int, + @Key Uniqueidentifier, + @EntityKey Uniqueidentifier, + @OptionKey Uniqueidentifier +AS + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EntityOptionKey], @Key) From [Entity].[EntityOption] Where [EntityOptionId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EntityOptionId], -1) From [Entity].[EntityOption] Where [EntityOptionKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EntityOption] (EntityOptionKey, EntityKey, OptionKey) + Values (@Key, @EntityKey, @OptionKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- EntityOption master + Update [Entity].[EntityOption] + Set OptionKey = @OptionKey, + ModifiedDate = GetUTCDate() + Where EntityOptionId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityTimeRecurringDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityTimeRecurringDelete.sql new file mode 100644 index 00000000..e46bdff1 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityTimeRecurringDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[EntityTimeRecurringDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EntityTimeRecurringKey], @Key) From [Entity].[EntityTimeRecurring] Where [EntityTimeRecurringId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EntityTimeRecurringId], -1) From [Entity].[EntityTimeRecurring] Where [EntityTimeRecurringKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[EntityTimeRecurring] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EntityTimeRecurringId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EntityTimeRecurringSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EntityTimeRecurringSave.sql new file mode 100644 index 00000000..83e39d7e --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EntityTimeRecurringSave.sql @@ -0,0 +1,54 @@ +Create PROCEDURE [EntityCode].[EntityTimeRecurringSave] + @Id Int, + @Key Uniqueidentifier, + @BeginDay int, + @EndDay int, + @BeginTime datetime, + @EndTime datetime, + @TimeTypeKey Uniqueidentifier, + @EntityKey Uniqueidentifier +AS + -- Local variables + Declare @TimeRecurringId As Int = -1 + Declare @TimeRecurringKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + + -- Validate Data + If (@EntityKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EntityTimeRecurringKey], @Key) From [Entity].[EntityTimeRecurring] Where [EntityTimeRecurringId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EntityTimeRecurringId], -1) From [Entity].[EntityTimeRecurring] Where [EntityTimeRecurringKey] = @Key + + -- TimeRecurring + Select Top 1 @TimeRecurringId = IsNull(TimeRecurringId, @TimeRecurringId), @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), [TimeRecurringKey]) From [Entity].[TimeRecurring] TR Where BeginDay = @BeginDay AND EndDay = @EndDay AND BeginTime = @BeginTime AND EndTime = @EndTime + -- TimeRecurring Insert only + If (@TimeRecurringId Is Null) Or (@TimeRecurringId = -1) + Begin + Select @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRecurring] (TimeRecurringKey, BeginDay, EndDay, BeginTime, EndTime) + Values (@TimeRecurringKey, @BeginDay, @EndDay, @BeginTime, @EndTime) + Select @TimeRecurringId = SCOPE_IDENTITY() + End + -- EntityTimeRecurring + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert EntityTimeRecurring + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EntityTimeRecurring] (EntityTimeRecurringKey, EntityKey, TimeRecurringKey, TimeTypeKey, RecordStateKey) + Values (@Key, @EntityKey, @TimeRecurringKey, NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update [EntityTimeRecurring] + Update [Entity].[EntityTimeRecurring] + Set EntityKey = IsNull(@EntityKey, EntityKey), + TimeRecurringKey = IsNull(@TimeRecurringKey, TimeRecurringKey), + TimeTypeKey = NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where EntityTimeRecurringKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventAppointmentDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventAppointmentDelete.sql new file mode 100644 index 00000000..f913afc0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventAppointmentDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[EventAppointmentDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventAppointmentKey], @Key) From [Entity].[EventAppointment] Where [EventAppointmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventAppointmentId], -1) From [Entity].[EventAppointment] Where [EventAppointmentKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[EventAppointment] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EventAppointmentId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventAppointmentSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventAppointmentSave.sql new file mode 100644 index 00000000..d586a83c --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventAppointmentSave.sql @@ -0,0 +1,71 @@ +Create PROCEDURE [EntityCode].[EventAppointmentSave] + @Id Int, + @Key Uniqueidentifier, + @EventKey Uniqueidentifier, + @AppointmentKey Uniqueidentifier, + @AppointmentName nvarchar(50), + @AppointmentDescription nvarchar(2000), + @BeginDate datetime, + @EndDate datetime +AS + -- Local variables + Declare @TimeRangeId As Int = -1 + Declare @TimeRangeKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + -- Initialize + Select @AppointmentName = RTRIM(LTRIM(@AppointmentName)) + Select @AppointmentDescription = RTRIM(LTRIM(@AppointmentDescription)) + -- Validate Data + If (@EventKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Save Time + Select Top 1 @TimeRangeId = IsNull(TimeRangeId, @TimeRangeId), @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), [TimeRangeKey]) From [Entity].[TimeRange] TR Where BeginDate = @BeginDate And EndDate = @EndDate + -- Insert-only table + If (@TimeRangeId Is Null) Or (@TimeRangeId = -1) + Begin + Select @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRange] (TimeRangeKey, BeginDate, EndDate) + Values (@TimeRangeKey, @BeginDate, @EndDate) + Select @TimeRangeId = SCOPE_IDENTITY() + End + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventAppointmentKey], @Key), @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), AppointmentKey), + @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventAppointment] Where [EventAppointmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventAppointmentId], -1), @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), AppointmentKey), @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventAppointment] Where [EventAppointmentKey] = @Key + -- Appointment: Insert vs. Update + If (@AppointmentKey Is Null) Or (@AppointmentKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EventAppointment + Select @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Appointment] (AppointmentKey, AppointmentName, AppointmentDescription, TimeRangeKey, SlotLocationKey, SlotResourceKey, RecordStateKey) + Values (@AppointmentKey, @AppointmentName, @AppointmentDescription, @TimeRangeKey, NULL, NULL, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Appointment + Update [Entity].[Appointment] + Set AppointmentName = IsNull(@AppointmentName, AppointmentName), + AppointmentDescription = IsNull(@AppointmentDescription, AppointmentDescription), + TimeRangeKey = IsNull(@TimeRangeKey, TimeRangeKey), + ModifiedDate = GetUtcDate() + Where AppointmentKey = @AppointmentKey + End + -- EventAppointment: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert EventAppointment + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EventAppointment] (EventAppointmentKey, EventKey, AppointmentKey, RecordStateKey) + Values (@Key, @EventKey, @AppointmentKey, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Appointment + Update [Entity].[EventAppointment] + Set ModifiedDate = GetUtcDate() + Where EventAppointmentKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventDetailDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventDetailDelete.sql new file mode 100644 index 00000000..03be17e5 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventDetailDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[EventDetailDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(EventDetailId, -1) From [Entity].[EventDetail] P Where [EventDetailKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[EventDetail] + Where EventDetailId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventDetailSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventDetailSave.sql new file mode 100644 index 00000000..18e53458 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventDetailSave.sql @@ -0,0 +1,42 @@ +Create PROCEDURE [EntityCode].[EventDetailSave] + @Id Int, + @Key Uniqueidentifier, + @EventKey Uniqueidentifier, + @DetailTypeKey Uniqueidentifier, + @DetailData nvarchar(1000) +AS + -- Initialize + Declare @DetailKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + -- First find match to flip to update if necessary + Select @Id = IsNull(ED.EventDetailId, @Id), @Key = IsNull(ED.EventDetailKey, @Key), @DetailKey = IsNull(ED.DetailKey, @DetailKey) + From [Entity].[EventDetail] ED Join [Entity].[Detail] D On ED.DetailKey = D.DetailKey + Where ED.EventKey = @EventKey And D.DetailTypeKey = @DetailTypeKey + + -- Do nothing if bad data + If (@DetailTypeKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Insert vs Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Detail + Select @DetailKey = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Detail] (DetailKey, DetailTypeKey, DetailData) + Values (@DetailKey, @DetailTypeKey, @DetailData) + -- EventDetail + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EventDetail] (EventDetailKey, EventKey, DetailKey) + Values (@Key, @EventKey, @DetailKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + Update [Entity].[Detail] + Set DetailData = @DetailData, + + ModifiedDate = GetUTCDate() + Where DetailKey = @DetailKey + End + End + + -- Return ID + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventEntityOptionDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventEntityOptionDelete.sql new file mode 100644 index 00000000..3b19a6d9 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventEntityOptionDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[EventEntityOptionDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(EventEntityOptionId, -1) From [Entity].[EventEntityOption] P Where [EventEntityOptionKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[EventEntityOption] + Where EventEntityOptionId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventEntityOptionSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventEntityOptionSave.sql new file mode 100644 index 00000000..9469fefc --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventEntityOptionSave.sql @@ -0,0 +1,30 @@ +Create PROCEDURE [EntityCode].[EventEntityOptionSave] + @Id Int, + @Key Uniqueidentifier, + @EventKey Uniqueidentifier, + @EntityKey Uniqueidentifier, + @OptionKey Uniqueidentifier +AS + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventEntityOptionKey], @Key) From [Entity].[EventEntityOption] Where [EventEntityOptionId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventEntityOptionId], -1) From [Entity].[EventEntityOption] Where [EventEntityOptionKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EventEntityOption] (EventEntityOptionKey, EventKey, EntityKey, OptionKey) + Values (@Key, @EventKey, @EntityKey, @OptionKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- EventEntityOption master + Update [Entity].[EventEntityOption] + Set OptionKey = @OptionKey, + + ModifiedDate = GetUTCDate() + Where EventEntityOptionId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventInfoDelete.sql new file mode 100644 index 00000000..6579f03a --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[EventInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(EventId, -1) From [Entity].[Event] P Where [EventKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Event] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EventId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventInfoSave.sql new file mode 100644 index 00000000..c2b235f8 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventInfoSave.sql @@ -0,0 +1,42 @@ +Create PROCEDURE [EntityCode].[EventInfoSave] + @Id Int, + @Key Uniqueidentifier, + @EventGroupKey Uniqueidentifier, + @EventTypeKey Uniqueidentifier, + @EventCreatorKey Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(200), + @Slogan nvarchar(50) +AS + -- Local variables + -- Initialize + Select @Name = RTRIM(LTRIM(@Name)) + Select @Description = RTRIM(LTRIM(@Description)) + Select @Slogan = RTRIM(LTRIM(@Slogan)) + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventKey], @Key) From [Entity].[Event] Where [EventId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventId], -1) From [Entity].[Event] Where [EventKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Event] (EventKey, EventGroupKey, EventTypeKey, EventCreatorKey, EventName, EventDescription, EventSlogan, RecordStateKey) + Values (@Key, @EventGroupKey, @EventTypeKey, @EventCreatorKey, @Name, @Description, @Slogan, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Event master + Update [Entity].[Event] + Set EventName = @Name, + EventDescription = @Description, + EventSlogan = @Slogan, + EventTypeKey = @EventTypeKey, + + ModifiedDate = GetUTCDate() + Where EventId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventLocationDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventLocationDelete.sql new file mode 100644 index 00000000..96fb95ba --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventLocationDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[EventLocationDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventLocationKey], @Key) From [Entity].[EventLocation] Where [EventLocationId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventLocationId], -1) From [Entity].[EventLocation] Where [EventLocationKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[EventLocation] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EventLocationId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventLocationSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventLocationSave.sql new file mode 100644 index 00000000..3cae1554 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventLocationSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[EventLocationSave] + @Id Int, + @Key Uniqueidentifier, + @EventKey Uniqueidentifier, + @EventName nvarchar(50), + @EventDescription nvarchar(2000), + @LocationKey Uniqueidentifier, + @LocationName nvarchar(50), + @LocationDescription nvarchar(2000), + @LocationTypeKey Uniqueidentifier +AS + -- Initialize + Select @LocationName = RTRIM(LTRIM(@LocationName)) + Select @LocationDescription = RTRIM(LTRIM(@LocationDescription)) + -- Validate Data + If (@EventKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventLocationKey], @Key), @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), LocationKey), + @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventLocation] Where [EventLocationId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventLocationId], -1), @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), LocationKey), @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventLocation] Where [EventLocationKey] = @Key + -- Event: Insert vs. Update + If (@EventKey Is Null) Or (@EventKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EventEvent + Select @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Event] (EventKey, EventName, EventDescription, RecordStateKey) + Values (@EventKey, @EventName, @EventDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Event + Update [Entity].[Event] + Set EventName = IsNull(@EventName, EventName), + EventDescription = IsNull(@EventDescription, EventDescription), + ModifiedDate = GetUtcDate() + Where EventKey = @EventKey + End + -- Location: Insert vs. Update + If (@LocationKey Is Null) Or (@LocationKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EventLocation + Select @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Location] (LocationKey, LocationName, LocationDescription, RecordStateKey) + Values (@LocationKey, @LocationName, @LocationDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Location + Update [Entity].[Location] + Set LocationName = IsNull(@LocationName, LocationName), + LocationDescription = IsNull(@LocationDescription, LocationDescription), + ModifiedDate = GetUtcDate() + Where LocationKey = @LocationKey + End + -- EventLocation: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert EventLocation + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EventLocation] (EventLocationKey, EventKey, LocationKey, LocationTypeKey, RecordStateKey) + Values (@Key, @EventKey, @LocationKey, NullIf(@LocationTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Location + Update [Entity].[EventLocation] + Set LocationTypeKey = NullIf(@LocationTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where EventLocationKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventOptionDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventOptionDelete.sql new file mode 100644 index 00000000..927f0116 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventOptionDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[EventOptionDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(EventOptionId, -1) From [Entity].[EventOption] P Where [EventOptionKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[EventOption] + Where EventOptionId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventOptionSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventOptionSave.sql new file mode 100644 index 00000000..2099d927 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventOptionSave.sql @@ -0,0 +1,29 @@ +Create PROCEDURE [EntityCode].[EventOptionSave] + @Id Int, + @Key Uniqueidentifier, + @EventKey Uniqueidentifier, + @OptionKey Uniqueidentifier +AS + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventOptionKey], @Key) From [Entity].[EventOption] Where [EventOptionId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventOptionId], -1) From [Entity].[EventOption] Where [EventOptionKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EventOption] (EventOptionKey, EventKey, OptionKey) + Values (@Key, @EventKey, @OptionKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- EventOption master + Update [Entity].[EventOption] + Set OptionKey = @OptionKey, + + ModifiedDate = GetUTCDate() + Where EventOptionId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventResourceDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventResourceDelete.sql new file mode 100644 index 00000000..8b22a4e0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventResourceDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[EventResourceDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventResourceKey], @Key) From [Entity].[EventResource] Where [EventResourceId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventResourceId], -1) From [Entity].[EventResource] Where [EventResourceKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[EventResource] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EventResourceId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventResourceSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventResourceSave.sql new file mode 100644 index 00000000..0536f3e7 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventResourceSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[EventResourceSave] + @Id Int, + @Key Uniqueidentifier, + @EventKey Uniqueidentifier, + @EventName nvarchar(50), + @EventDescription nvarchar(2000), + @ResourceKey Uniqueidentifier, + @ResourceName nvarchar(50), + @ResourceDescription nvarchar(2000), + @ResourceTypeKey Uniqueidentifier +AS + -- Initialize + Select @ResourceName = RTRIM(LTRIM(@ResourceName)) + Select @ResourceDescription = RTRIM(LTRIM(@ResourceDescription)) + -- Validate Data + If (@EventKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventResourceKey], @Key), @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), ResourceKey), + @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventResource] Where [EventResourceId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventResourceId], -1), @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), ResourceKey), @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventResource] Where [EventResourceKey] = @Key + -- Event: Insert vs. Update + If (@EventKey Is Null) Or (@EventKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EventEvent + Select @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Event] (EventKey, EventName, EventDescription, RecordStateKey) + Values (@EventKey, @EventName, @EventDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Event + Update [Entity].[Event] + Set EventName = IsNull(@EventName, EventName), + EventDescription = IsNull(@EventDescription, EventDescription), + ModifiedDate = GetUtcDate() + Where EventKey = @EventKey + End + -- Resource: Insert vs. Update + If (@ResourceKey Is Null) Or (@ResourceKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EventResource + Select @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Resource] (ResourceKey, ResourceName, ResourceDescription, RecordStateKey) + Values (@ResourceKey, @ResourceName, @ResourceDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Resource + Update [Entity].[Resource] + Set ResourceName = IsNull(@ResourceName, ResourceName), + ResourceDescription = IsNull(@ResourceDescription, ResourceDescription), + ModifiedDate = GetUtcDate() + Where ResourceKey = @ResourceKey + End + -- EventResource: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert EventResource + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EventResource] (EventResourceKey, EventKey, ResourceKey, ResourceTypeKey, RecordStateKey) + Values (@Key, @EventKey, @ResourceKey, NullIf(@ResourceTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Resource + Update [Entity].[EventResource] + Set ResourceTypeKey = NullIf(@ResourceTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where EventResourceKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventScheduleDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventScheduleDelete.sql new file mode 100644 index 00000000..48b7e300 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventScheduleDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[EventScheduleDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventScheduleKey], @Key) From [Entity].[EventSchedule] Where [EventScheduleId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventScheduleId], -1) From [Entity].[EventSchedule] Where [EventScheduleKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[EventSchedule] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where EventScheduleId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/EventScheduleSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/EventScheduleSave.sql new file mode 100644 index 00000000..1d14c1ab --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/EventScheduleSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[EventScheduleSave] + @Id Int, + @Key Uniqueidentifier, + @EventKey Uniqueidentifier, + @EventName nvarchar(50), + @EventDescription nvarchar(2000), + @ScheduleKey Uniqueidentifier, + @ScheduleName nvarchar(50), + @ScheduleDescription nvarchar(2000), + @ScheduleTypeKey Uniqueidentifier +AS + -- Initialize + Select @ScheduleName = RTRIM(LTRIM(@ScheduleName)) + Select @ScheduleDescription = RTRIM(LTRIM(@ScheduleDescription)) + -- Validate Data + If (@EventKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([EventScheduleKey], @Key), @ScheduleKey = IsNull(NullIf(@ScheduleKey, '00000000-0000-0000-0000-000000000000'), ScheduleKey), + @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventSchedule] Where [EventScheduleId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([EventScheduleId], -1), @ScheduleKey = IsNull(NullIf(@ScheduleKey, '00000000-0000-0000-0000-000000000000'), ScheduleKey), @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), EventKey) From [Entity].[EventSchedule] Where [EventScheduleKey] = @Key + -- Event: Insert vs. Update + If (@EventKey Is Null) Or (@EventKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EventEvent + Select @EventKey = IsNull(NullIf(@EventKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Event] (EventKey, EventName, EventDescription, RecordStateKey) + Values (@EventKey, @EventName, @EventDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Event + Update [Entity].[Event] + Set EventName = IsNull(@EventName, EventName), + EventDescription = IsNull(@EventDescription, EventDescription), + ModifiedDate = GetUtcDate() + Where EventKey = @EventKey + End + -- Schedule: Insert vs. Update + If (@ScheduleKey Is Null) Or (@ScheduleKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert EventSchedule + Select @ScheduleKey = IsNull(NullIf(@ScheduleKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Schedule] (ScheduleKey, ScheduleName, ScheduleDescription,RecordStateKey) + Values (@ScheduleKey, @ScheduleName, @ScheduleDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Schedule + Update [Entity].[Schedule] + Set ScheduleName = IsNull(@ScheduleName, ScheduleName), + ScheduleDescription = IsNull(@ScheduleDescription, ScheduleDescription), + ModifiedDate = GetUtcDate() + Where ScheduleKey = @ScheduleKey + End + -- EventSchedule: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert EventSchedule + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[EventSchedule] (EventScheduleKey, EventKey, ScheduleKey, ScheduleTypeKey, RecordStateKey) + Values (@Key, @EventKey, @ScheduleKey, NullIf(@ScheduleTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Schedule + Update [Entity].[EventSchedule] + Set ScheduleTypeKey = NullIf(@ScheduleTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where EventScheduleKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/GovernmentInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/GovernmentInfoDelete.sql new file mode 100644 index 00000000..7e65369a --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/GovernmentInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[GovernmentInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(GovernmentId, -1) From [Entity].[Government] P Where [GovernmentKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].Government + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where GovernmentId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/GovernmentInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/GovernmentInfoSave.sql new file mode 100644 index 00000000..436e2fcd --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/GovernmentInfoSave.sql @@ -0,0 +1,47 @@ +Create Procedure [EntityCode].[GovernmentInfoSave] + @Id int, + @Key uniqueidentifier, + @Name nvarchar(50) +AS + -- Initialize + Select @Name = RTRIM(LTRIM(@Name)) + + -- Validate data that will be inserted/updated, and ensure basic values exist + If (@Name <> '') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(GovernmentKey, @Key) From [Entity].[Government] P Where P.[GovernmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(GovernmentId, -1) From [Entity].[Government] P Where [GovernmentKey] = @Key + -- Insert vs Update + + Begin Try + If (@Id Is Null) Or (@Id = -1) + Begin + -- Create main entity record + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Entity] (EntityKey) Values (@Key) + -- Create Government record + Insert Into [Entity].[Government] (GovernmentKey, GovernmentName, RecordStateKey) + Values (@Key, @Name, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Create main entity record + Update P + Set P.GovernmentName = @Name, + P.ModifiedDate = GetUTCDate() + From [Entity].[Government] P + Where P.GovernmentId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End + + -- Return data + Select IsNull(@Id, -1) As [Id], IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ItemInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/ItemInfoDelete.sql new file mode 100644 index 00000000..d1586f21 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ItemInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[ItemInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ItemId, -1) From [Entity].[Item] P Where [ItemKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Item] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where ItemId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ItemInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/ItemInfoSave.sql new file mode 100644 index 00000000..82069b63 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ItemInfoSave.sql @@ -0,0 +1,37 @@ +Create PROCEDURE [EntityCode].[ItemInfoSave] + @Id Int, + @Key Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(200), + @ItemTypeKey Uniqueidentifier +AS + -- Local variables + -- Initialize + Select @Name = RTRIM(LTRIM(@Name)) + Select @Description = RTRIM(LTRIM(@Description)) + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([ItemKey], @Key) From [Entity].[Item] Where [ItemId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([ItemId], -1) From [Entity].[Item] Where [ItemKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Item] (ItemKey, ItemName, ItemDescription, ItemTypeKey, RecordStateKey) + Values (@Key, @Name, @Description, @ItemTypeKey, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Item master + Update [Entity].[Item] + Set ItemName = @Name, + ItemDescription = @Description, + ItemTypeKey = @ItemTypeKey, + + ModifiedDate = GetUTCDate() + Where ItemId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/LocationInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/LocationInfoDelete.sql new file mode 100644 index 00000000..9ece270f --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/LocationInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[LocationInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(LocationId, -1) From [Entity].[Location] P Where [LocationKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Location] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where LocationId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/LocationInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/LocationInfoSave.sql new file mode 100644 index 00000000..26587916 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/LocationInfoSave.sql @@ -0,0 +1,35 @@ +Create PROCEDURE [EntityCode].[LocationInfoSave] + @Id Int, + @Key Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(200) +AS + -- Local variables + -- Initialize + Select @Name = RTRIM(LTRIM(@Name)) + Select @Description = RTRIM(LTRIM(@Description)) + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([LocationKey], @Key) From [Entity].[Location] Where [LocationId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([LocationId], -1) From [Entity].[Location] Where [LocationKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Location] (LocationKey, LocationName, LocationDescription, RecordStateKey) + Values (@Key, @Name, @Description, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Location master + Update [Entity].[Location] + Set LocationName = @Name, + LocationDescription = @Description, + + ModifiedDate = GetUTCDate() + Where LocationId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/LocationTimeRecurringDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/LocationTimeRecurringDelete.sql new file mode 100644 index 00000000..02e6d118 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/LocationTimeRecurringDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[LocationTimeRecurringDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([LocationTimeRecurringKey], @Key) From [Entity].[LocationTimeRecurring] Where [LocationTimeRecurringId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([LocationTimeRecurringId], -1) From [Entity].[LocationTimeRecurring] Where [LocationTimeRecurringKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[LocationTimeRecurring] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where LocationTimeRecurringId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/LocationTimeRecurringSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/LocationTimeRecurringSave.sql new file mode 100644 index 00000000..80864600 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/LocationTimeRecurringSave.sql @@ -0,0 +1,54 @@ +Create PROCEDURE [EntityCode].[LocationTimeRecurringSave] + @Id Int, + @Key Uniqueidentifier, + @BeginDay int, + @EndDay int, + @BeginTime datetime, + @EndTime datetime, + @TimeTypeKey Uniqueidentifier, + @LocationKey Uniqueidentifier +AS + -- Local variables + Declare @TimeRecurringId As Int = -1 + Declare @TimeRecurringKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + + -- Validate Data + If (@LocationKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([LocationTimeRecurringKey], @Key) From [Entity].[LocationTimeRecurring] Where [LocationTimeRecurringId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([LocationTimeRecurringId], -1) From [Entity].[LocationTimeRecurring] Where [LocationTimeRecurringKey] = @Key + + -- TimeRecurring + Select Top 1 @TimeRecurringId = IsNull(TimeRecurringId, @TimeRecurringId), @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), [TimeRecurringKey]) From [Entity].[TimeRecurring] TR Where BeginDay = @BeginDay AND EndDay = @EndDay AND BeginTime = @BeginTime AND EndTime = @EndTime + -- TimeRecurring Insert only + If (@TimeRecurringId Is Null) Or (@TimeRecurringId = -1) + Begin + Select @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRecurring] (TimeRecurringKey, BeginDay, EndDay, BeginTime, EndTime) + Values (@TimeRecurringKey, @BeginDay, @EndDay, @BeginTime, @EndTime) + Select @TimeRecurringId = SCOPE_IDENTITY() + End + -- LocationTimeRecurring + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert LocationTimeRecurring + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[LocationTimeRecurring] (LocationTimeRecurringKey, LocationKey, TimeRecurringKey, TimeTypeKey, RecordStateKey) + Values (@Key, @LocationKey, @TimeRecurringKey, NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update [LocationTimeRecurring] + Update [Entity].[LocationTimeRecurring] + Set LocationKey = IsNull(@LocationKey, LocationKey), + TimeRecurringKey = IsNull(@TimeRecurringKey, TimeRecurringKey), + TimeTypeKey = NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where LocationTimeRecurringKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/PersonInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/PersonInfoDelete.sql new file mode 100644 index 00000000..fda6073d --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/PersonInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[PersonInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(PersonId, -1) From [Entity].[Person] P Where [PersonKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Person] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where PersonId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/PersonInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/PersonInfoSave.sql new file mode 100644 index 00000000..bf7d4310 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/PersonInfoSave.sql @@ -0,0 +1,65 @@ +Create Procedure [EntityCode].[PersonInfoSave] + @Id int, + @Key uniqueidentifier, + @FirstName nvarchar(50), + @MiddleName nvarchar(50), + @LastName nvarchar(50), + @BirthDate datetime, + @GenderCode nvarchar(10) +AS + -- Local variables + Declare @EntityId As Int = -1 + Declare @GenderId as Int = -1 + -- Initialize + Select @Id = IsNull(@Id, -1) + Select @Key = IsNull(@Key, '00000000-0000-0000-0000-000000000000') + Select @FirstName = RTRIM(LTRIM(@FirstName)) + Select @MiddleName = RTRIM(LTRIM(@MiddleName)) + Select @LastName = RTRIM(LTRIM(@LastName)) + + -- Validate data that will be inserted/updated, and ensure basic values exist + If ((@FirstName <> '') Or (@MiddleName <> '') Or (@LastName <> '')) + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(PersonKey, @Key) From [Entity].[Person] P Where [PersonId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(PersonId, -1) From [Entity].[Person] P Where [PersonKey] = @Key + -- Get extra data + Select @GenderId = IsNull(GenderId, -1) From [Entity].[Gender] Where GenderCode = @GenderCode + -- Insert vs Update + Begin Try + If (@Id Is Null) Or (@Id = -1) + Begin + -- Create main entity record + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Entity] (EntityKey) + Values (@Key) + Select @EntityId = SCOPE_IDENTITY() + -- Create person record + Insert Into [Entity].[Person] (PersonKey, FirstName, MiddleName, LastName, BirthDate, GenderId, RecordStateKey) + Values (@Key, @FirstName, @MiddleName, @LastName, @BirthDate, @GenderId, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Create main entity record + Update P + Set P.FirstName = @FirstName, + P.MiddleName = @MiddleName, + P.LastName = @LastName, + P.BirthDate = @BirthDate, + P.GenderId = @GenderId, + P.ModifiedDate = GetUTCDate() + From [Entity].[Person] P + Where P.PersonId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End + + -- Return data + Select IsNull(@Id, -1) As [Id], IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourceInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourceInfoDelete.sql new file mode 100644 index 00000000..07eb3eb4 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourceInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[ResourceInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ResourceId, -1) From [Entity].[Resource] P Where [ResourceKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Resource] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where ResourceId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourceInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourceInfoSave.sql new file mode 100644 index 00000000..8aba83d2 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourceInfoSave.sql @@ -0,0 +1,31 @@ +Create PROCEDURE [EntityCode].[ResourceInfoSave] + @Id Int, + @Key Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(2000) +AS + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([ResourceKey], @Key) From [Entity].[Resource] Where [ResourceId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([ResourceId], -1) From [Entity].[Resource] Where [ResourceKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert Resource + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Resource] (ResourceKey, RecordStateKey) + Values (@Key, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update + Update [Entity].[Resource] + Set ResourceName = IsNull(@Name, ResourceName), + ResourceDescription = IsNull(@Description, ResourceDescription), + + ModifiedDate = GetUtcDate() + Where ResourceId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourceItemDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourceItemDelete.sql new file mode 100644 index 00000000..b642a1d4 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourceItemDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[ResourceItemDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ResourceItemId, -1) From [Entity].[ResourceItem] P Where [ResourceItemKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[ResourceItem] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where ResourceItemId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourceItemSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourceItemSave.sql new file mode 100644 index 00000000..ff9e7604 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourceItemSave.sql @@ -0,0 +1,68 @@ +Create Procedure [EntityCode].[ResourceItemSave] + @Id int, + @Key uniqueidentifier, + @ResourceName nvarchar(50), + @ResourceDescription nvarchar(50), + @ItemName nvarchar(50), + @ItemDescription nvarchar(50) +AS + -- Local variables + Declare @ResourceKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + Declare @ItemKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + -- Initialize + Select @Key = IsNull(@Key, '00000000-0000-0000-0000-000000000000') + Select @ResourceName = RTRIM(LTRIM(@ResourceName)) + Select @ResourceDescription = RTRIM(LTRIM(@ResourceDescription)) + Select @ItemName = RTRIM(LTRIM(@ItemName)) + Select @ItemDescription = RTRIM(LTRIM(@ItemDescription)) + + -- Validate data that will be inserted/updated, and ensure basic values exist + If ((@ResourceName <> '') Or (@ItemName <> '')) + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(ResourceItemKey, @Key), @ResourceKey = ResourceKey, @ItemKey = ItemKey From [Entity].[ResourceItem] P Where [ResourceItemId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ResourceItemId, -1), @ResourceKey = ResourceKey, @ItemKey = ItemKey From [Entity].[ResourceItem] P Where [ResourceItemKey] = @Key + -- Insert vs Update + Begin Try + If (@Id Is Null) Or (@Id = -1) + Begin + -- Create main entity record + Select @ItemKey = IsNull(NullIf(@ItemKey, '00000000-0000-0000-0000-000000000000'), NewId()) + -- Create Item record + Insert Into [Entity].[Item] (ItemKey, ItemName, ItemDescription, RecordStateKey) + Values (@ItemKey, @ItemName, @ItemDescription, '00000000-0000-0000-0000-000000000000') + -- Create Resource record + Select @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Resource] (ResourceKey, ResourceName, ResourceDescription, RecordStateKey) + Values (@ResourceKey, @ResourceName, @ResourceDescription, '00000000-0000-0000-0000-000000000000') + -- Create ResourceItem record + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[ResourceItem] (ResourceItemKey, ResourceKey, ItemKey, RecordStateKey) + Values (@Key, @ResourceKey, @ItemKey, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Resource + Update P + Set P.ResourceName = @ResourceName, + P.ResourceDescription = @ResourceDescription, + P.ModifiedDate = GetUTCDate() + From [Entity].[Resource] P + Where P.ResourceKey = @ResourceKey + -- Item + Update P + Set P.ItemName = @ItemName, + P.ItemDescription = @ItemDescription, + P.ModifiedDate = GetUTCDate() + From [Entity].[Item] P + Where P.ItemKey = @ItemKey + End + End Try + Begin Catch + Exec [Activity].[ExceptionLogInsertByException]; + End Catch + End + + -- Return data + Select IsNull(@Id, -1) As [Id], IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourcePersonDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourcePersonDelete.sql new file mode 100644 index 00000000..7e497df5 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourcePersonDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[ResourcePersonDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ResourcePersonId, -1) From [Entity].[ResourcePerson] P Where [ResourcePersonKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[ResourcePerson] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where ResourcePersonId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourcePersonSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourcePersonSave.sql new file mode 100644 index 00000000..1bebf1c0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourcePersonSave.sql @@ -0,0 +1,71 @@ +Create Procedure [EntityCode].[ResourcePersonSave] + @Id int, + @Key uniqueidentifier, + @FirstName nvarchar(50), + @MiddleName nvarchar(50), + @LastName nvarchar(50), + @BirthDate datetime, + @GenderCode nvarchar(10) +AS + -- Local variables + Declare @ResourceKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + Declare @PersonKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + Declare @GenderId as Int = -1 + -- Initialize + Select @Key = IsNull(@Key, '00000000-0000-0000-0000-000000000000') + Select @FirstName = RTRIM(LTRIM(@FirstName)) + Select @MiddleName = RTRIM(LTRIM(@MiddleName)) + Select @LastName = RTRIM(LTRIM(@LastName)) + + -- Validate data that will be inserted/updated, and ensure basic values exist + If ((@FirstName <> '') Or (@MiddleName <> '') Or (@LastName <> '')) + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(ResourcePersonKey, @Key), @ResourceKey = ResourceKey, @PersonKey = PersonKey From [Entity].[ResourcePerson] P Where [ResourcePersonId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ResourcePersonId, -1), @ResourceKey = ResourceKey, @PersonKey = PersonKey From [Entity].[ResourcePerson] P Where [ResourcePersonKey] = @Key + -- Get extra data + Select @GenderId = IsNull(GenderId, -1) From [Entity].[Gender] Where GenderCode = @GenderCode + -- Insert vs Update + Begin Try + If (@Id Is Null) Or (@Id = -1) + Begin + -- Create main entity record + Select @PersonKey = IsNull(NullIf(@PersonKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Entity] (EntityKey) Values (@PersonKey) + -- Create person record + Insert Into [Entity].[Person] (PersonKey, FirstName, MiddleName, LastName, BirthDate, GenderId, RecordStateKey) + Values (@PersonKey, @FirstName, @MiddleName, @LastName, @BirthDate, @GenderId, '00000000-0000-0000-0000-000000000000') + -- Create Resource record + Select @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Resource] (ResourceKey, RecordStateKey) + Values (@ResourceKey, '00000000-0000-0000-0000-000000000000') + -- Create ResourcePerson record + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[ResourcePerson] (ResourcePersonKey, ResourceKey, PersonKey, RecordStateKey) + Values (@Key, @ResourceKey, @PersonKey, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Create main entity record + Update P + Set P.FirstName = @FirstName, + P.MiddleName = @MiddleName, + P.LastName = @LastName, + P.BirthDate = @BirthDate, + P.GenderId = @GenderId, + P.ModifiedDate = GetUTCDate() + From [Entity].[Person] P + Where P.PersonKey = @PersonKey + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End + + -- Return data + Select IsNull(@Id, -1) As [Id], IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourceTimeRecurringDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourceTimeRecurringDelete.sql new file mode 100644 index 00000000..158203fc --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourceTimeRecurringDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[ResourceTimeRecurringDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([ResourceTimeRecurringKey], @Key) From [Entity].[ResourceTimeRecurring] Where [ResourceTimeRecurringId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([ResourceTimeRecurringId], -1) From [Entity].[ResourceTimeRecurring] Where [ResourceTimeRecurringKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[ResourceTimeRecurring] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where ResourceTimeRecurringId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ResourceTimeRecurringSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/ResourceTimeRecurringSave.sql new file mode 100644 index 00000000..0eb51e6f --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ResourceTimeRecurringSave.sql @@ -0,0 +1,69 @@ +Create PROCEDURE [EntityCode].[ResourceTimeRecurringSave] + @Id Int, + @Key Uniqueidentifier, + @BeginDay int, + @EndDay int, + @BeginTime datetime, + @EndTime datetime, + @TimeTypeKey Uniqueidentifier, + @ResourceKey Uniqueidentifier, + @ResourceName nvarchar(50), + @ResourceDescription nvarchar(2000) +AS + -- Local variables + Declare @TimeRecurringId As Int = -1 + Declare @TimeRecurringKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([ResourceTimeRecurringKey], @Key) From [Entity].[ResourceTimeRecurring] Where [ResourceTimeRecurringId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([ResourceTimeRecurringId], -1) From [Entity].[ResourceTimeRecurring] Where [ResourceTimeRecurringKey] = @Key + + -- TimeRecurring + Select Top 1 @TimeRecurringId = IsNull(TimeRecurringId, @TimeRecurringId), @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), [TimeRecurringKey]) From [Entity].[TimeRecurring] TR Where BeginDay = @BeginDay AND EndDay = @EndDay AND BeginTime = @BeginTime AND EndTime = @EndTime + If (@TimeRecurringId Is Null) Or (@TimeRecurringId = -1) + Begin + Select @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRecurring] (TimeRecurringKey, BeginDay, EndDay, BeginTime, EndTime) + Values (@TimeRecurringKey, @BeginDay, @EndDay, @BeginTime, @EndTime) + Select @TimeRecurringId = SCOPE_IDENTITY() + End + + -- Resource + If (@ResourceKey Is Null) Or (@ResourceKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert Resource + Select @ResourceKey = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Resource] (ResourceKey, ResourceName, ResourceDescription, RecordStateKey) + Values (@Key, @ResourceName, @ResourceDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Resource + Update [Entity].[Resource] + Set ResourceName = IsNull(@ResourceName, ResourceName), + ResourceDescription = IsNull(@ResourceDescription, ResourceDescription), + ModifiedDate = GetUtcDate() + Where ResourceKey = @ResourceKey + End + -- ResourceTimeRecurring + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert ResourceTimeRecurring + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[ResourceTimeRecurring] (ResourceTimeRecurringKey, ResourceKey, TimeRecurringKey, TimeTypeKey, RecordStateKey) + Values (@Key, @ResourceKey, @TimeRecurringKey, NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update [ResourceTimeRecurring] + Update [Entity].[ResourceTimeRecurring] + Set ResourceKey = IsNull(@ResourceKey, ResourceKey), + TimeRecurringKey = IsNull(@TimeRecurringKey, TimeRecurringKey), + TimeTypeKey = NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where ResourceTimeRecurringKey = @Key + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ScheduleInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleInfoDelete.sql new file mode 100644 index 00000000..f437787d --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[ScheduleInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ScheduleId, -1) From [Entity].[Schedule] P Where [ScheduleKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Schedule] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where ScheduleId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ScheduleInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleInfoSave.sql new file mode 100644 index 00000000..afc876c4 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleInfoSave.sql @@ -0,0 +1,31 @@ +Create PROCEDURE [EntityCode].[ScheduleInfoSave] + @Id Int, + @Key Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(2000) +AS + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([ScheduleKey], @Key) From [Entity].[Schedule] Where [ScheduleId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([ScheduleId], -1) From [Entity].[Schedule] Where [ScheduleKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert Schedule + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Schedule] (ScheduleKey, RecordStateKey) + Values (@Key, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update + Update [Entity].[Schedule] + Set ScheduleName = IsNull(@Name, ScheduleName), + ScheduleDescription = IsNull(@Description, ScheduleDescription), + + ModifiedDate = GetUtcDate() + Where ScheduleId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ScheduleSlotDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleSlotDelete.sql new file mode 100644 index 00000000..ea984bfa --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleSlotDelete.sql @@ -0,0 +1,19 @@ +Create Procedure [EntityCode].[ScheduleSlotDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(ScheduleSlotId, -1) From [Entity].[ScheduleSlot] P Where [ScheduleSlotKey] = @Key + If (@Id <> -1) + Begin + Delete From [Entity].[ScheduleSlot] + Where ScheduleSlotId = @Id + End + + End Try + Begin Catch + Exec [Activity].[ExceptionLogInsertByException]; + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/ScheduleSlotSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleSlotSave.sql new file mode 100644 index 00000000..fb480d86 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/ScheduleSlotSave.sql @@ -0,0 +1,20 @@ +Create PROCEDURE [EntityCode].[ScheduleSlotSave] + @Id Int, + @Key Uniqueidentifier, + @ScheduleKey Uniqueidentifier, + @SlotKey Uniqueidentifier +AS + + -- Pull by unique key + Select Top 1 @Id = IsNull([ScheduleSlotId], -1), @Key = IsNull([ScheduleSlotKey], @Key) From [Entity].[ScheduleSlot] Where [ScheduleKey] = @ScheduleKey And [SlotKey] = @SlotKey + -- Insert Only + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert Schedule + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[ScheduleSlot] (ScheduleSlotKey, ScheduleKey, SlotKey) + Values (@Key, @ScheduleKey, @SlotKey) + Select @Id = SCOPE_IDENTITY() + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotInfoDelete.sql new file mode 100644 index 00000000..00faaf17 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[SlotInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(SlotId, -1) From [Entity].[Slot] P Where [SlotKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Slot] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where SlotId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotInfoSave.sql new file mode 100644 index 00000000..33e47d6e --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotInfoSave.sql @@ -0,0 +1,29 @@ +Create PROCEDURE [EntityCode].[SlotInfoSave] + @Id Int, + @Key Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(2000) +AS + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([SlotKey], @Key) From [Entity].[Slot] Where [SlotId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([SlotId], -1) From [Entity].[Slot] Where [SlotKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert Slot + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Slot] (SlotKey, SlotName, SlotDescription, RecordStateKey) + Values (@Key, @Name, @Description, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Slot + Update [Entity].[Slot] + Set SlotName = IsNull(@Name, SlotName), + SlotDescription = IsNull(@Description, SlotDescription), + ModifiedDate = GetUtcDate() + Where SlotKey = @Key + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotLocationDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotLocationDelete.sql new file mode 100644 index 00000000..bc8c8a1a --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotLocationDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[SlotLocationDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(SlotId, -1) From [Entity].[Slot] P Where [SlotKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[SlotLocation] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where SlotLocationId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotLocationSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotLocationSave.sql new file mode 100644 index 00000000..02ea1401 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotLocationSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[SlotLocationSave] + @Id Int, + @Key Uniqueidentifier, + @SlotKey Uniqueidentifier, + @SlotName nvarchar(50), + @SlotDescription nvarchar(2000), + @LocationKey Uniqueidentifier, + @LocationName nvarchar(50), + @LocationDescription nvarchar(2000), + @LocationTypeKey Uniqueidentifier +AS + -- Initialize + Select @LocationName = RTRIM(LTRIM(@LocationName)) + Select @LocationDescription = RTRIM(LTRIM(@LocationDescription)) + -- Validate Data + If (@SlotKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([SlotLocationKey], @Key), @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), LocationKey), + @SlotKey = IsNull(NullIf(@SlotKey, '00000000-0000-0000-0000-000000000000'), SlotKey) From [Entity].[SlotLocation] Where [SlotLocationId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([SlotLocationId], -1), @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), LocationKey), @SlotKey = IsNull(NullIf(@SlotKey, '00000000-0000-0000-0000-000000000000'), SlotKey) From [Entity].[SlotLocation] Where [SlotLocationKey] = @Key + -- Slot: Insert vs. Update + If (@SlotKey Is Null) Or (@SlotKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert SlotSlot + Select @SlotKey = IsNull(NullIf(@SlotKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Slot] (SlotKey, SlotName, SlotDescription, RecordStateKey) + Values (@SlotKey, @SlotName, @SlotDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Slot + Update [Entity].[Slot] + Set SlotName = IsNull(@SlotName, SlotName), + SlotDescription = IsNull(@SlotDescription, SlotDescription), + ModifiedDate = GetUtcDate() + Where SlotKey = @SlotKey + End + -- Location: Insert vs. Update + If (@LocationKey Is Null) Or (@LocationKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert SlotLocation + Select @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Location] (LocationKey, LocationName, LocationDescription, RecordStateKey) + Values (@LocationKey, @LocationName, @LocationDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Location + Update [Entity].[Location] + Set LocationName = IsNull(@LocationName, LocationName), + LocationDescription = IsNull(@LocationDescription, LocationDescription), + ModifiedDate = GetUtcDate() + Where LocationKey = @LocationKey + End + -- SlotLocation: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert SlotLocation + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[SlotLocation] (SlotLocationKey, SlotKey, LocationKey, LocationTypeKey, RecordStateKey) + Values (@Key, @SlotKey, @LocationKey, NullIf(@LocationTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Location + Update [Entity].[SlotLocation] + Set LocationTypeKey = NullIf(@LocationTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where SlotLocationKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotResourceDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotResourceDelete.sql new file mode 100644 index 00000000..0bcaa745 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotResourceDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[SlotResourceDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(SlotId, -1) From [Entity].[Slot] P Where [SlotKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[SlotResource] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where SlotResourceId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotResourceSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotResourceSave.sql new file mode 100644 index 00000000..d8772dcc --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotResourceSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[SlotResourceSave] + @Id Int, + @Key Uniqueidentifier, + @SlotKey Uniqueidentifier, + @SlotName nvarchar(50), + @SlotDescription nvarchar(2000), + @ResourceKey Uniqueidentifier, + @ResourceName nvarchar(50), + @ResourceDescription nvarchar(2000), + @ResourceTypeKey Uniqueidentifier +AS + -- Initialize + Select @ResourceName = RTRIM(LTRIM(@ResourceName)) + Select @ResourceDescription = RTRIM(LTRIM(@ResourceDescription)) + -- Validate Data + If (@SlotKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([SlotResourceKey], @Key), @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), ResourceKey), + @SlotKey = IsNull(NullIf(@SlotKey, '00000000-0000-0000-0000-000000000000'), SlotKey) From [Entity].[SlotResource] Where [SlotResourceId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([SlotResourceId], -1), @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), ResourceKey), @SlotKey = IsNull(NullIf(@SlotKey, '00000000-0000-0000-0000-000000000000'), SlotKey) From [Entity].[SlotResource] Where [SlotResourceKey] = @Key + -- Slot: Insert vs. Update + If (@SlotKey Is Null) Or (@SlotKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert SlotSlot + Select @SlotKey = IsNull(NullIf(@SlotKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Slot] (SlotKey, SlotName, SlotDescription, RecordStateKey) + Values (@SlotKey, @SlotName, @SlotDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Slot + Update [Entity].[Slot] + Set SlotName = IsNull(@SlotName, SlotName), + SlotDescription = IsNull(@SlotDescription, SlotDescription), + ModifiedDate = GetUtcDate() + Where SlotKey = @SlotKey + End + -- Resource: Insert vs. Update + If (@ResourceKey Is Null) Or (@ResourceKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert SlotResource + Select @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Resource] (ResourceKey, ResourceName, ResourceDescription, RecordStateKey) + Values (@ResourceKey, @ResourceName, @ResourceDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Resource + Update [Entity].[Resource] + Set ResourceName = IsNull(@ResourceName, ResourceName), + ResourceDescription = IsNull(@ResourceDescription, ResourceDescription), + ModifiedDate = GetUtcDate() + Where ResourceKey = @ResourceKey + End + -- SlotResource: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert SlotResource + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[SlotResource] (SlotResourceKey, SlotKey, ResourceKey, ResourceTypeKey, RecordStateKey) + Values (@Key, @SlotKey, @ResourceKey, NullIf(@ResourceTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Resource + Update [Entity].[SlotResource] + Set ResourceTypeKey = NullIf(@ResourceTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where SlotResourceKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRangeDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRangeDelete.sql new file mode 100644 index 00000000..ceec3e47 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRangeDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[SlotTimeRangeDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(SlotId, -1) From [Entity].[Slot] P Where [SlotKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[SlotTimeRange] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where SlotTimeRangeId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRangeSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRangeSave.sql new file mode 100644 index 00000000..9456afec --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRangeSave.sql @@ -0,0 +1,67 @@ +Create PROCEDURE [EntityCode].[SlotTimeRangeSave] + @Id Int, + @Key Uniqueidentifier, + @SlotKey Uniqueidentifier, + @SlotName nvarchar(50), + @SlotDescription nvarchar(2000), + @BeginDate datetime, + @EndDate datetime, + @TimeTypeKey Uniqueidentifier +AS + -- Local variables + Declare @TimeRangeId As Int = -1 + Declare @TimeRangeKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), [SlotTimeRangeKey]) From [Entity].[SlotTimeRange] Where [SlotTimeRangeId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([SlotTimeRangeId], -1) From [Entity].[SlotTimeRange] Where [SlotTimeRangeKey] = @Key + + -- Save Time + Select Top 1 @TimeRangeId = IsNull(TimeRangeId, @TimeRangeId), @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), [TimeRangeKey]) From [Entity].[TimeRange] TR Where BeginDate = @BeginDate And EndDate = @EndDate + -- Insert-only table + If (@TimeRangeId Is Null) Or (@TimeRangeId = -1) + Begin + Select @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRange] (TimeRangeKey, BeginDate, EndDate) + Values (@TimeRangeKey, @BeginDate, @EndDate) + Select @TimeRangeId = SCOPE_IDENTITY() + End + + -- Slot + If (@SlotKey Is Null) Or (@SlotKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert Slot + Select @SlotKey = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Slot] (SlotKey, SlotName, SlotDescription, RecordStateKey) + Values (@Key, @SlotName, @SlotDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Slot + Update [Entity].[Slot] + Set SlotName = IsNull(@SlotName, SlotName), + SlotDescription = IsNull(@SlotDescription, SlotDescription), + ModifiedDate = GetUtcDate() + Where SlotKey = @SlotKey + End + -- SlotTimeRange + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert SlotTimeRange + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[SlotTimeRange] (SlotTimeRangeKey, SlotKey, TimeRangeKey, TimeTypeKey, RecordStateKey) + Values (@Key, @SlotKey, @TimeRangeKey, NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update [SlotTimeRange] + Update [Entity].[SlotTimeRange] + Set TimeRangeKey = IsNull(@TimeRangeKey, TimeRangeKey), + TimeTypeKey = NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where SlotTimeRangeKey = @Key + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRecurringDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRecurringDelete.sql new file mode 100644 index 00000000..026b9177 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRecurringDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[SlotTimeRecurringDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(SlotId, -1) From [Entity].[Slot] P Where [SlotKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[SlotTimeRecurring] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where SlotTimeRecurringId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRecurringSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRecurringSave.sql new file mode 100644 index 00000000..dd72ab2f --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/SlotTimeRecurringSave.sql @@ -0,0 +1,68 @@ +Create PROCEDURE [EntityCode].[SlotTimeRecurringSave] + @Id Int, + @Key Uniqueidentifier, + @BeginDay int, + @EndDay int, + @BeginTime datetime, + @EndTime datetime, + @TimeTypeKey Uniqueidentifier, + @TimeCycleKey Uniqueidentifier, + @SlotKey Uniqueidentifier, + @SlotName nvarchar(50), + @SlotDescription nvarchar(2000) +AS + -- Local variables + Declare @TimeRecurringId As Int = -1 + Declare @TimeRecurringKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), [SlotTimeRecurringKey]) From [Entity].[SlotTimeRecurring] Where [SlotTimeRecurringId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([SlotTimeRecurringId], -1) From [Entity].[SlotTimeRecurring] Where [SlotTimeRecurringKey] = @Key + -- TimeRecurring + Select Top 1 @TimeRecurringId = IsNull(TimeRecurringId, @TimeRecurringId), @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), [TimeRecurringKey]) From [Entity].[TimeRecurring] TR Where BeginDay = @BeginDay AND EndDay = @EndDay AND BeginTime = @BeginTime AND EndTime = @EndTime AND TimeCycleKey = @TimeCycleKey + If (@TimeRecurringId Is Null) Or (@TimeRecurringId = -1) + Begin + Select @TimeRecurringKey = IsNull(NullIf(@TimeRecurringKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRecurring] (TimeRecurringKey, BeginDay, EndDay, BeginTime, EndTime, TimeCycleKey) + Values (@TimeRecurringKey, @BeginDay, @EndDay, @BeginTime, @EndTime, @TimeCycleKey) + Select @TimeRecurringId = SCOPE_IDENTITY() + End + -- Slot + If (@SlotKey Is Null) Or (@SlotKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert Slot + Select @SlotKey = IsNull(NullIf(@SlotKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Slot] (SlotKey, SlotName, SlotDescription, RecordStateKey) + Values (@SlotKey, @SlotName, @SlotDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Slot + Update [Entity].[Slot] + Set SlotName = IsNull(@SlotName, SlotName), + SlotDescription = IsNull(@SlotDescription, SlotDescription), + ModifiedDate = GetUtcDate() + Where SlotKey = @SlotKey + End + -- SlotTimeRecurring + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert SlotTimeRecurring + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[SlotTimeRecurring] (SlotTimeRecurringKey, SlotKey, TimeRecurringKey, TimeTypeKey, RecordStateKey) + Values (@Key, @SlotKey, @TimeRecurringKey, NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update [SlotTimeRecurring] + Update [Entity].[SlotTimeRecurring] + Set SlotKey = IsNull(@SlotKey, SlotKey), + TimeRecurringKey = IsNull(@TimeRecurringKey, TimeRecurringKey), + TimeTypeKey = NullIf(@TimeTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where SlotTimeRecurringKey = @Key + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureAppointmentDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureAppointmentDelete.sql new file mode 100644 index 00000000..c360c74b --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureAppointmentDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[VentureAppointmentDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureAppointmentKey], @Key) From [Entity].[VentureAppointment] Where [VentureAppointmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureAppointmentId], -1) From [Entity].[VentureAppointment] Where [VentureAppointmentKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[VentureAppointment] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where VentureAppointmentId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureAppointmentSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureAppointmentSave.sql new file mode 100644 index 00000000..4b03cf6d --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureAppointmentSave.sql @@ -0,0 +1,71 @@ +Create PROCEDURE [EntityCode].[VentureAppointmentSave] + @Id Int, + @Key Uniqueidentifier, + @VentureKey Uniqueidentifier, + @AppointmentKey Uniqueidentifier, + @AppointmentName nvarchar(50), + @AppointmentDescription nvarchar(2000), + @BeginDate datetime, + @EndDate datetime +AS + -- Local variables + Declare @TimeRangeId As Int = -1 + Declare @TimeRangeKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + -- Initialize + Select @AppointmentName = RTRIM(LTRIM(@AppointmentName)) + Select @AppointmentDescription = RTRIM(LTRIM(@AppointmentDescription)) + -- Validate Data + If (@VentureKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Save Time + Select Top 1 @TimeRangeId = IsNull(TimeRangeId, @TimeRangeId), @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), [TimeRangeKey]) From [Entity].[TimeRange] TR Where BeginDate = @BeginDate And EndDate = @EndDate + -- Insert-only table + If (@TimeRangeId Is Null) Or (@TimeRangeId = -1) + Begin + Select @TimeRangeKey = IsNull(NullIf(@TimeRangeKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[TimeRange] (TimeRangeKey, BeginDate, EndDate) + Values (@TimeRangeKey, @BeginDate, @EndDate) + Select @TimeRangeId = SCOPE_IDENTITY() + End + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureAppointmentKey], @Key), @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), AppointmentKey), + @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureAppointment] Where [VentureAppointmentId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureAppointmentId], -1), @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), AppointmentKey), @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureAppointment] Where [VentureAppointmentKey] = @Key + -- Appointment: Insert vs. Update + If (@AppointmentKey Is Null) Or (@AppointmentKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert VentureAppointment + Select @AppointmentKey = IsNull(NullIf(@AppointmentKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Appointment] (AppointmentKey, AppointmentName, AppointmentDescription, TimeRangeKey, SlotLocationKey, SlotResourceKey, RecordStateKey) + Values (@AppointmentKey, @AppointmentName, @AppointmentDescription, @TimeRangeKey, NULL, NULL, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Appointment + Update [Entity].[Appointment] + Set AppointmentName = IsNull(@AppointmentName, AppointmentName), + AppointmentDescription = IsNull(@AppointmentDescription, AppointmentDescription), + TimeRangeKey = IsNull(@TimeRangeKey, TimeRangeKey), + ModifiedDate = GetUtcDate() + Where AppointmentKey = @AppointmentKey + End + -- VentureAppointment: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert VentureAppointment + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[VentureAppointment] (VentureAppointmentKey, VentureKey, AppointmentKey, RecordStateKey) + Values (@Key, @VentureKey, @AppointmentKey, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Appointment + Update [Entity].[VentureAppointment] + Set ModifiedDate = GetUtcDate() + Where VentureAppointmentKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureDetailDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureDetailDelete.sql new file mode 100644 index 00000000..cdcba80c --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureDetailDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[VentureDetailDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(VentureDetailId, -1) From [Entity].[VentureDetail] P Where [VentureDetailKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[VentureDetail] + Where VentureDetailId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureDetailSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureDetailSave.sql new file mode 100644 index 00000000..0fa90e1b --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureDetailSave.sql @@ -0,0 +1,42 @@ +Create PROCEDURE [EntityCode].[VentureDetailSave] + @Id Int, + @Key Uniqueidentifier, + @VentureKey Uniqueidentifier, + @DetailTypeKey Uniqueidentifier, + @DetailData nvarchar(1000) +AS + -- Initialize + Declare @DetailKey As Uniqueidentifier = '00000000-0000-0000-0000-000000000000' + -- First find match to flip to update if necessary + Select @Id = IsNull(ED.VentureDetailId, @Id), @Key = IsNull(ED.VentureDetailKey, @Key), @DetailKey = IsNull(ED.DetailKey, @DetailKey) + From [Entity].[VentureDetail] ED Join [Entity].[Detail] D On ED.DetailKey = D.DetailKey + Where ED.VentureKey = @VentureKey And D.DetailTypeKey = @DetailTypeKey + + -- Do nothing if bad data + If (@DetailTypeKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Insert vs Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Detail + Select @DetailKey = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Detail] (DetailKey, DetailTypeKey, DetailData) + Values (@DetailKey, @DetailTypeKey, @DetailData) + -- VentureDetail + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[VentureDetail] (VentureDetailKey, VentureKey, DetailKey) + Values (@Key, @VentureKey, @DetailKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + Update [Entity].[Detail] + Set DetailData = @DetailData, + + ModifiedDate = GetUTCDate() + Where DetailKey = @DetailKey + End + End + + -- Return ID + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureEntityOptionDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureEntityOptionDelete.sql new file mode 100644 index 00000000..c33c8f05 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureEntityOptionDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[VentureEntityOptionDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(VentureEntityOptionId, -1) From [Entity].[VentureEntityOption] P Where [VentureEntityOptionKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[VentureEntityOption] + Where VentureEntityOptionId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureEntityOptionSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureEntityOptionSave.sql new file mode 100644 index 00000000..dc446074 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureEntityOptionSave.sql @@ -0,0 +1,30 @@ +Create PROCEDURE [EntityCode].[VentureEntityOptionSave] + @Id Int, + @Key Uniqueidentifier, + @VentureKey Uniqueidentifier, + @EntityKey Uniqueidentifier, + @OptionKey Uniqueidentifier +AS + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureEntityOptionKey], @Key) From [Entity].[VentureEntityOption] Where [VentureEntityOptionId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureEntityOptionId], -1) From [Entity].[VentureEntityOption] Where [VentureEntityOptionKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[VentureEntityOption] (VentureEntityOptionKey, VentureKey, EntityKey, OptionKey) + Values (@Key, @VentureKey, @EntityKey, @OptionKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- VentureEntityOption master + Update [Entity].[VentureEntityOption] + Set OptionKey = @OptionKey, + + ModifiedDate = GetUTCDate() + Where VentureEntityOptionId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureInfoDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureInfoDelete.sql new file mode 100644 index 00000000..107e4905 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureInfoDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[VentureInfoDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(VentureId, -1) From [Entity].[Venture] P Where [VentureKey] = @Key + If (@Id <> -1) + Begin + Update [Entity].[Venture] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where VentureId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureInfoSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureInfoSave.sql new file mode 100644 index 00000000..0058b0c6 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureInfoSave.sql @@ -0,0 +1,41 @@ +Create PROCEDURE [EntityCode].[VentureInfoSave] + @Id Int, + @Key Uniqueidentifier, + @VentureGroupKey Uniqueidentifier, + @VentureTypeKey Uniqueidentifier, + @Name nvarchar(50), + @Description nvarchar(200), + @Slogan nvarchar(50) +AS + -- Local variables + -- Initialize + Select @Name = RTRIM(LTRIM(@Name)) + Select @Description = RTRIM(LTRIM(@Description)) + Select @Slogan = RTRIM(LTRIM(@Slogan)) + + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureKey], @Key) From [Entity].[Venture] Where [VentureId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureId], -1) From [Entity].[Venture] Where [VentureKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Venture] (VentureKey, VentureGroupKey, VentureTypeKey, VentureName, VentureDescription, VentureSlogan, RecordStateKey) + Values (@Key, @VentureGroupKey, @VentureTypeKey, @Name, @Description, @Slogan, '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Venture master + Update [Entity].[Venture] + Set VentureName = @Name, + VentureDescription = @Description, + VentureSlogan = @Slogan, + VentureTypeKey = @VentureTypeKey, + + ModifiedDate = GetUTCDate() + Where VentureId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureLocationDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureLocationDelete.sql new file mode 100644 index 00000000..0641c995 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureLocationDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[VentureLocationDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureLocationKey], @Key) From [Entity].[VentureLocation] Where [VentureLocationId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureLocationId], -1) From [Entity].[VentureLocation] Where [VentureLocationKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[VentureLocation] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where VentureLocationId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureLocationSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureLocationSave.sql new file mode 100644 index 00000000..48912f77 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureLocationSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[VentureLocationSave] + @Id Int, + @Key Uniqueidentifier, + @VentureKey Uniqueidentifier, + @VentureName nvarchar(50), + @VentureDescription nvarchar(2000), + @LocationKey Uniqueidentifier, + @LocationName nvarchar(50), + @LocationDescription nvarchar(2000), + @LocationTypeKey Uniqueidentifier +AS + -- Initialize + Select @LocationName = RTRIM(LTRIM(@LocationName)) + Select @LocationDescription = RTRIM(LTRIM(@LocationDescription)) + -- Validate Data + If (@VentureKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureLocationKey], @Key), @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), LocationKey), + @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureLocation] Where [VentureLocationId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureLocationId], -1), @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), LocationKey), @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureLocation] Where [VentureLocationKey] = @Key + -- Venture: Insert vs. Update + If (@VentureKey Is Null) Or (@VentureKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert VentureVenture + Select @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Venture] (VentureKey, VentureName, VentureDescription, RecordStateKey) + Values (@VentureKey, @VentureName, @VentureDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Venture + Update [Entity].[Venture] + Set VentureName = IsNull(@VentureName, VentureName), + VentureDescription = IsNull(@VentureDescription, VentureDescription), + ModifiedDate = GetUtcDate() + Where VentureKey = @VentureKey + End + -- Location: Insert vs. Update + If (@LocationKey Is Null) Or (@LocationKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert VentureLocation + Select @LocationKey = IsNull(NullIf(@LocationKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Location] (LocationKey, LocationName, LocationDescription, RecordStateKey) + Values (@LocationKey, @LocationName, @LocationDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Location + Update [Entity].[Location] + Set LocationName = IsNull(@LocationName, LocationName), + LocationDescription = IsNull(@LocationDescription, LocationDescription), + ModifiedDate = GetUtcDate() + Where LocationKey = @LocationKey + End + -- VentureLocation: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert VentureLocation + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[VentureLocation] (VentureLocationKey, VentureKey, LocationKey, LocationTypeKey, RecordStateKey) + Values (@Key, @VentureKey, @LocationKey, NullIf(@LocationTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Location + Update [Entity].[VentureLocation] + Set LocationTypeKey = NullIf(@LocationTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where VentureLocationKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureOptionDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureOptionDelete.sql new file mode 100644 index 00000000..d5024c25 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureOptionDelete.sql @@ -0,0 +1,22 @@ +Create Procedure [EntityCode].[VentureOptionDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull(VentureOptionId, -1) From [Entity].[VentureOption] P Where [VentureOptionKey] = @Key + If (@Id <> -1) + Begin + Delete + From [Entity].[VentureOption] + Where VentureOptionId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureOptionSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureOptionSave.sql new file mode 100644 index 00000000..cdc3660f --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureOptionSave.sql @@ -0,0 +1,29 @@ +Create PROCEDURE [EntityCode].[VentureOptionSave] + @Id Int, + @Key Uniqueidentifier, + @VentureKey Uniqueidentifier, + @OptionKey Uniqueidentifier +AS + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureOptionKey], @Key) From [Entity].[VentureOption] Where [VentureOptionId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureOptionId], -1) From [Entity].[VentureOption] Where [VentureOptionKey] = @Key + -- Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[VentureOption] (VentureOptionKey, VentureKey, OptionKey) + Values (@Key, @VentureKey, @OptionKey) + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- VentureOption master + Update [Entity].[VentureOption] + Set OptionKey = @OptionKey, + + ModifiedDate = GetUTCDate() + Where VentureOptionId = @Id + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureResourceDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureResourceDelete.sql new file mode 100644 index 00000000..cde0e7ac --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureResourceDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[VentureResourceDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureResourceKey], @Key) From [Entity].[VentureResource] Where [VentureResourceId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureResourceId], -1) From [Entity].[VentureResource] Where [VentureResourceKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[VentureResource] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where VentureResourceId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureResourceSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureResourceSave.sql new file mode 100644 index 00000000..964fbd6d --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureResourceSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[VentureResourceSave] + @Id Int, + @Key Uniqueidentifier, + @VentureKey Uniqueidentifier, + @VentureName nvarchar(50), + @VentureDescription nvarchar(2000), + @ResourceKey Uniqueidentifier, + @ResourceName nvarchar(50), + @ResourceDescription nvarchar(2000), + @ResourceTypeKey Uniqueidentifier +AS + -- Initialize + Select @ResourceName = RTRIM(LTRIM(@ResourceName)) + Select @ResourceDescription = RTRIM(LTRIM(@ResourceDescription)) + -- Validate Data + If (@VentureKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureResourceKey], @Key), @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), ResourceKey), + @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureResource] Where [VentureResourceId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureResourceId], -1), @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), ResourceKey), @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureResource] Where [VentureResourceKey] = @Key + -- Venture: Insert vs. Update + If (@VentureKey Is Null) Or (@VentureKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert VentureVenture + Select @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Venture] (VentureKey, VentureName, VentureDescription, RecordStateKey) + Values (@VentureKey, @VentureName, @VentureDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Venture + Update [Entity].[Venture] + Set VentureName = IsNull(@VentureName, VentureName), + VentureDescription = IsNull(@VentureDescription, VentureDescription), + ModifiedDate = GetUtcDate() + Where VentureKey = @VentureKey + End + -- Resource: Insert vs. Update + If (@ResourceKey Is Null) Or (@ResourceKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert VentureResource + Select @ResourceKey = IsNull(NullIf(@ResourceKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Resource] (ResourceKey, ResourceName, ResourceDescription, RecordStateKey) + Values (@ResourceKey, @ResourceName, @ResourceDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Resource + Update [Entity].[Resource] + Set ResourceName = IsNull(@ResourceName, ResourceName), + ResourceDescription = IsNull(@ResourceDescription, ResourceDescription), + ModifiedDate = GetUtcDate() + Where ResourceKey = @ResourceKey + End + -- VentureResource: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert VentureResource + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[VentureResource] (VentureResourceKey, VentureKey, ResourceKey, ResourceTypeKey, RecordStateKey) + Values (@Key, @VentureKey, @ResourceKey, NullIf(@ResourceTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Resource + Update [Entity].[VentureResource] + Set ResourceTypeKey = NullIf(@ResourceTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where VentureResourceKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureScheduleDelete.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureScheduleDelete.sql new file mode 100644 index 00000000..90260a08 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureScheduleDelete.sql @@ -0,0 +1,25 @@ +Create Procedure [EntityCode].[VentureScheduleDelete] + @Id INT, + @Key uniqueidentifier +AS + Begin + + Begin Try + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureScheduleKey], @Key) From [Entity].[VentureSchedule] Where [VentureScheduleId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureScheduleId], -1) From [Entity].[VentureSchedule] Where [VentureScheduleKey] = @Key + -- Validate + If (@Id <> -1) + Begin + Update [Entity].[VentureSchedule] + Set RecordStateKey = '081C6A5B-0817-4161-A3AD-AD7924BEA874' + Where VentureScheduleId = @Id + End + + End Try + Begin Catch + + Exec [Activity].[ExceptionLogInsertByException]; + + End Catch + End \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Stored Procedures/VentureScheduleSave.sql b/data/Entity.Database/EntityCode/Stored Procedures/VentureScheduleSave.sql new file mode 100644 index 00000000..35c0bfb3 --- /dev/null +++ b/data/Entity.Database/EntityCode/Stored Procedures/VentureScheduleSave.sql @@ -0,0 +1,76 @@ +Create PROCEDURE [EntityCode].[VentureScheduleSave] + @Id Int, + @Key Uniqueidentifier, + @VentureKey Uniqueidentifier, + @VentureName nvarchar(50), + @VentureDescription nvarchar(2000), + @ScheduleKey Uniqueidentifier, + @ScheduleName nvarchar(50), + @ScheduleDescription nvarchar(2000), + @ScheduleTypeKey Uniqueidentifier +AS + -- Initialize + Select @ScheduleName = RTRIM(LTRIM(@ScheduleName)) + Select @ScheduleDescription = RTRIM(LTRIM(@ScheduleDescription)) + -- Validate Data + If (@VentureKey <> '00000000-0000-0000-0000-000000000000') + Begin + -- Id and Key are both valid. Sync now. + If (@Id <> -1) Select Top 1 @Key = IsNull([VentureScheduleKey], @Key), @ScheduleKey = IsNull(NullIf(@ScheduleKey, '00000000-0000-0000-0000-000000000000'), ScheduleKey), + @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureSchedule] Where [VentureScheduleId] = @Id + If (@Id = -1 AND @Key <> '00000000-0000-0000-0000-000000000000') Select Top 1 @Id = IsNull([VentureScheduleId], -1), @ScheduleKey = IsNull(NullIf(@ScheduleKey, '00000000-0000-0000-0000-000000000000'), ScheduleKey), @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), VentureKey) From [Entity].[VentureSchedule] Where [VentureScheduleKey] = @Key + -- Venture: Insert vs. Update + If (@VentureKey Is Null) Or (@VentureKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert VentureVenture + Select @VentureKey = IsNull(NullIf(@VentureKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Venture] (VentureKey, VentureName, VentureDescription, RecordStateKey) + Values (@VentureKey, @VentureName, @VentureDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Venture + Update [Entity].[Venture] + Set VentureName = IsNull(@VentureName, VentureName), + VentureDescription = IsNull(@VentureDescription, VentureDescription), + ModifiedDate = GetUtcDate() + Where VentureKey = @VentureKey + End + -- Schedule: Insert vs. Update + If (@ScheduleKey Is Null) Or (@ScheduleKey = '00000000-0000-0000-0000-000000000000') + Begin + -- Insert VentureSchedule + Select @ScheduleKey = IsNull(NullIf(@ScheduleKey, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[Schedule] (ScheduleKey, ScheduleName, ScheduleDescription, RecordStateKey) + Values (@ScheduleKey, @ScheduleName, @ScheduleDescription, '00000000-0000-0000-0000-000000000000') + End + Else + Begin + -- Update Schedule + Update [Entity].[Schedule] + Set ScheduleName = IsNull(@ScheduleName, ScheduleName), + ScheduleDescription = IsNull(@ScheduleDescription, ScheduleDescription), + ModifiedDate = GetUtcDate() + Where ScheduleKey = @ScheduleKey + End + -- VentureSchedule: Insert vs. Update + If (@Id Is Null) Or (@Id = -1) + Begin + -- Insert VentureSchedule + Select @Key = IsNull(NullIf(@Key, '00000000-0000-0000-0000-000000000000'), NewId()) + Insert Into [Entity].[VentureSchedule] (VentureScheduleKey, VentureKey, ScheduleKey, ScheduleTypeKey, RecordStateKey) + Values (@Key, @VentureKey, @ScheduleKey, NullIf(@ScheduleTypeKey, '00000000-0000-0000-0000-000000000000'), '00000000-0000-0000-0000-000000000000') + Select @Id = SCOPE_IDENTITY() + End + Else + Begin + -- Update Schedule + Update [Entity].[VentureSchedule] + Set ScheduleTypeKey = NullIf(@ScheduleTypeKey, '00000000-0000-0000-0000-000000000000'), + + ModifiedDate = GetUtcDate() + Where VentureScheduleKey = @Key + End + End + -- Return data + Select IsNull(@Id, -1) As Id, IsNull(@Key, '00000000-0000-0000-0000-000000000000') As [Key] diff --git a/data/Entity.Database/EntityCode/Views/ApplicationInfo.sql b/data/Entity.Database/EntityCode/Views/ApplicationInfo.sql new file mode 100644 index 00000000..adfd928f --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ApplicationInfo.sql @@ -0,0 +1,15 @@ + CREATE View [EntityCode].[ApplicationInfo] +AS + Select A.ApplicationId As [Id], + A.ApplicationKey As [Key], + A.ApplicationName As Name, + A.ApplicationSlogan As Slogan, + A.SharedApplicationKey, + A.SharedSecret, + A.BusinessEntityKey As BusinessKey, + A.PrivacyUrl, + A.TermsUrl, + A.TermsRevisedDate, + A.CreatedDate, + A.ModifiedDate + From [Entity].[Application] A diff --git a/data/Entity.Database/EntityCode/Views/ApplicationSetting.sql b/data/Entity.Database/EntityCode/Views/ApplicationSetting.sql new file mode 100644 index 00000000..3ccc9cbd --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ApplicationSetting.sql @@ -0,0 +1,13 @@ +Create VIEW [EntityCode].[ApplicationSetting] + AS +SELECT ASet.ApplicationSettingId As [Id], + ASet.ApplicationSettingKey As [Key], + Aset.ApplicationKey, + Aset.SettingKey, + S.SettingTypeKey, + S.SettingName, + S.SettingValue, + S.CreatedDate, + S.ModifiedDate +From [Setting].[ApplicationSetting] ASet +Join [Setting].[Setting] S On ASet.SettingKey = S.SettingKey diff --git a/data/Entity.Database/EntityCode/Views/AppointmentInfo.sql b/data/Entity.Database/EntityCode/Views/AppointmentInfo.sql new file mode 100644 index 00000000..c23266c2 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/AppointmentInfo.sql @@ -0,0 +1,17 @@ +Create VIEW [EntityCode].[AppointmentInfo] +AS + Select A.AppointmentId As [Id], + A.AppointmentKey As [Key], + A.AppointmentName As [Name], + A.AppointmentDescription As [Description], + IsNull(A.SlotLocationKey, '00000000-0000-0000-0000-000000000000') As [SlotLocationKey], + IsNull(A.SlotResourceKey, '00000000-0000-0000-0000-000000000000') As [SlotResourceKey], + A.CreatedDate, + A.ModifiedDate, + + A.TimeRangeKey, + TR.BeginDate, + TR.EndDate + From [Entity].[Appointment] A + Join [Entity].[TimeRange] TR On A.TimeRangeKey = TR.TimeRangeKey + Where A.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/BusinessInfo.sql b/data/Entity.Database/EntityCode/Views/BusinessInfo.sql new file mode 100644 index 00000000..994ff5e0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/BusinessInfo.sql @@ -0,0 +1,10 @@ +Create View [EntityCode].[BusinessInfo] +As +Select B.BusinessId As [Id], + B.BusinessKey As [Key], + B.BusinessName As Name, + B.TaxNumber, + B.CreatedDate, + B.ModifiedDate +From [Entity].[Business] B +Where B.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' diff --git a/data/Entity.Database/EntityCode/Views/DetailInfo.sql b/data/Entity.Database/EntityCode/Views/DetailInfo.sql new file mode 100644 index 00000000..74e68445 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/DetailInfo.sql @@ -0,0 +1,11 @@ +Create VIEW [EntityCode].[DetailInfo] + AS +SELECT D.DetailId As [Id], + D.DetailKey As [Key], + D.DetailData As [Data], + DT.DetailTypeName As [Name], + DT.DetailTypeDescription As [Description], + D.DetailTypeKey, + D.CreatedDate +FROM [Entity].[Detail] D + Join [Entity].[DetailType] DT On D.DetailTypeKey = DT.DetailTypeKey diff --git a/data/Entity.Database/EntityCode/Views/DetailType.sql b/data/Entity.Database/EntityCode/Views/DetailType.sql new file mode 100644 index 00000000..f837825c --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/DetailType.sql @@ -0,0 +1,8 @@ +Create VIEW [EntityCode].[DetailType] + AS +SELECT DT.DetailTypeId As [Id], + DT.DetailTypeKey As [Key], + DT.DetailTypeName As [Name], + DT.DetailTypeDescription As [Description], + DT.CreatedDate +FROM [Entity].[DetailType] DT diff --git a/data/Entity.Database/EntityCode/Views/EntityAppointment.sql b/data/Entity.Database/EntityCode/Views/EntityAppointment.sql new file mode 100644 index 00000000..3026401c --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EntityAppointment.sql @@ -0,0 +1,20 @@ +Create VIEW [EntityCode].[EntityAppointment] +AS + Select EA.EntityAppointmentId As [Id], + EA.EntityAppointmentKey As [Key], + EA.EntityKey, + A.AppointmentKey, + A.AppointmentName, + A.AppointmentDescription, + A.TimeRangeKey, + TR.BeginDate, + TR.EndDate, + IsNull(A.SlotLocationKey, '00000000-0000-0000-0000-000000000000') As [SlotLocationKey], + IsNull(A.SlotResourceKey, '00000000-0000-0000-0000-000000000000') As [SlotResourceKey], + EA.CreatedDate, + EA.ModifiedDate + From [Entity].[EntityAppointment] EA + Join [Entity].[Entity] E On EA.EntityKey = E.EntityKey + Join [Entity].[Appointment] A On EA.AppointmentKey = A.AppointmentKey + Join [Entity].[TimeRange] TR On A.TimeRangeKey = TR.TimeRangeKey + Where EA.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/EntityDetail.sql b/data/Entity.Database/EntityCode/Views/EntityDetail.sql new file mode 100644 index 00000000..ff3c9d01 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EntityDetail.sql @@ -0,0 +1,15 @@ +Create VIEW [EntityCode].[EntityDetail] + AS +SELECT ED.[EntityDetailId] As Id, + ED.[EntityDetailKey] As [Key], + ED.[EntityKey], + ED.[DetailKey], + D.[DetailTypeKey] As DetailTypeKey, + D.[DetailData], + DT.[DetailTypeName] As [Name], + DT.[DetailTypeDescription] As [Description], + ED.CreatedDate, + ED.ModifiedDate + FROM [Entity].[EntityDetail] ED + Join [Entity].[Detail] D On ED.DetailKey = D.DetailKey + Join [Entity].[DetailType] DT On D.DetailTypeKey = DT.DetailTypeKey diff --git a/data/Entity.Database/EntityCode/Views/EntityInfo.sql b/data/Entity.Database/EntityCode/Views/EntityInfo.sql new file mode 100644 index 00000000..97badb5d --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EntityInfo.sql @@ -0,0 +1,7 @@ +Create View [EntityCode].[EntityInfo] +As +Select C.EntityId As [Id], + C.EntityKey As [Key], + C.CreatedDate, + C.ModifiedDate +From [Entity].[Entity] C diff --git a/data/Entity.Database/EntityCode/Views/EntityLocation.sql b/data/Entity.Database/EntityCode/Views/EntityLocation.sql new file mode 100644 index 00000000..1dfa5917 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EntityLocation.sql @@ -0,0 +1,14 @@ +Create View [EntityCode].[EntityLocation] +As +Select C.EntityLocationId As [Id], + C.EntityLocationKey As [Key], + C.EntityKey, + C.LocationKey, + L.LocationName, + L.LocationDescription, + IsNull(C.LocationTypeKey, '00000000-0000-0000-0000-000000000000') As [LocationTypeKey], + C.CreatedDate, + C.ModifiedDate +From [Entity].[EntityLocation] C + Join [Entity].[Location] L On C.LocationKey = L.LocationKey +Where C.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/EntityOption.sql b/data/Entity.Database/EntityCode/Views/EntityOption.sql new file mode 100644 index 00000000..7299681f --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EntityOption.sql @@ -0,0 +1,13 @@ +Create View [EntityCode].[EntityOption] + AS +Select CP.EntityOptionId As [Id], + CP.EntityOptionKey As [Key], + CP.EntityKey, + P.OptionKey, + P.OptionGroupKey, + P.OptionName, + P.OptionDescription, + CP.ModifiedDate, + CP.CreatedDate +From [Entity].EntityOption CP +Join [Entity].[Option] P On CP.OptionKey = P.OptionKey diff --git a/data/Entity.Database/EntityCode/Views/EntityTimeRecurring.sql b/data/Entity.Database/EntityCode/Views/EntityTimeRecurring.sql new file mode 100644 index 00000000..ed331c97 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EntityTimeRecurring.sql @@ -0,0 +1,17 @@ +Create VIEW [EntityCode].[EntityTimeRecurring] +AS + Select LTA.EntityTimeRecurringId As [Id], + LTA.EntityTimeRecurringKey As [Key], + L.EntityKey, + TA.BeginDay, + TA.EndDay, + TA.BeginTime, + TA.EndTime, + TA.Interval, + IsNull(LTA.TimeTypeKey, '00000000-0000-0000-0000-000000000000') As [TimeTypeKey], + LTA.CreatedDate, + LTA.ModifiedDate + From [Entity].[EntityTimeRecurring] LTA + Join [Entity].[Entity] L On LTA.EntityKey = L.EntityKey + Join [Entity].[TimeRecurring] TA On LTA.TimeRecurringKey = TA.TimeRecurringKey + Where LTA.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/EventAppointment.sql b/data/Entity.Database/EntityCode/Views/EventAppointment.sql new file mode 100644 index 00000000..339d1de9 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventAppointment.sql @@ -0,0 +1,22 @@ +Create VIEW [EntityCode].[EventAppointment] +AS + Select EA.EventAppointmentId As [Id], + EA.EventAppointmentKey As [Key], + EA.EventKey, + E.EventName, + E.EventDescription, + A.AppointmentKey, + A.AppointmentName, + A.AppointmentDescription, + A.TimeRangeKey, + TR.BeginDate, + TR.EndDate, + IsNull(A.SlotLocationKey, '00000000-0000-0000-0000-000000000000') As [SlotLocationKey], + IsNull(A.SlotResourceKey, '00000000-0000-0000-0000-000000000000') As [SlotResourceKey], + EA.CreatedDate, + EA.ModifiedDate + From [Entity].[EventAppointment] EA + Join [Entity].[Event] E On EA.EventKey = E.EventKey + Join [Entity].[Appointment] A On EA.AppointmentKey = A.AppointmentKey + Join [Entity].[TimeRange] TR On A.TimeRangeKey = TR.TimeRangeKey + Where EA.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/EventDetail.sql b/data/Entity.Database/EntityCode/Views/EventDetail.sql new file mode 100644 index 00000000..4c5a61e6 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventDetail.sql @@ -0,0 +1,15 @@ +Create VIEW [EntityCode].[EventDetail] + AS +SELECT ED.[EventDetailId] As Id, + ED.[EventDetailKey] As [Key], + ED.[EventKey], + ED.[DetailKey], + D.[DetailTypeKey] As DetailTypeKey, + D.[DetailData], + DT.[DetailTypeName] As [Name], + DT.[DetailTypeDescription] As [Description], + ED.CreatedDate, + ED.ModifiedDate + FROM [Entity].[EventDetail] ED + Join [Entity].[Detail] D On ED.DetailKey = D.DetailKey + Join [Entity].[DetailType] DT On D.DetailTypeKey = DT.DetailTypeKey diff --git a/data/Entity.Database/EntityCode/Views/EventEntityOption.sql b/data/Entity.Database/EntityCode/Views/EventEntityOption.sql new file mode 100644 index 00000000..6f2257db --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventEntityOption.sql @@ -0,0 +1,14 @@ +Create View [EntityCode].[EventEntityOption] + AS +Select CP.EventEntityOptionId As [Id], + CP.EventEntityOptionKey As [Key], + CP.EventKey, + CP.EntityKey, + P.OptionKey, + P.OptionGroupKey, + P.OptionName, + P.OptionDescription, + CP.ModifiedDate, + CP.CreatedDate +From [Entity].EventEntityOption CP +Join [Entity].[Option] P On CP.OptionKey = P.OptionKey diff --git a/data/Entity.Database/EntityCode/Views/EventGroup.sql b/data/Entity.Database/EntityCode/Views/EventGroup.sql new file mode 100644 index 00000000..21d6bbb0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventGroup.sql @@ -0,0 +1,10 @@ +Create VIEW [EntityCode].[EventGroup] + AS +SELECT ET.EventGroupId As [Id], + ET.EventGroupKey As [Key], + ET.EventGroupName As Name, + ET.EventGroupDescription As Description, + ET.CreatedDate, + ET.EventGroupKey +FROM [Entity].[EventGroup] ET + diff --git a/data/Entity.Database/EntityCode/Views/EventInfo.sql b/data/Entity.Database/EntityCode/Views/EventInfo.sql new file mode 100644 index 00000000..a83816f2 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventInfo.sql @@ -0,0 +1,15 @@ +Create VIEW [EntityCode].[EventInfo] +AS + Select E.EventId As [Id], + E.EventKey As [Key], + E.EventGroupKey, + E.EventTypeKey, + E.EventCreatorKey, + E.EventName As Name, + E.EventDescription As [Description], + E.EventSlogan As Slogan, + E.CreatedDate, + E.ModifiedDate + From [Entity].[Event] E + Where E.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' + diff --git a/data/Entity.Database/EntityCode/Views/EventLocation.sql b/data/Entity.Database/EntityCode/Views/EventLocation.sql new file mode 100644 index 00000000..7a458d28 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventLocation.sql @@ -0,0 +1,18 @@ +Create VIEW [EntityCode].[EventLocation] +AS + Select ESL.EventLocationId As [Id], + ESL.EventLocationKey As [Key], + ESL.EventKey, + E.EventName, + E.EventDescription, + E.EventCreatorKey, + L.LocationKey, + L.LocationName, + L.LocationDescription, + IsNull(ESL.LocationTypeKey, '00000000-0000-0000-0000-000000000000') As [LocationTypeKey], + ESL.CreatedDate, + ESL.ModifiedDate + From [Entity].[EventLocation] ESL + Join [Entity].[Event] E On ESL.EventKey = E.EventKey + Join [Entity].[Location] L On ESL.LocationKey = L.LocationKey + Where ESL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/EventOption.sql b/data/Entity.Database/EntityCode/Views/EventOption.sql new file mode 100644 index 00000000..e6987a96 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventOption.sql @@ -0,0 +1,13 @@ +Create View [EntityCode].[EventOption] + AS +Select CP.EventOptionId As [Id], + CP.EventOptionKey As [Key], + CP.EventKey, + P.OptionKey, + P.OptionGroupKey, + P.OptionName, + P.OptionDescription, + CP.ModifiedDate, + CP.CreatedDate +From [Entity].EventOption CP +Join [Entity].[Option] P On CP.OptionKey = P.OptionKey diff --git a/data/Entity.Database/EntityCode/Views/EventResource.sql b/data/Entity.Database/EntityCode/Views/EventResource.sql new file mode 100644 index 00000000..6172b08c --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventResource.sql @@ -0,0 +1,18 @@ +Create VIEW [EntityCode].[EventResource] +AS + Select ESL.EventResourceId As [Id], + ESL.EventResourceKey As [Key], + ESL.EventKey, + E.EventName, + E.EventDescription, + E.EventCreatorKey, + L.ResourceKey, + L.ResourceName, + L.ResourceDescription, + IsNull(ESL.ResourceTypeKey, '00000000-0000-0000-0000-000000000000') As [ResourceTypeKey], + ESL.CreatedDate, + ESL.ModifiedDate + From [Entity].[EventResource] ESL + Join [Entity].[Event] E On ESL.EventKey = E.EventKey + Join [Entity].[Resource] L On ESL.ResourceKey = L.ResourceKey + Where ESL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/EventSchedule.sql b/data/Entity.Database/EntityCode/Views/EventSchedule.sql new file mode 100644 index 00000000..970332ef --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventSchedule.sql @@ -0,0 +1,18 @@ +Create VIEW [EntityCode].[EventSchedule] +AS + Select ESL.EventScheduleId As [Id], + ESL.EventScheduleKey As [Key], + ESL.EventKey, + E.EventName, + E.EventDescription, + E.EventCreatorKey, + L.ScheduleKey, + L.ScheduleName, + L.ScheduleDescription, + IsNull(ESL.ScheduleTypeKey, '00000000-0000-0000-0000-000000000000') As [ScheduleTypeKey], + ESL.CreatedDate, + ESL.ModifiedDate + From [Entity].[EventSchedule] ESL + Join [Entity].[Event] E On ESL.EventKey = E.EventKey + Join [Entity].[Schedule] L On ESL.ScheduleKey = L.ScheduleKey + Where ESL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/EventType.sql b/data/Entity.Database/EntityCode/Views/EventType.sql new file mode 100644 index 00000000..16043aa7 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/EventType.sql @@ -0,0 +1,10 @@ +Create VIEW [EntityCode].[EventType] + AS +SELECT ET.EventTypeId As [Id], + ET.EventTypeKey As [Key], + ET.EventTypeName As Name, + ET.EventTypeDescription As Description, + ET.CreatedDate, + ET.EventGroupKey +FROM [Entity].[EventType] ET + diff --git a/data/Entity.Database/EntityCode/Views/FlowInfo.sql b/data/Entity.Database/EntityCode/Views/FlowInfo.sql new file mode 100644 index 00000000..4a97c878 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/FlowInfo.sql @@ -0,0 +1,14 @@ +Create View [EntityCode].[FlowInfo] + AS +Select [FlowId] As [Id], + [FlowKey] As [Key], + [FlowName] as Name, + [FlowDescription] As Description, + [FlowTypeKey], + [ModuleKey], + [TimeoutInSeconds], + [RecordDeleteInMinutes], + [NonRepeatable], + [CreatedDate], + [ModifiedDate] +From [Entity].[Flow] diff --git a/data/Entity.Database/EntityCode/Views/GenderInfo.sql b/data/Entity.Database/EntityCode/Views/GenderInfo.sql new file mode 100644 index 00000000..dff60e6c --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/GenderInfo.sql @@ -0,0 +1,9 @@ +Create View [EntityCode].[GenderInfo] + AS +Select [GenderId] As [Id], + [GenderKey] As [Key], + [GenderName] as Name, + [GenderCode] As Code, + [CreatedDate], + [ModifiedDate] +From [Entity].[Gender] diff --git a/data/Entity.Database/EntityCode/Views/GovernmentInfo.sql b/data/Entity.Database/EntityCode/Views/GovernmentInfo.sql new file mode 100644 index 00000000..921ed201 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/GovernmentInfo.sql @@ -0,0 +1,9 @@ +Create View [EntityCode].[GovernmentInfo] +As +Select G.GovernmentId As [Id], + G.GovernmentKey As [Key], + G.GovernmentName As Name, + G.CreatedDate, + G.ModifiedDate +From [Entity].[Government] G +Where G.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' diff --git a/data/Entity.Database/EntityCode/Views/ItemGroup.sql b/data/Entity.Database/EntityCode/Views/ItemGroup.sql new file mode 100644 index 00000000..4b7a89d8 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ItemGroup.sql @@ -0,0 +1,10 @@ +Create VIEW [EntityCode].[ItemGroup] + AS +SELECT ET.ItemGroupId As [Id], + ET.ItemGroupKey As [Key], + ET.ItemGroupName As Name, + ET.ItemGroupDescription As Description, + ET.CreatedDate, + ET.ItemGroupKey +FROM [Entity].[ItemGroup] ET + diff --git a/data/Entity.Database/EntityCode/Views/ItemInfo.sql b/data/Entity.Database/EntityCode/Views/ItemInfo.sql new file mode 100644 index 00000000..ded60da8 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ItemInfo.sql @@ -0,0 +1,11 @@ +Create VIEW [EntityCode].[ItemInfo] +AS + Select L.ItemId As [Id], + L.ItemKey As [Key], + L.ItemName As [Name], + L.ItemDescription As [Description], + L.ItemTypeKey, + L.CreatedDate, + L.ModifiedDate + From [Entity].[Item] L + Where L.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/ItemType.sql b/data/Entity.Database/EntityCode/Views/ItemType.sql new file mode 100644 index 00000000..964d452b --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ItemType.sql @@ -0,0 +1,10 @@ +Create VIEW [EntityCode].[ItemType] + AS +SELECT ET.ItemTypeId As [Id], + ET.ItemTypeKey As [Key], + ET.ItemTypeName As Name, + ET.ItemTypeDescription As Description, + ET.CreatedDate, + ET.ItemGroupKey +FROM [Entity].[ItemType] ET + diff --git a/data/Entity.Database/EntityCode/Views/LocationInfo.sql b/data/Entity.Database/EntityCode/Views/LocationInfo.sql new file mode 100644 index 00000000..dc55d8dc --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/LocationInfo.sql @@ -0,0 +1,10 @@ +Create VIEW [EntityCode].[LocationInfo] +AS + Select L.LocationId As [Id], + L.LocationKey As [Key], + L.LocationName As [Name], + L.LocationDescription As [Description], + L.CreatedDate, + L.ModifiedDate + From [Entity].[Location] L + Where L.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/LocationTimeRecurring.sql b/data/Entity.Database/EntityCode/Views/LocationTimeRecurring.sql new file mode 100644 index 00000000..8976bc67 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/LocationTimeRecurring.sql @@ -0,0 +1,19 @@ +Create VIEW [EntityCode].[LocationTimeRecurring] +AS + Select LTA.LocationTimeRecurringId As [Id], + LTA.LocationTimeRecurringKey As [Key], + L.LocationKey, + L.LocationName, + L.LocationDescription, + TA.BeginDay, + TA.EndDay, + TA.BeginTime, + TA.EndTime, + TA.Interval, + IsNull(LTA.TimeTypeKey, '00000000-0000-0000-0000-000000000000') As [TimeTypeKey], + LTA.CreatedDate, + LTA.ModifiedDate + From [Entity].[LocationTimeRecurring] LTA + Join [Entity].[Location] L On LTA.LocationKey = L.LocationKey + Join [Entity].[TimeRecurring] TA On LTA.TimeRecurringKey = TA.TimeRecurringKey + Where LTA.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/LocationType.sql b/data/Entity.Database/EntityCode/Views/LocationType.sql new file mode 100644 index 00000000..a315a0ba --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/LocationType.sql @@ -0,0 +1,9 @@ +Create VIEW [EntityCode].[LocationType] + AS +SELECT ET.LocationTypeId As [Id], + ET.LocationTypeKey As [Key], + ET.LocationTypeName As Name, + ET.LocationTypeDescription As Description, + ET.CreatedDate +FROM [Entity].[LocationType] ET + diff --git a/data/Entity.Database/EntityCode/Views/ModuleInfo.sql b/data/Entity.Database/EntityCode/Views/ModuleInfo.sql new file mode 100644 index 00000000..ba72610e --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ModuleInfo.sql @@ -0,0 +1,9 @@ +CREATE View [EntityCode].[ModuleInfo] +AS + Select M.ModuleId As [Id], + M.ModuleKey As [Key], + M.ModuleName As Name, + M.ModuleDescription As Description, + M.CreatedDate, + M.ModifiedDate + From [Entity].[Module] M diff --git a/data/Entity.Database/EntityCode/Views/ModuleSetting.sql b/data/Entity.Database/EntityCode/Views/ModuleSetting.sql new file mode 100644 index 00000000..a796b6e5 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ModuleSetting.sql @@ -0,0 +1,17 @@ +Create VIEW [EntityCode].[ModuleSetting] + AS +SELECT MSet.ModuleSettingId As [Id], + MSet.ModuleSettingKey As [Key], + MSet.ModuleKey, + MSet.SettingKey, + S.SettingName, + S.SettingTypeKey, + S.SettingValue, + S.CreatedDate, + S.ModifiedDate +From [Setting].[ModuleSetting] MSet +Join [Setting].[Setting] S On MSet.SettingKey = S.SettingKey + + + + \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/OptionGroup.sql b/data/Entity.Database/EntityCode/Views/OptionGroup.sql new file mode 100644 index 00000000..451ef76b --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/OptionGroup.sql @@ -0,0 +1,9 @@ +Create View [EntityCode].[OptionGroup] +AS +Select PG.OptionGroupId As [Id], + PG.OptionGroupKey As [Key], + PG.OptionGroupName As Name, + PG.OptionGroupDescription As Description, + PG.CreatedDate, + PG.ModifiedDate +From [Entity].OptionGroup PG diff --git a/data/Entity.Database/EntityCode/Views/OptionInfo.sql b/data/Entity.Database/EntityCode/Views/OptionInfo.sql new file mode 100644 index 00000000..139c070d --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/OptionInfo.sql @@ -0,0 +1,15 @@ +Create View [EntityCode].[OptionInfo] + AS +SELECT O.OptionId As [Id], + O.OptionKey As [Key], + O.OptionGroupKey, + O.OptionName As Name, + O.OptionDescription As Description, + O.OptionCode As Code, + (OG.OptionGroupName + '-' + O.OptionName) As FullName, + (OG.OptionGroupCode + '-' + O.OptionCode) As FullCode, + O.SortOrder, + O.CreatedDate, + O.ModifiedDate +From [Entity].[Option] O +Join [Entity].[OptionGroup] OG On O.OptionGroupKey = OG.OptionGroupKey diff --git a/data/Entity.Database/EntityCode/Views/PersonInfo.sql b/data/Entity.Database/EntityCode/Views/PersonInfo.sql new file mode 100644 index 00000000..f317afa5 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/PersonInfo.sql @@ -0,0 +1,14 @@ +Create View [EntityCode].[PersonInfo] +As +Select P.PersonId As [Id], + P.PersonKey As [Key], + P.FirstName, + P.MiddleName, + P.LastName, + P.BirthDate, + IsNull(G.GenderCode, '') As GenderCode, + P.CreatedDate, + P.ModifiedDate +From [Entity].[Person] P +Left Join [Entity].[Gender] G On P.GenderId = G.GenderId +Where P.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/ResourceInfo.sql b/data/Entity.Database/EntityCode/Views/ResourceInfo.sql new file mode 100644 index 00000000..eff29b3b --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ResourceInfo.sql @@ -0,0 +1,11 @@ +Create VIEW [EntityCode].[ResourceInfo] +AS + Select S.ResourceId As [Id], + S.ResourceKey As [Key], + S.ResourceName As [Name], + S.ResourceDescription As [Description], + S.RecordStateKey, + S.CreatedDate, + S.ModifiedDate + From [Entity].[Resource] S + Where S.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' diff --git a/data/Entity.Database/EntityCode/Views/ResourceItem.sql b/data/Entity.Database/EntityCode/Views/ResourceItem.sql new file mode 100644 index 00000000..49a0781e --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ResourceItem.sql @@ -0,0 +1,17 @@ +Create View [EntityCode].[ResourceItem] +As +Select RP.ResourceItemId As [Id], + RP.ResourceItemKey As [Key], + R.ResourceKey, + R.ResourceName, + R.ResourceDescription, + P.ItemKey, + P.ItemName, + P.ItemDescription, + P.ItemTypeKey, + RP.CreatedDate, + RP.ModifiedDate +From [Entity].[ResourceItem] RP + Join [Entity].[Resource] R On RP.ResourceKey = R.ResourceKey + Join [Entity].[Item] P On RP.ItemKey = P.ItemKey +Where RP.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/ResourcePerson.sql b/data/Entity.Database/EntityCode/Views/ResourcePerson.sql new file mode 100644 index 00000000..d742f1d6 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ResourcePerson.sql @@ -0,0 +1,20 @@ +Create View [EntityCode].[ResourcePerson] +As +Select RP.ResourcePersonId As [Id], + RP.ResourcePersonKey As [Key], + R.ResourceKey, + R.ResourceName, + R.ResourceDescription, + P.PersonKey, + P.FirstName, + P.MiddleName, + P.LastName, + P.BirthDate, + IsNull(G.GenderCode, '') As GenderCode, + RP.CreatedDate, + RP.ModifiedDate +From [Entity].[ResourcePerson] RP + Join [Entity].[Resource] R On RP.ResourceKey = R.ResourceKey + Join [Entity].[Person] P On RP.PersonKey = P.PersonKey + Left Join [Entity].[Gender] G On P.GenderId = G.GenderId +Where RP.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/ResourceTimeRecurring.sql b/data/Entity.Database/EntityCode/Views/ResourceTimeRecurring.sql new file mode 100644 index 00000000..211d494c --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ResourceTimeRecurring.sql @@ -0,0 +1,19 @@ +Create VIEW [EntityCode].[ResourceTimeRecurring] +AS + Select RTA.ResourceTimeRecurringId As [Id], + RTA.ResourceTimeRecurringKey As [Key], + L.ResourceKey, + L.ResourceName, + L.ResourceDescription, + TA.BeginDay, + TA.EndDay, + TA.BeginTime, + TA.EndTime, + TA.Interval, + IsNull(RTA.TimeTypeKey, '00000000-0000-0000-0000-000000000000') As [TimeTypeKey], + RTA.CreatedDate, + RTA.ModifiedDate + From [Entity].[ResourceTimeRecurring] RTA + Join [Entity].[Resource] L On RTA.ResourceKey = L.ResourceKey + Join [Entity].[TimeRecurring] TA On RTA.TimeRecurringKey = TA.TimeRecurringKey + Where RTA.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/ResourceType.sql b/data/Entity.Database/EntityCode/Views/ResourceType.sql new file mode 100644 index 00000000..14290871 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ResourceType.sql @@ -0,0 +1,9 @@ +Create VIEW [EntityCode].[ResourceType] + AS +SELECT ET.ResourceTypeId As [Id], + ET.ResourceTypeKey As [Key], + ET.ResourceTypeName As Name, + ET.ResourceTypeDescription As Description, + ET.CreatedDate +FROM [Entity].[ResourceType] ET + diff --git a/data/Entity.Database/EntityCode/Views/ScheduleInfo.sql b/data/Entity.Database/EntityCode/Views/ScheduleInfo.sql new file mode 100644 index 00000000..aacfe93e --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ScheduleInfo.sql @@ -0,0 +1,11 @@ +Create VIEW [EntityCode].[ScheduleInfo] +AS + Select S.ScheduleId As [Id], + S.ScheduleKey As [Key], + S.ScheduleName As [Name], + S.ScheduleDescription As [Description], + S.RecordStateKey, + S.CreatedDate, + S.ModifiedDate + From [Entity].[Schedule] S + Where S.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/ScheduleSlot.sql b/data/Entity.Database/EntityCode/Views/ScheduleSlot.sql new file mode 100644 index 00000000..209ffaf4 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ScheduleSlot.sql @@ -0,0 +1,9 @@ +Create VIEW [EntityCode].[ScheduleSlot] +AS + Select S.ScheduleSlotId As [Id], + S.ScheduleSlotKey As [Key], + S.ScheduleKey, + S.SlotKey, + S.CreatedDate, + S.ModifiedDate + From [Entity].[ScheduleSlot] S \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/ScheduleType.sql b/data/Entity.Database/EntityCode/Views/ScheduleType.sql new file mode 100644 index 00000000..151ba0b8 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/ScheduleType.sql @@ -0,0 +1,9 @@ +Create VIEW [EntityCode].[ScheduleType] + AS +SELECT ET.ScheduleTypeId As [Id], + ET.ScheduleTypeKey As [Key], + ET.ScheduleTypeName As Name, + ET.ScheduleTypeDescription As Description, + ET.CreatedDate +FROM [Entity].[ScheduleType] ET + diff --git a/data/Entity.Database/EntityCode/Views/SlotInfo.sql b/data/Entity.Database/EntityCode/Views/SlotInfo.sql new file mode 100644 index 00000000..49a8dfdd --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/SlotInfo.sql @@ -0,0 +1,11 @@ +Create VIEW [EntityCode].[SlotInfo] +AS + Select S.SlotId As [Id], + S.SlotKey As [Key], + S.SlotName As [Name], + S.SlotDescription As [Description], + S.RecordStateKey, + S.CreatedDate, + S.ModifiedDate + From [Entity].[Slot] S + Where S.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/SlotLocation.sql b/data/Entity.Database/EntityCode/Views/SlotLocation.sql new file mode 100644 index 00000000..8a3036d7 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/SlotLocation.sql @@ -0,0 +1,18 @@ +Create VIEW [EntityCode].[SlotLocation] +AS + Select SL.SlotLocationId As [Id], + SL.SlotLocationKey As [Key], + S.SlotKey, + S.SlotName, + S.SlotDescription, + L.LocationKey, + L.LocationName, + L.LocationDescription, + IsNull(SL.LocationTypeKey, '00000000-0000-0000-0000-000000000000') As [LocationTypeKey], + SL.RecordStateKey, + SL.CreatedDate, + SL.ModifiedDate + From [Entity].[SlotLocation] SL + Join [Entity].[Slot] S On SL.SlotKey = S.SlotKey + Join [Entity].[Location] L On SL.LocationKey = L.LocationKey + Where SL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/SlotResource.sql b/data/Entity.Database/EntityCode/Views/SlotResource.sql new file mode 100644 index 00000000..cccca755 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/SlotResource.sql @@ -0,0 +1,18 @@ +Create VIEW [EntityCode].[SlotResource] +AS + Select SL.SlotResourceId As [Id], + SL.SlotResourceKey As [Key], + S.SlotKey, + S.SlotName, + S.SlotDescription, + L.ResourceKey, + L.ResourceName, + L.ResourceDescription, + IsNull(SL.ResourceTypeKey, '00000000-0000-0000-0000-000000000000') As [ResourceTypeKey], + SL.RecordStateKey, + SL.CreatedDate, + SL.ModifiedDate + From [Entity].[SlotResource] SL + Join [Entity].[Slot] S On SL.SlotKey = S.SlotKey + Join [Entity].[Resource] L On SL.ResourceKey = L.ResourceKey + Where SL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/SlotTimeRange.sql b/data/Entity.Database/EntityCode/Views/SlotTimeRange.sql new file mode 100644 index 00000000..d263c275 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/SlotTimeRange.sql @@ -0,0 +1,19 @@ +Create VIEW [EntityCode].[SlotTimeRange] +AS + Select ST.SlotTimeRangeId As [Id], + ST.SlotTimeRangeKey As [Key], + S.SlotKey, + S.SlotName, + S.SlotDescription, + TR.BeginDate, + TR.EndDate, + IsNull(ST.TimeTypeKey, '00000000-0000-0000-0000-000000000000') As [TimeTypeKey], + IsNull(TT.TimeBehavior, 1) As [TimeBehavior], + ST.RecordStateKey, + ST.CreatedDate, + ST.ModifiedDate + From [Entity].[SlotTimeRange] ST + Join [Entity].[Slot] S On ST.SlotKey = S.SlotKey + Join [Entity].[TimeRange] TR On ST.TimeRangeKey = TR.TimeRangeKey + Left Join [Entity].[TimeType] TT On ST.TimeTypeKey = TT.TimeTypeKey + Where ST.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/SlotTimeRecurring.sql b/data/Entity.Database/EntityCode/Views/SlotTimeRecurring.sql new file mode 100644 index 00000000..70b6cc2e --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/SlotTimeRecurring.sql @@ -0,0 +1,23 @@ +Create VIEW [EntityCode].[SlotTimeRecurring] +AS + Select ST.SlotTimeRecurringId As [Id], + ST.SlotTimeRecurringKey As [Key], + S.SlotKey, + S.SlotName, + S.SlotDescription, + TR.BeginDay, + TR.EndDay, + TR.BeginTime, + TR.EndTime, + TR.Interval, + TR.TimeCycleKey, + IsNull(ST.TimeTypeKey, '00000000-0000-0000-0000-000000000000') As [TimeTypeKey], + IsNull(TT.TimeBehavior, 1) As [TimeBehavior], + ST.RecordStateKey, + ST.CreatedDate, + ST.ModifiedDate + From [Entity].[SlotTimeRecurring] ST + Join [Entity].[Slot] S On ST.SlotKey = S.SlotKey + Join [Entity].[TimeRecurring] TR On ST.TimeRecurringKey = TR.TimeRecurringKey + Left Join [Entity].[TimeType] TT On ST.TimeTypeKey = TT.TimeTypeKey + Where ST.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/TimeType.sql b/data/Entity.Database/EntityCode/Views/TimeType.sql new file mode 100644 index 00000000..f1427ba0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/TimeType.sql @@ -0,0 +1,10 @@ +Create VIEW [EntityCode].[TimeType] + AS +SELECT ET.TimeTypeId As [Id], + ET.TimeTypeKey As [Key], + ET.TimeTypeName As [Name], + ET.TimeBehavior As [TimeBehavior], + ET.TimeTypeDescription As Description, + ET.CreatedDate +FROM [Entity].[TimeType] ET + diff --git a/data/Entity.Database/EntityCode/Views/VentureAppointment.sql b/data/Entity.Database/EntityCode/Views/VentureAppointment.sql new file mode 100644 index 00000000..c5dba0ae --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureAppointment.sql @@ -0,0 +1,22 @@ +Create VIEW [EntityCode].[VentureAppointment] +AS + Select EA.VentureAppointmentId As [Id], + EA.VentureAppointmentKey As [Key], + EA.VentureKey, + E.VentureName, + E.VentureDescription, + A.AppointmentKey, + A.AppointmentName, + A.AppointmentDescription, + A.TimeRangeKey, + TR.BeginDate, + TR.EndDate, + IsNull(A.SlotLocationKey, '00000000-0000-0000-0000-000000000000') As [SlotLocationKey], + IsNull(A.SlotResourceKey, '00000000-0000-0000-0000-000000000000') As [SlotResourceKey], + EA.CreatedDate, + EA.ModifiedDate + From [Entity].[VentureAppointment] EA + Join [Entity].[Venture] E On EA.VentureKey = E.VentureKey + Join [Entity].[Appointment] A On EA.AppointmentKey = A.AppointmentKey + Join [Entity].[TimeRange] TR On A.TimeRangeKey = TR.TimeRangeKey + Where EA.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/VentureDetail.sql b/data/Entity.Database/EntityCode/Views/VentureDetail.sql new file mode 100644 index 00000000..c4326e6c --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureDetail.sql @@ -0,0 +1,15 @@ +Create VIEW [EntityCode].[VentureDetail] + AS +SELECT VD.[VentureDetailId] As Id, + VD.[VentureDetailKey] As [Key], + VD.[VentureKey], + VD.[DetailKey], + D.[DetailTypeKey] As DetailTypeKey, + D.[DetailData], + DT.[DetailTypeName] As [Name], + DT.[DetailTypeDescription] As [Description], + VD.CreatedDate, + VD.ModifiedDate + FROM [Entity].[VentureDetail] VD + Join [Entity].[Detail] D On VD.DetailKey = D.DetailKey + Join [Entity].[DetailType] DT On D.DetailTypeKey = DT.DetailTypeKey diff --git a/data/Entity.Database/EntityCode/Views/VentureEntityOption.sql b/data/Entity.Database/EntityCode/Views/VentureEntityOption.sql new file mode 100644 index 00000000..049dbc6f --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureEntityOption.sql @@ -0,0 +1,14 @@ +Create View [EntityCode].[VentureEntityOption] + AS +Select CP.VentureEntityOptionId As [Id], + CP.VentureEntityOptionKey As [Key], + CP.VentureKey, + CP.EntityKey, + P.OptionKey, + P.OptionGroupKey, + P.OptionName, + P.OptionDescription, + CP.ModifiedDate, + CP.CreatedDate +From [Entity].VentureEntityOption CP +Join [Entity].[Option] P On CP.OptionKey = P.OptionKey diff --git a/data/Entity.Database/EntityCode/Views/VentureInfo.sql b/data/Entity.Database/EntityCode/Views/VentureInfo.sql new file mode 100644 index 00000000..bcdb4d28 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureInfo.sql @@ -0,0 +1,14 @@ +Create VIEW [EntityCode].[VentureInfo] +AS + Select E.VentureId As [Id], + E.VentureKey As [Key], + E.VentureGroupKey, + E.VentureTypeKey, + E.VentureName As Name, + E.VentureDescription As [Description], + E.VentureSlogan As Slogan, + E.CreatedDate, + E.ModifiedDate + From [Entity].[Venture] E + Where E.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' + diff --git a/data/Entity.Database/EntityCode/Views/VentureLocation.sql b/data/Entity.Database/EntityCode/Views/VentureLocation.sql new file mode 100644 index 00000000..78a287a0 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureLocation.sql @@ -0,0 +1,17 @@ +Create VIEW [EntityCode].[VentureLocation] +AS + Select ESL.VentureLocationId As [Id], + ESL.VentureLocationKey As [Key], + ESL.VentureKey, + E.VentureName, + E.VentureDescription, + L.LocationKey, + L.LocationName, + L.LocationDescription, + IsNull(ESL.LocationTypeKey, '00000000-0000-0000-0000-000000000000') As [LocationTypeKey], + ESL.CreatedDate, + ESL.ModifiedDate + From [Entity].[VentureLocation] ESL + Join [Entity].[Venture] E On ESL.VentureKey = E.VentureKey + Join [Entity].[Location] L On ESL.LocationKey = L.LocationKey + Where ESL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/VentureOption.sql b/data/Entity.Database/EntityCode/Views/VentureOption.sql new file mode 100644 index 00000000..574677f2 --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureOption.sql @@ -0,0 +1,13 @@ +Create View [EntityCode].[VentureOption] + AS +Select CP.VentureOptionId As [Id], + CP.VentureOptionKey As [Key], + CP.VentureKey, + P.OptionKey, + P.OptionGroupKey, + P.OptionName, + P.OptionDescription, + CP.ModifiedDate, + CP.CreatedDate +From [Entity].VentureOption CP +Join [Entity].[Option] P On CP.OptionKey = P.OptionKey diff --git a/data/Entity.Database/EntityCode/Views/VentureResource.sql b/data/Entity.Database/EntityCode/Views/VentureResource.sql new file mode 100644 index 00000000..c6ff6d2c --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureResource.sql @@ -0,0 +1,17 @@ +Create VIEW [EntityCode].[VentureResource] +AS + Select ESL.VentureResourceId As [Id], + ESL.VentureResourceKey As [Key], + ESL.VentureKey, + E.VentureName, + E.VentureDescription, + L.ResourceKey, + L.ResourceName, + L.ResourceDescription, + IsNull(ESL.ResourceTypeKey, '00000000-0000-0000-0000-000000000000') As [ResourceTypeKey], + ESL.CreatedDate, + ESL.ModifiedDate + From [Entity].[VentureResource] ESL + Join [Entity].[Venture] E On ESL.VentureKey = E.VentureKey + Join [Entity].[Resource] L On ESL.ResourceKey = L.ResourceKey + Where ESL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/EntityCode/Views/VentureSchedule.sql b/data/Entity.Database/EntityCode/Views/VentureSchedule.sql new file mode 100644 index 00000000..a8a5010a --- /dev/null +++ b/data/Entity.Database/EntityCode/Views/VentureSchedule.sql @@ -0,0 +1,17 @@ +Create VIEW [EntityCode].[VentureSchedule] +AS + Select ESL.VentureScheduleId As [Id], + ESL.VentureScheduleKey As [Key], + ESL.VentureKey, + E.VentureName, + E.VentureDescription, + L.ScheduleKey, + L.ScheduleName, + L.ScheduleDescription, + IsNull(ESL.ScheduleTypeKey, '00000000-0000-0000-0000-000000000000') As [ScheduleTypeKey], + ESL.CreatedDate, + ESL.ModifiedDate + From [Entity].[VentureSchedule] ESL + Join [Entity].[Venture] E On ESL.VentureKey = E.VentureKey + Join [Entity].[Schedule] L On ESL.ScheduleKey = L.ScheduleKey + Where ESL.RecordStateKey <> '081C6A5B-0817-4161-A3AD-AD7924BEA874' \ No newline at end of file diff --git a/data/Entity.Database/GoodToCode.Entity.Database.sqlproj b/data/Entity.Database/GoodToCode.Entity.Database.sqlproj new file mode 100644 index 00000000..82f7eb68 --- /dev/null +++ b/data/Entity.Database/GoodToCode.Entity.Database.sqlproj @@ -0,0 +1,386 @@ + + + + + Debug + AnyCPU + GoodToCode.Entity.Database + 2.0 + 4.1 + {f8aa8218-1e36-483a-80b4-1ba49fd43e35} + Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider + Database + + + GoodToCode.Entity.Database + GoodToCode.Entity.Database + 1033,CI + BySchemaAndSchemaType + True + v4.6 + CS + Properties + False + True + True + SAK + SAK + SAK + SAK + dbo + SQL_Latin1_General_CP1_CI_AS + PRIMARY + + GoodToCode.Entity.Database + GoodToCode.Entity.EntityData + 3.00.001 + GoodToCode Framework data, schema, security objects and DBA objects. + + + bin\Release\ + $(MSBuildProjectName).sql + False + pdbonly + true + false + true + prompt + 4 + + + bin\Debug\ + $(MSBuildProjectName).sql + false + true + full + false + true + true + prompt + 4 + GoodToCode.Framework + + + 11.0 + + True + 11.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Dev + $(SqlCmdVar__1) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Call "$(MSBuildProjectDirectory)\App_Data\PostBuild.$(ConfigurationName).bat" "$(MSBuildProjectDirectory)\$(OutDir)" "$(ConfigurationName)" "$(ProjectName)" + + + Call "$(MSBuildProjectDirectory)\App_Data\PreBuild.$(ConfigurationName).bat" "$(MSBuildProjectDirectory)" "$(ConfigurationName)" "$(ProjectName)" + + \ No newline at end of file diff --git a/data/Entity.Database/Identity/Tables/AspNetRoles.sql b/data/Entity.Database/Identity/Tables/AspNetRoles.sql new file mode 100644 index 00000000..4a97910c --- /dev/null +++ b/data/Entity.Database/Identity/Tables/AspNetRoles.sql @@ -0,0 +1,11 @@ +CREATE TABLE [Identity].[AspNetRoles] ( + [Id] NVARCHAR (128) CONSTRAINT [DF_AspNetRoles_Id] DEFAULT ('') NOT NULL, + [Name] NVARCHAR (256) CONSTRAINT [DF_AspNetRoles_Name] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_AspNetRoles_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_AspNetRoles_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_AspNetRoles] PRIMARY KEY CLUSTERED ([Id] ASC) +); +GO +CREATE UNIQUE NONCLUSTERED INDEX [RoleNameIndex] + ON [Identity].[AspNetRoles]([Name] ASC); + diff --git a/data/Entity.Database/Identity/Tables/AspNetUserClaims.sql b/data/Entity.Database/Identity/Tables/AspNetUserClaims.sql new file mode 100644 index 00000000..38c065dc --- /dev/null +++ b/data/Entity.Database/Identity/Tables/AspNetUserClaims.sql @@ -0,0 +1,16 @@ +CREATE TABLE [Identity].[AspNetUserClaims] ( + [Id] INT IDENTITY (1, 1) NOT NULL, + [UserId] NVARCHAR (128) CONSTRAINT [DF_AspNetUserClaims_UserId] DEFAULT ('') NOT NULL, + [ClaimType] NVARCHAR (MAX) NULL, + [ClaimValue] NVARCHAR (MAX) NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_AspNetUserClaims_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_AspNetUserClaims_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PKAspNetUserClaims] PRIMARY KEY CLUSTERED ([Id] ASC), + CONSTRAINT [FKAspNetUserClaimsAspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [Identity].[AspNetUsers] ([Id]) ON DELETE CASCADE +); + + +GO +CREATE NONCLUSTERED INDEX [IX_UserId] + ON [Identity].[AspNetUserClaims]([UserId] ASC); + diff --git a/data/Entity.Database/Identity/Tables/AspNetUserLogins.sql b/data/Entity.Database/Identity/Tables/AspNetUserLogins.sql new file mode 100644 index 00000000..a5a42bbf --- /dev/null +++ b/data/Entity.Database/Identity/Tables/AspNetUserLogins.sql @@ -0,0 +1,13 @@ +CREATE TABLE [Identity].[AspNetUserLogins] ( + [LoginProvider] NVARCHAR (128) CONSTRAINT [DF_AspNetUserLogins_LoginProvider] DEFAULT ('') NOT NULL, + [ProviderKey] NVARCHAR (128) CONSTRAINT [DF_AspNetUserLogins_ProviderKey] DEFAULT ('') NOT NULL, + [UserId] NVARCHAR (128) CONSTRAINT [DF_AspNetUserLogins_UserId] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_AspNetUserLogins_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_AspNetUserLogins_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PKAspNetUserLogins] PRIMARY KEY CLUSTERED ([LoginProvider] ASC, [ProviderKey] ASC, [UserId] ASC), + CONSTRAINT [FKAspNetUserLoginsAspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [Identity].[AspNetUsers] ([Id]) ON DELETE CASCADE +); +GO +CREATE NONCLUSTERED INDEX [IX_UserId] + ON [Identity].[AspNetUserLogins]([UserId] ASC); + diff --git a/data/Entity.Database/Identity/Tables/AspNetUserRoles.sql b/data/Entity.Database/Identity/Tables/AspNetUserRoles.sql new file mode 100644 index 00000000..1682d608 --- /dev/null +++ b/data/Entity.Database/Identity/Tables/AspNetUserRoles.sql @@ -0,0 +1,20 @@ +CREATE TABLE [Identity].[AspNetUserRoles] ( + [UserId] NVARCHAR (128) CONSTRAINT [DF_AspNetUserRoles_UserId] DEFAULT ('') NOT NULL, + [RoleId] NVARCHAR (128) CONSTRAINT [DF_AspNetUserRoles_RoleId] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_AspNetUserRoles_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_AspNetUserRoles_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PKAspNetUserRoles] PRIMARY KEY CLUSTERED ([UserId] ASC, [RoleId] ASC), + CONSTRAINT [FKAspNetUserRolesAspNetRoles_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [Identity].[AspNetRoles] ([Id]) ON DELETE CASCADE, + CONSTRAINT [FKAspNetUserRolesAspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [Identity].[AspNetUsers] ([Id]) ON DELETE CASCADE +); + + +GO +CREATE NONCLUSTERED INDEX [IX_UserId] + ON [Identity].[AspNetUserRoles]([UserId] ASC); + + +GO +CREATE NONCLUSTERED INDEX [IX_RoleId] + ON [Identity].[AspNetUserRoles]([RoleId] ASC); + diff --git a/data/Entity.Database/Identity/Tables/AspNetUsers.sql b/data/Entity.Database/Identity/Tables/AspNetUsers.sql new file mode 100644 index 00000000..965b75e7 --- /dev/null +++ b/data/Entity.Database/Identity/Tables/AspNetUsers.sql @@ -0,0 +1,27 @@ +CREATE TABLE [Identity].[AspNetUsers] ( + [Id] NVARCHAR (128) NOT NULL CONSTRAINT [DF_AspNetUsers_Id] DEFAULT (''), + [Email] NVARCHAR (256) NULL CONSTRAINT [DF_AspNetUsers_Email] DEFAULT (''), + [EmailConfirmed] BIT NOT NULL CONSTRAINT [DF_AspNetUsers_EmailConfirmed] DEFAULT (0), + [PasswordHash] NVARCHAR (MAX) NULL, + [SecurityStamp] NVARCHAR (MAX) NULL, + [PhoneNumber] NVARCHAR (MAX) NULL, + [PhoneNumberConfirmed] BIT NOT NULL CONSTRAINT [DF_AspNetUsers_PhoneNumberConfirmed] DEFAULT (0), + [TwoFactorEnabled] BIT NOT NULL CONSTRAINT [DF_AspNetUsers_TwoFactorEnabled] DEFAULT (0), + [LockoutEndDateUtc] DATETIME NULL, + [LockoutEnabled] BIT NOT NULL CONSTRAINT [DF_AspNetUsers_LockoutEnabled] DEFAULT (0), + [AccessFailedCount] INT NOT NULL CONSTRAINT [DF_AspNetUsers_AccessFailedCount] DEFAULT ('-1'), + [Username] NVARCHAR (256) NOT NULL CONSTRAINT [DF_AspNetUsers_Username] DEFAULT (''), + [EntityId] INT NOT NULL CONSTRAINT [DF_AspNetUsers_Entity] DEFAULT ('-1'), + [CreatedActivityId] INT NOT NULL CONSTRAINT [DF_AspNetUsers_CreatedActivity] DEFAULT ('-1'), + [ModifiedActivityId] INT NOT NULL CONSTRAINT [DF_AspNetUsers_ModifiedActivity] DEFAULT ('-1'), + [CreatedDate] DATETIME NOT NULL CONSTRAINT [DF_AspNetUsers_CreatedDate] DEFAULT (getutcdate()), + [ModifiedDate] DATETIME NOT NULL CONSTRAINT [DF_AspNetUsers_ModifiedDate] DEFAULT (getutcdate()), + CONSTRAINT [PKAspNetUsers] PRIMARY KEY CLUSTERED ([Id] ASC), +); +GO +CREATE UNIQUE NONCLUSTERED INDEX [IDX_AspNetUsers_Username] + ON [Identity].[AspNetUsers]([Username] ASC); +GO +CREATE NONCLUSTERED INDEX [IDX_AspNetUsers_Email] + ON [Identity].[AspNetUsers]([Email] ASC); +GO \ No newline at end of file diff --git a/data/Entity.Database/Identity/Tables/__MigrationHistory.sql b/data/Entity.Database/Identity/Tables/__MigrationHistory.sql new file mode 100644 index 00000000..2a13151f --- /dev/null +++ b/data/Entity.Database/Identity/Tables/__MigrationHistory.sql @@ -0,0 +1,8 @@ +CREATE TABLE [Identity].[__MigrationHistory] ( + [MigrationId] NVARCHAR (150) NOT NULL, + [ContextKey] NVARCHAR (300) NOT NULL, + [Model] VARBINARY (MAX) NOT NULL, + [ProductVersion] NVARCHAR (32) NOT NULL, + CONSTRAINT [PK_MigrationHistory] PRIMARY KEY CLUSTERED ([MigrationId] ASC, [ContextKey] ASC) +); + diff --git a/data/Entity.Database/Properties/AssemblyInfo.cs b/data/Entity.Database/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..d9e5762f --- /dev/null +++ b/data/Entity.Database/Properties/AssemblyInfo.cs @@ -0,0 +1,28 @@ +using System.Reflection; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with the SQLCLR assembly. +[assembly: AssemblyTitle("GoodToCode Entities EntityData Database")] +[assembly: AssemblyDescription("GoodToCode Entities powers your resuable framework for your .Net Core PCL/libraries, Universal x-platform mobile apps and all .Net Full libraries and apps.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("GoodToCode")] +[assembly: AssemblyProduct("GoodToCode Entities EntityData Database")] +[assembly: AssemblyCopyright("Copyright © 2017 GoodToCode. All rights reserved.")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("3.17.06")] +[assembly: AssemblyFileVersion("3.17.06")] + +// MUST add this to every AssemblyInfo.cs that wants to be compliant +[assembly: System.CLSCompliant(true)] diff --git a/data/Entity.Database/Scripts/Data/GoodToCodeData.sql b/data/Entity.Database/Scripts/Data/GoodToCodeData.sql new file mode 100644 index 00000000..d20b5591 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/GoodToCodeData.sql @@ -0,0 +1,63 @@ +--- +-- GoodToCodeData: Inserts all GoodToCode data, and one sandbox applicationId associated to GoodToCode. +--- + +-------------------------------------------------------------- +-- Initialize +-------------------------------------------------------------- +Declare @EntityKey UNIQUEIDENTIFIER = N'CF4D5026-958F-440E-8DFE-342DD48C5AFE' +Declare @SandboxApplicationKey UNIQUEIDENTIFIER = N'1EE3F6EC-59A7-4FD3-91D7-22AE3E20D412' +Declare @ActiveSoversApplicationKey UNIQUEIDENTIFIER = N'3C272F13-FB34-4550-BD09-6BE825ACB485' +Declare @FrameworkModuleKey UNIQUEIDENTIFIER = N'FED60864-3604-407E-8379-BEA5823F7CA1' +Declare @FlowStepKey Uniqueidentifier = '3767f875-7e3d-4f12-b85d-61e31e6d43f1' + +-------------------------------------------------------------- +-- Entity - Need for all other records +-------------------------------------------------------------- +Use [EntityData] +MERGE INTO [Entity].[Entity] AS Target +USING (VALUES + (@EntityKey) + ) + AS Source ([EntityKey]) +ON Target.[EntityKey] = Source.[EntityKey] +WHEN NOT MATCHED BY TARGET THEN + INSERT ([EntityKey]) + VALUES (Source.[EntityKey]) +; + +-------------------------------------------------------------- +-- Application - Need for all other records +-------------------------------------------------------------- +-- Application Record +Use [EntityData] +MERGE INTO [Entity].[Application] AS Target +USING (VALUES + (@SandboxApplicationKey, @EntityKey, N'GoodToCode Sandbox App', N'GoodToCode Sandbox App for development and testing', N'http://www.GoodToCode.com/Policy/Privacy.html', N'http://www.GoodToCode.com/Policy/Terms.html', GetUTCDate()) + ) + AS Source ([ApplicationKey], [BusinessEntityKey], [ApplicationName], [ApplicationSlogan], [PrivacyUrl], [TermsUrl], [TermsRevisedDate]) +ON Target.[ApplicationKey] = Source.[ApplicationKey] +WHEN MATCHED THEN + UPDATE SET [ApplicationName] = Source.[ApplicationName], [ApplicationSlogan] = Source.[ApplicationSlogan], [PrivacyUrl] = Source.[PrivacyUrl], [TermsUrl] = Source.[TermsUrl], [TermsRevisedDate] =Source.[TermsRevisedDate] +WHEN NOT MATCHED BY TARGET THEN + INSERT ([ApplicationKey], [BusinessEntityKey], [ApplicationName], [ApplicationSlogan], [PrivacyUrl], [TermsUrl], [TermsRevisedDate]) + VALUES (Source.[ApplicationKey], Source.[BusinessEntityKey], Source.[ApplicationName], Source.[ApplicationSlogan], Source.[PrivacyUrl], Source.[TermsUrl], Source.[TermsRevisedDate]) +; + +-------------------------------------------------------------- +-- Business +-------------------------------------------------------------- +-- Business Record +Use [EntityData] +MERGE INTO [Entity].[Business] AS Target +USING (VALUES + (@EntityKey, N'GoodToCode') + ) + AS Source ([BusinessKey], [BusinessName]) +ON Target.[BusinessKey] = Source.[BusinessKey] +WHEN MATCHED THEN + UPDATE SET [BusinessName] = Source.[BusinessName] +WHEN NOT MATCHED BY TARGET THEN + INSERT ([BusinessKey], [BusinessName]) + VALUES (Source.[BusinessKey], Source.[BusinessName]) +; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Master/EventGroup.sql b/data/Entity.Database/Scripts/Data/Master/EventGroup.sql new file mode 100644 index 00000000..b628941c --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Master/EventGroup.sql @@ -0,0 +1,23 @@ +-------------------------------------------------------------- +-- Event +-------------------------------------------------------------- +-- Event Group +MERGE INTO [Entity].[EventGroup] AS Target +USING (VALUES + (N'00000000-0000-0000-0000-000000000000', N'None', N'No group (default.)'), + (N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Get Together', N'Get together for a personal event. Has invite emails. Has RSVP.'), + (N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Meeting', N'Recurring meeting. Initial invite email. Has RSVP.'), + (N'784e9cd6-aa75-4023-9220-b40318733339', N'Experience', N'Personal experience. Does not have invite emails. No RSVP.'), + (N'11ad3246-967f-4318-b82b-b8496772db84', N'Public', N'Public event without invite emails. Has RSVP.') + ) +AS Source ([EventGroupKey], [EventGroupName], [EventGroupDescription]) +ON Target.[EventGroupKey] = Source.[EventGroupKey] +-- Update +WHEN MATCHED THEN + UPDATE SET [EventGroupName] = Source.[EventGroupName], [EventGroupDescription] = Source.[EventGroupDescription] +-- Insert +WHEN NOT MATCHED BY TARGET THEN + INSERT ([EventGroupKey], [EventGroupName], [EventGroupDescription]) Values (Source.[EventGroupKey], Source.[EventGroupName], Source.[EventGroupDescription]) +-- This table drives workflows and UIs. Must not be extended without inner working knowledge. +WHEN NOT MATCHED BY SOURCE THEN + DELETE; diff --git a/data/Entity.Database/Scripts/Data/Master/Gender.sql b/data/Entity.Database/Scripts/Data/Master/Gender.sql new file mode 100644 index 00000000..7cb263a0 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Master/Gender.sql @@ -0,0 +1,23 @@ +-------------------------------------------------------------- +-- Genders - Global data to all products +-------------------------------------------------------------- +-- ISO 5218 Genders +MERGE INTO [Entity].[Gender] AS Target +USING (VALUES (-1, N'00000000-0000-0000-0000-000000000000', N'', N'Not Supplied') + ,(0, N'5273832D-99D7-4B45-A653-45A74C012AD4', N'U', N'Unknown') + ,(1, N'CCC10950-B71D-4223-BD01-86FF1B2449BC', N'M', N'Male') + ,(2, N'FC3B6DED-E71E-4DDE-825A-4B9319B50557', N'F', N'Female') + ,(9, N'9F9100E5-06DC-407D-B67E-EFCD4785901F', N'N', N'Not Applicable') + ) +AS Source ([GenderId], [GenderKey], [GenderCode], [GenderName]) + ON Target.[GenderId] = Source.[GenderId] +-- Update +WHEN MATCHED THEN + UPDATE SET [GenderCode] = Source.[GenderCode], + [GenderName] = Source.[GenderName] +-- Insert +WHEN NOT MATCHED BY TARGET THEN + INSERT ([GenderId], [GenderKey], [GenderCode], [GenderName]) + VALUES (Source.[GenderId], Source.[GenderKey], Source.[GenderCode], Source.[GenderName]) +WHEN NOT MATCHED BY SOURCE THEN + DELETE; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Master/RecordState.sql b/data/Entity.Database/Scripts/Data/Master/RecordState.sql new file mode 100644 index 00000000..194edc00 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Master/RecordState.sql @@ -0,0 +1,20 @@ +-------------------------------------------------------------- +-- RecordState - Global data to all products +-------------------------------------------------------------- +-- RecordState +MERGE INTO [Entity].[RecordState] AS Target +USING (VALUES (-1, N'00000000-0000-0000-0000-000000000000', N'Default') + ,(1, N'F3B57E0D-9213-425C-B86B-405E46EB37AA', N'Read-only') + ,(2, N'5A5DAEB7-235A-4E00-9AAB-99C1D96ED5B5', N'Historical') + ,(4, N'081C6A5B-0817-4161-A3AD-AD7924BEA874', N'Deleted') + ) +AS Source ([RecordStateId], [RecordStateKey], [RecordStateName]) + ON Target.[RecordStateKey] = Source.[RecordStateKey] +-- Update +WHEN MATCHED THEN + UPDATE SET [RecordStateName] = Source.[RecordStateName] +-- Insert +WHEN NOT MATCHED BY TARGET THEN + INSERT ([RecordStateId], [RecordStateKey], [RecordStateName]) VALUES (Source.[RecordStateId], Source.[RecordStateKey], Source.[RecordStateName]) +WHEN NOT MATCHED BY SOURCE THEN + DELETE; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Master/SettingType.sql b/data/Entity.Database/Scripts/Data/Master/SettingType.sql new file mode 100644 index 00000000..b03ebbc1 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Master/SettingType.sql @@ -0,0 +1,30 @@ +-------------------------------------------------------------- +-- Setting - Global data to all products +-------------------------------------------------------------- +-- SettingType +MERGE INTO [Setting].[SettingType] AS Target +USING (VALUES (N'4eb25417-be3e-e411-9419-00155d016607', N'URLSimple') + ,(N'f2c317fe-be3e-e411-9419-00155d016607', N'URLFacebook') + ,(N'f5c317fe-be3e-e411-9419-00155d016607', N'WebTitle') + ,(N'f8c317fe-be3e-e411-9419-00155d016607', N'WebDescription') + ,(N'fbc317fe-be3e-e411-9419-00155d016607', N'WebKeywords') + ,(N'fec317fe-be3e-e411-9419-00155d016607', N'FacebookAppID') + ,(N'01c417fe-be3e-e411-9419-00155d016607', N'FacebookPageID') + ,(N'04c417fe-be3e-e411-9419-00155d016607', N'FacebookAdminID') + ,(N'76c152bb-97a2-4238-b36d-03b63407fd27', N'BingMapKey') + ,(N'6815f709-ef40-4d65-b674-169a26f1275a', N'SiteURLFull') + ,(N'19d5bf05-605a-4dde-9f7d-4e9278c24ea3', N'SupportURLFull') + ,(N'f555fa17-83e9-48b9-a577-4ffa1c5d104b', N'BingAdID') + ,(N'd2178b48-55e6-4a02-ba3c-6ebbd534aecd', N'BingAdUnit') + ,(N'e3214338-b852-484f-959e-a37519bc2db2', N'SiteURLFriendly') + ) +AS Source ([SettingTypeKey], [SettingTypeName]) + ON Target.[SettingTypeKey] = Source.[SettingTypeKey] +-- Update +WHEN MATCHED THEN + UPDATE SET [SettingTypeName] = Source.[SettingTypeName] +-- Insert +WHEN NOT MATCHED BY TARGET THEN + INSERT ([SettingTypeKey], [SettingTypeName]) VALUES (Source.[SettingTypeKey], Source.[SettingTypeName]) +WHEN NOT MATCHED BY SOURCE THEN + DELETE; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Master/TimeCycle.sql b/data/Entity.Database/Scripts/Data/Master/TimeCycle.sql new file mode 100644 index 00000000..e89e2011 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Master/TimeCycle.sql @@ -0,0 +1,26 @@ +-------------------------------------------------------------- +-- TimeCycle - All common time cycles +-------------------------------------------------------------- +-- TimeCycle +MERGE INTO [Entity].[TimeCycle] AS Target +USING (VALUES + (N'00000000-0000-0000-0000-000000000000', N'Daily', 1, -1) + ,(N'B55CDC94-F9B6-4A45-BA46-13574AB35FF4', N'Weekdays', 5, -1) + ,(N'325F3E37-76E5-4070-8BF9-7486A2EB62D3', N'Weekends', 2, -1) + ,(N'F4C5AED5-4853-47E1-AA2C-A30F86F4A357', N'WeeklyDay', 7, -1) + ,(N'28C6DE9B-600A-45DC-90AE-01CB20CD9BA8', N'MonthDay', 31, -1) + ,(N'07424BEE-9C82-4893-85F3-2B1F5A3E5A67', N'MonthlyDayOfWeek', 7, 4) + ,(N'E9971F55-4715-4D23-8245-730575B74D1A', N'YearlyDayOfWeek', 7, 52) + ,(N'403E4772-655E-4129-87B3-058EDCF1E553', N'YearlyDay', 365, -1) + ) +AS Source ([TimeCycleKey], [TimeCycleName], [Days], [Interval]) + ON Target.[TimeCycleKey] = Source.[TimeCycleKey] +-- Update +WHEN MATCHED THEN + UPDATE SET [TimeCycleName] = Source.[TimeCycleName] +-- Insert +WHEN NOT MATCHED BY TARGET THEN + INSERT ([TimeCycleKey], [TimeCycleName], [Days], [Interval]) + VALUES (Source.[TimeCycleKey], Source.[TimeCycleName], Source.[Days], Source.[Interval]) +WHEN NOT MATCHED BY SOURCE THEN + DELETE; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Shared/DetailType.sql b/data/Entity.Database/Scripts/Data/Shared/DetailType.sql new file mode 100644 index 00000000..d2c1af12 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/DetailType.sql @@ -0,0 +1,27 @@ +-------------------------------------------------------------- +-- +-------------------------------------------------------------- +-- Group +MERGE INTO [Entity].[DetailType] AS Target +USING (VALUES + (N'ddc2033a-8977-49ca-85e9-1d780567f522', N'Web Site', N'Web Site'), + (N'0a9cb93c-79ab-440d-9681-2cb461afba66', N'Hours of Operation', N'Hours of Operation'), + (N'a74424d0-d392-4ce6-ab96-3619196ab3eb', N'Admission', N'Admission'), + (N'9c00e926-f4a6-402b-87c8-3647b54c7b55', N'How to Entity', N'How to Entity'), + (N'61363878-37fd-499a-943c-374650e31c3e', N'Directions', N'Directions'), + (N'57bc7b92-2d59-4252-b087-9d3ae2d7e172', N'More Info', N'More Info'), + (N'130aeffe-0162-4bd3-b8e1-fa6e82ff3377', N'Parking', N'Parking') + ) +AS Source ([DetailTypeKey], [DetailTypeName], [DetailTypeDescription]) +ON Target.[DetailTypeKey] = Source.[DetailTypeKey] +-- Update +WHEN MATCHED THEN + UPDATE SET [DetailTypeName] = Source.[DetailTypeName], [DetailTypeDescription] = Source.[DetailTypeDescription] +-- Insert +WHEN NOT MATCHED BY TARGET THEN + INSERT ([DetailTypeKey], [DetailTypeName], [DetailTypeDescription]) Values (Source.[DetailTypeKey], Source.[DetailTypeName], Source.[DetailTypeDescription]) +; -- Terminate here, when there is no DELETE logic +-- Delete: Do not delete, this is a multi-tenant database and each tenant's DB project will maintain it's own values +--WHEN NOT MATCHED BY SOURCE THEN + --DELETE; + diff --git a/data/Entity.Database/Scripts/Data/Shared/EventType.sql b/data/Entity.Database/Scripts/Data/Shared/EventType.sql new file mode 100644 index 00000000..a8bec88b --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/EventType.sql @@ -0,0 +1,71 @@ +-------------------------------------------------------------- +-- Event +-------------------------------------------------------------- +-- [EventType] +MERGE INTO [Entity].[EventType] AS Target +USING (VALUES + -- Generic get together + (N'00000000-0000-0000-0000-000000000000', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Get Together', N'Get Together'), + -- Personal Events + (N'502d9e5a-f88e-4a01-9d67-e3df7449d575', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Game on TV', N'Watch the game!'), + (N'3e61891d-6c29-41a4-a0bb-15149b4a0e14', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Dinner Party', N'Dinner Party'), + (N'afbd9678-4d6f-4963-b928-31cfdd473dd6', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Baby Shower', N'Baby Shower'), + (N'e0d07790-7780-4217-b2d4-410a7bdf0c2b', N'11ad3246-967f-4318-b82b-b8496772db84', N'Poker Party', N'Poker Party'), + (N'520db710-91ab-4d1c-b2af-415a06b807e5', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'BBQ', N'BBQ'), + (N'53e6b6c2-1ee4-4a3d-bcb9-419d4c196ee3', N'11ad3246-967f-4318-b82b-b8496772db84', N'Concert', N'Concert'), + (N'b1e32717-9042-4679-8e2f-4a2b9d6f7d10', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Birthday Party', N'Birthday Party'), + (N'2cf9433c-a739-4b5d-8e09-5128c480fb1a', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Bridal Shower', N'Bridal Shower'), + (N'851089a1-b4fc-4fad-8d6c-54291d5091bc', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Casino Night', N'Casino Night'), + (N'3b0c7553-6189-49c1-b055-568d1512add1', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Comedy Night', N'Comedy Club'), + (N'fc55aeaa-a438-4373-8d22-571177c2a282', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Costume Party', N'Costume Party'), + (N'f4b566cb-0e01-47f5-b65b-652c350f518b', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Family Friendly Party', N'Family Friendly Party'), + (N'14c5ffab-cc35-4f22-b73f-72080bc15977', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Girls'' Night', N'Girls'' Night'), + (N'15bafd63-6d98-407a-952c-792e6d12b990', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'House Party', N'House Party'), + (N'903f074b-3381-4930-8044-7d975da24013', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Housewarming', N'Housewarming'), + (N'9e658ab2-6ca8-407c-87a0-7e670f7002a3', N'11ad3246-967f-4318-b82b-b8496772db84', N'Conference', N'Conference'), + (N'3a71602b-62e2-4a21-9882-7fc46f85e6c5', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Pool Party', N'Pool Party'), + (N'585bd93a-71de-46c9-a9e5-827e0310e11c', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Potluck', N'Potluck'), + (N'09300ad4-f7b3-48ee-b779-890601ffcf8e', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Film Festival', N'Film Festival'), + (N'b6926133-9ab8-4bf0-8e85-8ac2fd4dab8f', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Soccer Game', N'Watch the game!'), + (N'f4ebca0f-da35-47fd-aedf-8c1790d1b7e3', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Stag Party', N'Stag Party'), + (N'3ec6b4cf-d5bb-4214-b501-8ef486905bef', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Football Game', N'Watch the Game'), + (N'1a2501e5-5d9b-4d7d-acae-9c40c52e7490', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Bite to Eat', N'Bite to Eat'), + (N'c4bb559b-bfbf-4a2d-922b-99c6dcb6f0ad', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Wedding', N'Wedding'), + (N'985e86ef-77b5-4540-ba7a-9ec74bd60fc6', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Fundraiser', N'Fundraiser'), + (N'c808443e-b792-4f4d-a7d4-a31afa6a586a', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Movie Night', N'Movie Time'), + -- Meetings + (N'96233d32-ce06-4095-8fb6-9240e635e7fa', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Tradition Promises (TP)', N'Tradition Promises (TP)'), + (N'f5936a2e-b9fa-4189-a9ca-9b884738cffe', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'BB Step Study (BS)', N'BB Step Study (BS)'), + (N'02871523-21ad-4216-bf35-9c94584be2ed', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Beginner (BG)', N'Beginner (BG)'), + (N'cca5f43b-56a5-49a1-ad27-272c2d827484', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Tradition (T)', N'Tradition (T)'), + (N'f39e2260-8c3b-4331-9418-a678d01368ab', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Big Book (BB)', N'Big Book (BB)'), + (N'3fa22688-cd40-4e55-8390-a6b87eb43b64', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Big Book/12 & 12 (SBS)', N'Big Book/12 & 12 (SBS)'), + (N'ea06a726-8ac5-4663-823d-b070f7ee215b', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Closed (C)', N'Closed (C)'), + (N'e3baeacf-4749-45eb-bb21-b2a38b93e707', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Beach Party', N'Beach Party'), + (N'c6ff1aec-4525-4013-9495-b4ee30516850', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Discussion (D)', N'Discussion (D)'), + (N'e19cd529-908b-4b07-a845-b95e4da5ee1c', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Cup of Coffee', N'Cup of Coffee'), + (N'dff3ff72-c7f3-410d-bdb0-bc6bb9898cc7', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Grapevine (GV)', N'Grapevine (GV)'), + (N'e9c2273f-8727-4cc6-b20f-bd4b6ca93820', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Living Sober (LS)', N'Living Sober (LS)'), + (N'79f42e96-7b93-4bb5-9cde-c625528582bb', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Gaming Party', N'Gaming Party'), + (N'db670998-d0a0-4ab1-9c17-cf590f051be5', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Open (O)', N'Open (O)'), + (N'2ecd30d4-8fe6-4ac3-89dd-df147a804d44', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Promises (P)', N'Promises (P)'), + (N'936162d9-317c-4ac8-81d5-e537146a80b7', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Hockey Game', N'Watch the game!'), + (N'5322f0c6-d32a-4e35-92fb-ebf42dfab9c7', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Baseball Game', N'Watch the game!'), + (N'aa5c0b60-837e-474c-903b-ec4d9d0d76ef', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Reflections (R)', N'Reflections (R)'), + (N'a203c6d2-3552-491b-ac5c-f5de162b9cf1', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Basketball Game', N'Watch the game!'), + (N'ac94a653-d43e-4ebe-b54b-f8ffe01127c0', N'26833573-f93c-47dc-9812-13a4ff7ddfb6', N'Game at the Stadium', N'Game at the Stadium'), + (N'49a97469-098a-4fd3-8c48-fab054e868be', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Speaker Discussion (SD)', N'Speaker Discussion (SD)'), + (N'0ac16b92-7da7-441b-8f38-fd081a6d221d', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Step (S)', N'Step (S)'), + (N'afc3f129-a11b-4df6-a664-fea900cd3807', N'5f1092f7-0199-4b5b-a92c-27f623d37ff4', N'Step/Tradition (ST)', N'Step/Tradition (ST)') + ) + AS Source ([EventTypeKey], [EventGroupKey], [EventTypeName], [EventTypeDescription]) + Join [Entity].[EventGroup] ET On Source.EventGroupKey = ET.EventGroupKey +ON Target.[EventTypeKey] = Source.[EventTypeKey] +-- Update +WHEN MATCHED THEN + UPDATE SET [EventGroupKey] = ET.[EventGroupKey], [EventTypeName] = Source.[EventTypeName], [EventTypeDescription] = Source.[EventTypeDescription] +-- Insert +WHEN NOT MATCHED BY TARGET THEN + INSERT ([EventTypeKey], [EventGroupKey], [EventTypeName], [EventTypeDescription]) + Values (Source.[EventTypeKey], ET.[EventGroupKey], Source.[EventTypeName], Source.[EventTypeDescription]) +; diff --git a/data/Entity.Database/Scripts/Data/Shared/Flow.sql b/data/Entity.Database/Scripts/Data/Shared/Flow.sql new file mode 100644 index 00000000..df7ec554 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/Flow.sql @@ -0,0 +1,35 @@ +-------------------------------------------------------------- +-- Flows +-------------------------------------------------------------- +MERGE INTO [Entity].[Flow] AS Target +USING (VALUES + -- Flow + (N'71C39399-6976-4620-9F24-CFC7FFA64B45', N'7814190A-255B-4032-A3C0-46B9EE54B3B2', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Sessionflow created', N'A session flow has been executed.', 3600, 720, 0) + -- People + ,(N'3C0217D8-33C1-4623-9D9E-1F615E936AAE', N'AA5CA555-23CE-4B8F-A1CA-6BBE2CF2C7E7', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Person Created', N'Person Created', 3600, 720, 1) + ,(N'29EE0791-A757-40B8-A918-3B81C07AC880', N'A06E4BDA-09B5-445E-A78B-F99003886AA5', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Person Profile Edited', N'Person Profile Edited', 3600, 720, 0) + ,(N'07079A37-0317-433D-9FDA-E29C42D123CA', N'A8E13DA0-1951-4C09-AE02-FC4906BC8E45', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Person Profile Viewed', N'Person Profile Viewed', 3600, 720, 0) + -- Business + ,(N'81BB8843-1707-416E-B5F3-0DFE319D120A', N'AA5CA555-23CE-4B8F-A1CA-6BBE2CF2C7E7', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Business Created', N'Business Created', 3600, 720, 1) + ,(N'4E885585-2133-443F-9E27-FEF4D374233A', N'A06E4BDA-09B5-445E-A78B-F99003886AA5', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Business Profile Edited', N'Business Profile Edited', 3600, 720, 0) + ,(N'E7F3181F-D9A2-46BF-934C-AFC403BB0979', N'A8E13DA0-1951-4C09-AE02-FC4906BC8E45', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Business Profile Viewed', N'Business Profile Viewed', 3600, 720, 0) + -- Events + ,(N'D6BA7173-5E28-40B0-B56E-C1C9BF3E7DF0', N'AA5CA555-23CE-4B8F-A1CA-6BBE2CF2C7E7', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Event Created', N'Event Created', 3600, 720, 0) + ,(N'BDCFB4CD-9125-41D7-9303-49B844E219F5', N'A06E4BDA-09B5-445E-A78B-F99003886AA5', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Event Info Changed', N'Event Info Changed', 3600, 720, 0) + ,(N'C23E767F-3AA1-4FFE-BFF2-7A23C1C54A4E', N'A06E4BDA-09B5-445E-A78B-F99003886AA5', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Event Detail Changed', N'Event Detail Changed', 3600, 720, 0) + ,(N'8083FF2D-1FBE-4B66-B64D-D4B1E1188AD2', N'A06E4BDA-09B5-445E-A78B-F99003886AA5', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Event Time/Location Changed', N'Event Time/Location Changed', 3600, 720, 0) + ,(N'FA038D4C-CC5B-4C41-8CE3-18AA0C3CAB7D', N'A8E13DA0-1951-4C09-AE02-FC4906BC8E45', N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Event Viewed', N'Event Viewed', 3600, 720, 0) + ) + AS Source ([FlowKey], [FlowTypeKey], [ModuleKey], [FlowName], [FlowDescription], [TimeoutInSeconds], [RecordDeleteInMinutes], [NonRepeatable]) + Join [Entity].[FlowType] FT On Source.FlowTypeKey = FT.FlowTypeKey + Join [Entity].[Module] M On Source.ModuleKey = M.ModuleKey +ON Target.[FlowKey] = Source.[FlowKey] +-- Update +WHEN MATCHED THEN +UPDATE SET [FlowTypeKey] = FT.[FlowTypeKey], [ModuleKey] = M.[ModuleKey], [FlowName] = Source.[FlowName], [FlowDescription] = Source.[FlowDescription], + [TimeoutInSeconds] = Source.[TimeoutInSeconds], [RecordDeleteInMinutes] = Source.[RecordDeleteInMinutes], [NonRepeatable] = Source.[NonRepeatable] +-- Insert +WHEN NOT MATCHED BY TARGET THEN +INSERT ([FlowKey], [FlowTypeKey], [ModuleKey], [FlowName], [FlowDescription], [TimeoutInSeconds], [RecordDeleteInMinutes], [NonRepeatable]) + Values (Source.[FlowKey], FT.[FlowTypeKey], M.[ModuleKey], Source.[FlowName], Source.[FlowDescription], Source.[TimeoutInSeconds], Source.[RecordDeleteInMinutes], Source.[NonRepeatable]) +; diff --git a/data/Entity.Database/Scripts/Data/Shared/FlowSequence.sql b/data/Entity.Database/Scripts/Data/Shared/FlowSequence.sql new file mode 100644 index 00000000..eb0d224d --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/FlowSequence.sql @@ -0,0 +1,20 @@ +---------------------------------------------------------------- +---- SessionflowSequence +---------------------------------------------------------------- +---- [SessionflowSequence] +--MERGE INTO [Entity].[SessionflowSequence] AS Target +--USING (VALUES +-- (newID(), N'Fictional Step 1', N'Description for fictional step 1.', FIRST_SESSIONFLOW_STEP_Id, 0), +-- (newID(), N'Fictional Step 2', N'Description for fictional step 2.', NEXT_SESSIONFLOW_STEP_Id, 1), +-- (newID(), N'Fictional Step 3', N'Description for fictional step 3.', FINAL_SESSIONFLOW_STEP_Id, 2) +-- ) +--AS Source ([SessionflowSequenceKey], [FlowKey], [SessionflowStepKey], [SortOrder]) +--ON Target.[SessionflowStepKey] = Source.[SessionflowStepKey] +---- Update +--WHEN MATCHED THEN +--UPDATE SET [FlowKey] = Source.[FlowKey], [SessionflowStepKey] = Source.[SessionflowStepKey], [SortOrder] = Source.[SortOrder] +---- Insert +--WHEN NOT MATCHED BY TARGET THEN +--INSERT ([SessionflowSequenceKey], [FlowKey], [SessionflowStepKey], [SortOrder]) +-- Values (Source.[SessionflowSequenceKey],Source. [FlowKey], Source.[SessionflowStepKey], Source.[SortOrder]) +--; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Shared/FlowStep.sql b/data/Entity.Database/Scripts/Data/Shared/FlowStep.sql new file mode 100644 index 00000000..dffd30c2 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/FlowStep.sql @@ -0,0 +1,25 @@ +-------------------------------------------------------------- +-- Workflow +-------------------------------------------------------------- +-- [FlowStep] +MERGE INTO [Entity].[FlowStep] AS Target +USING (VALUES + (N'00000000-0000-0000-0000-000000000000', N'Unprocessed', N'Unprocessed. This should always be the first step in any workflow.') + ,(N'e18ee532-2431-40f3-b696-2435fa7720a4', N'Pending Next Step', N'Pending another step, defined by the process data condition.') + ,(N'05f52306-143e-4a28-a669-5370428bcb32', N'Failed: Completed Previously', N'This workflow can not be ran twice.') + ,(N'8eef8d96-9dbe-449b-9eae-a2e6d34f7e90', N'Failed: Validation Failed', N'Not validated exception. Failed workflow.') + ,(N'8f952f23-5289-4bbd-82c5-1677a8f38858', N'Failed: Payment Failed', N'Payment failed exception. Failed workflow.') + ,(N'dcbca742-564c-40a8-b6c1-1d8211ac7297', N'Failed: Not Authorized', N'Not authorized exception. Failed workflow.') + ,(N'b6d4a2aa-d503-4200-b1c0-009629d7d6b9', N'Failed: Unexpected Exception', N'Unexpected exception. Failed workflow.') + ,(N'3767f875-7e3d-4f12-b85d-61e31e6d43f1', N'Completed', N'Completed. This should always be the last step in any workflow.') + ) +AS Source ([FlowStepKey], [FlowStepName], [FlowStepDescription]) +ON Target.[FlowStepKey] = Source.[FlowStepKey] +-- Update +WHEN MATCHED THEN +UPDATE SET [FlowStepName] = Source.[FlowStepName], [FlowStepDescription] = Source.[FlowStepDescription] +-- Insert +WHEN NOT MATCHED BY TARGET THEN +INSERT ([FlowStepKey], [FlowStepName], [FlowStepDescription]) + Values (Source.[FlowStepKey], Source.[FlowStepName], Source.[FlowStepDescription]) +; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Shared/FlowType.sql b/data/Entity.Database/Scripts/Data/Shared/FlowType.sql new file mode 100644 index 00000000..c3b9e4d4 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/FlowType.sql @@ -0,0 +1,22 @@ +-------------------------------------------------------------- +-- Workflow +-------------------------------------------------------------- +-- [FlowType] +MERGE INTO [Entity].[FlowType] AS Target +USING (VALUES + (N'7814190A-255B-4032-A3C0-46B9EE54B3B2', N'Sessionflow', N'Sessionflow created'), + (N'AA5CA555-23CE-4B8F-A1CA-6BBE2CF2C7E7', N'Entity Created', N'Entity (Person, Business or Event) Created'), + (N'A06E4BDA-09B5-445E-A78B-F99003886AA5', N'Entity Edited', N'Entity (Person, Business or Event) Edited'), + (N'A8E13DA0-1951-4C09-AE02-FC4906BC8E45', N'Entity Viewed', N'Entity (Person, Business or Event) Viewed'), + (N'021557FD-DD8E-4F00-8C68-3D2200E32055', N'Entity Printed', N'Entity (Person, Business or Event) Printed') + ) +AS Source ([FlowTypeKey], [FlowTypeName], [FlowTypeDescription]) +ON Target.[FlowTypeKey] = Source.[FlowTypeKey] +-- Update +WHEN MATCHED THEN +UPDATE SET [FlowTypeName] = Source.[FlowTypeName], [FlowTypeDescription] = Source.[FlowTypeDescription] +-- Insert +WHEN NOT MATCHED BY TARGET THEN +INSERT ([FlowTypeKey], [FlowTypeName], [FlowTypeDescription]) + VALUES (Source.[FlowTypeKey], Source.[FlowTypeName], Source.[FlowTypeDescription]) +; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Data/Shared/Module.sql b/data/Entity.Database/Scripts/Data/Shared/Module.sql new file mode 100644 index 00000000..e80fa549 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/Module.sql @@ -0,0 +1,17 @@ +-------------------------------------------------------------- +-- Modules. +-------------------------------------------------------------- +MERGE INTO [Entity].[Module] AS Target +USING (VALUES + (N'FED60864-3604-407E-8379-BEA5823F7CA1', N'Framework Module', N'Framework Module with Person, Business, Event and all support entities.') + ) +AS Source ([ModuleKey], [ModuleName], [ModuleDescription]) +ON Target.[ModuleKey] = Source.[ModuleKey] +-- Update +WHEN MATCHED THEN +UPDATE SET [ModuleName] = Source.[ModuleName], [ModuleDescription] = Source.[ModuleDescription] +-- Insert +WHEN NOT MATCHED BY TARGET THEN +INSERT ([ModuleKey], [ModuleName], [ModuleDescription]) + VALUES (Source.[ModuleKey], Source.[ModuleName], Source.[ModuleDescription]) +; diff --git a/data/Entity.Database/Scripts/Data/Shared/Option.sql b/data/Entity.Database/Scripts/Data/Shared/Option.sql new file mode 100644 index 00000000..92384362 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/Option.sql @@ -0,0 +1,43 @@ +------------------------------------------------------------- +-- Properties +-------------------------------------------------------------- +-- [Option] +MERGE Into [EntityData].[Entity].[Option] AS Target +USING ( +VALUES + (N'98E871B9-8E3E-452D-A61D-275CA1F42657', N'3DBC544F-9331-4FB6-B7E0-710162B15E4D', N'Venture Admin', N'Venture Admin', N'VA', 3) + ,(N'A3509D25-E94F-4AEE-8598-5405679F4260', N'3DBC544F-9331-4FB6-B7E0-710162B15E4D', N'Venture Contributor', N'Venture Contributor', N'VC', 2) + ,(N'23DBF692-5216-45B2-80EC-7611CCCD0517', N'3DBC544F-9331-4FB6-B7E0-710162B15E4D', N'Venture Reader', N'Venture Reader', N'VR', 1) + ,(N'07B504A3-BE9E-4D49-9558-D3B6F82D525F', N'35B62540-E479-4430-A094-C57C4CFC5D16', N'Event Admin', N'Event Admin', N'EA', 3) + ,(N'8DD97CDE-1860-4C0A-917A-57D5752C1070', N'35B62540-E479-4430-A094-C57C4CFC5D16', N'Event Contributor', N'Event Contributor', N'EC', 2) + ,(N'19FC3855-7AEE-4A48-A78C-A83B75CFE4BC', N'35B62540-E479-4430-A094-C57C4CFC5D16', N'Event Reader', N'Event Reader', N'ER', 1) + ,(N'32c4a908-d63c-45e6-81c8-116b3a44d8df', N'b8605781-0627-4d57-ad9c-4830bfb5f0d5', N'Yes and they do not live at home', N'Yes and they do not live at home.', N'NH', 5) + ,(N'7c78aacf-7edb-461c-95b6-13b89541a618', N'6ffeda98-189d-4065-90f9-d6987702c4cb', N'Separated', N'Separated', N'Sep', 5) + ,(N'57745823-17cf-46a9-aa7f-370dcc7a5d4b', N'4e51ea04-1ac7-4623-9acf-cfd9cb4fab0c', N'Moderately', N'Moderately', N'Mod', 3) + ,(N'f57e9798-6e70-4887-9580-44cca5eed894', N'b997d822-c6d1-4c0f-877b-5d8e8aa6cc99', N'Male', N'Male', N'M', 1) + ,(N'080c18a0-8800-4459-b15e-50fec4af4cd4', N'4e51ea04-1ac7-4623-9acf-cfd9cb4fab0c', N'Never have', N'Never have', N'NH', 4) + ,(N'29e8cf65-521e-4ba3-a239-6b2eb6d7f34a', N'b8605781-0627-4d57-ad9c-4830bfb5f0d5', N'Yes and they sometimes live at home', N'Yes and they sometimes live at home.', N'Some', 4) + ,(N'4b81eb4a-15bd-4cc4-912f-845fda0930cc', N'6ffeda98-189d-4065-90f9-d6987702c4cb', N'Divorced', N'Divorced', N'Div', 4) + ,(N'461317fd-f7ce-4ab3-8c27-859a68c7d224', N'4e51ea04-1ac7-4623-9acf-cfd9cb4fab0c', N'Socially', N'Socially', N'Soc', 2) + ,(N'6f129903-3b96-4e73-ae28-8842eee3ded4', N'6ffeda98-189d-4065-90f9-d6987702c4cb', N'Widow/Widower', N'Widow/Widower', N'Wid', 6) + ,(N'49810f46-e1b0-47c8-a6ba-88bd2cabfa84', N'b8605781-0627-4d57-ad9c-4830bfb5f0d5', N'Not Specified', N'No', N'NS', 1) + ,(N'e1af6db7-3747-4727-aa6d-8a42372edd38', N'4e51ea04-1ac7-4623-9acf-cfd9cb4fab0c', N'Sober in recovery', N'Sober in recovery', N'Sob', 5) + ,(N'1c8a6922-e186-452e-9204-95b7d4e17c23', N'b8605781-0627-4d57-ad9c-4830bfb5f0d5', N'Yes and they always live at home', N'Yes and they always live at home.', N'Hom', 3) + ,(N'd8969ac8-1f58-406a-b89c-9acf811f6392', N'6ffeda98-189d-4065-90f9-d6987702c4cb', N'Married', N'Married', N'Mar', 3) + ,(N'b2840a53-c0d6-47bd-be54-aa0dacb2ba61', N'b8605781-0627-4d57-ad9c-4830bfb5f0d5', N'No', N'No', N'N', 2) + ,(N'7f21986a-c0ba-439d-9b60-c37437d9c1bd', N'b997d822-c6d1-4c0f-877b-5d8e8aa6cc99', N'Female', N'Female', N'F', 21) + ,(N'250d907c-77c7-4bc0-b6e6-e6d96e437edd', N'4e51ea04-1ac7-4623-9acf-cfd9cb4fab0c', N'Not Specified', N'Not Specified', N'NS', 1) + ,(N'5d360eda-cb09-4e71-b650-ecff0dc51850', N'6ffeda98-189d-4065-90f9-d6987702c4cb', N'Not Specified', N'Not Specified', N'NS', 1) + ,(N'51e83e1e-5cc1-4e02-9656-f12559b54753', N'6ffeda98-189d-4065-90f9-d6987702c4cb', N'Never Married', N'Never Married', N'Nev', 2) + ) +AS Source ([OptionKey], [OptionGroupKey], [OptionName], [OptionDescription], [OptionCode], [SortOrder]) +Join [EntityData].[Entity].[OptionGroup] PG On Source.OptionGroupKey = PG.OptionGroupKey +ON Target.[OptionKey] = Source.[OptionKey] +-- Update +WHEN MATCHED THEN +UPDATE SET [OptionGroupKey] = PG.[OptionGroupKey], [OptionName] = Source.[OptionName], [OptionDescription] = Source.[OptionDescription], [OptionCode] = Source.[OptionCode] +-- Insert +WHEN NOT MATCHED BY TARGET THEN +INSERT ([OptionKey], [OptionGroupKey], [OptionName], [OptionDescription], [OptionCode], [SortOrder]) + VALUES (Source.[OptionKey], PG.[OptionGroupKey], Source.[OptionName], Source.[OptionDescription], Source.[OptionCode], Source.[SortOrder]) +; -- Terminate here, when there is no DELETE logic diff --git a/data/Entity.Database/Scripts/Data/Shared/OptionGroup.sql b/data/Entity.Database/Scripts/Data/Shared/OptionGroup.sql new file mode 100644 index 00000000..f7861a8b --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/OptionGroup.sql @@ -0,0 +1,23 @@ +-------------------------------------------------------------- +-- Properties +-------------------------------------------------------------- +-- [OptionGroup] +MERGE Into [EntityData].[Entity].[OptionGroup] AS Target +USING (VALUES + (N'3DBC544F-9331-4FB6-B7E0-710162B15E4D', N'Venture Roles', N'Venture Roles', N'VRO') + ,(N'35B62540-E479-4430-A094-C57C4CFC5D16', N'Event Roles', N'Event Roles', N'ERO') + ,(N'b8605781-0627-4d57-ad9c-4830bfb5f0d5', N'Has Children', N'Has Children', N'KID') + ,(N'b997d822-c6d1-4c0f-877b-5d8e8aa6cc99', N'Gender', N'Gender', N'GEN') + ,(N'4e51ea04-1ac7-4623-9acf-cfd9cb4fab0c', N'Alcohol Use', N'Alcohol Use', N'DRI') + ,(N'6ffeda98-189d-4065-90f9-d6987702c4cb', N'Marital Status', N'Marital Status', N'MAR') + ) +AS Source ([OptionGroupKey], [OptionGroupName], [OptionGroupDescription], [OptionGroupCode]) +ON Target.[OptionGroupKey] = Source.[OptionGroupKey] +-- Update +WHEN MATCHED THEN +UPDATE SET [OptionGroupName] = Source.[OptionGroupName], [OptionGroupDescription] = Source.[OptionGroupDescription], [OptionGroupCode] = Source.[OptionGroupCode] +-- Insert +WHEN NOT MATCHED BY TARGET THEN +INSERT ([OptionGroupKey], [OptionGroupName], [OptionGroupDescription], [OptionGroupCode]) + VALUES (Source.[OptionGroupKey], Source.[OptionGroupName], Source.[OptionGroupDescription], Source.[OptionGroupCode]) +; -- Terminate here, when there is no DELETE logic diff --git a/data/Entity.Database/Scripts/Data/Shared/Setting.sql b/data/Entity.Database/Scripts/Data/Shared/Setting.sql new file mode 100644 index 00000000..881ea25d --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/Setting.sql @@ -0,0 +1,18 @@ +---------------------------------------------------------------- +---- Setting +---------------------------------------------------------------- +---- Settings + +--MERGE INTO [Setting].[Setting] AS Target +--USING (VALUES () +-- ) +--AS Source ([SettingKey], [SettingTypeKey], [SettingName], [SettingValue]) +--ON Target.[SettingKey] = Source.[SettingKey] +---- Update +--WHEN MATCHED THEN +-- UPDATE SET [SettingTypeKey] = Source.[SettingTypeKey] , [SettingName] = Source.[SettingName], [SettingValue] = Source.[SettingValue] +---- Insert +--WHEN NOT MATCHED BY TARGET THEN +-- INSERT ([SettingKey], [SettingTypeKey], [SettingName], [SettingValue]) +-- Values (Source.[SettingKey], Source.[SettingTypeKey], Source.[SettingName], Source.[SettingValue]) +--; -- No delete, terminate diff --git a/data/Entity.Database/Scripts/Data/Shared/SettingModule.sql b/data/Entity.Database/Scripts/Data/Shared/SettingModule.sql new file mode 100644 index 00000000..3194e65d --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/SettingModule.sql @@ -0,0 +1,20 @@ +-------------------------------------------------------------- +-- SettingModule +-------------------------------------------------------------- +-- +-- SettingsModule +-- +--MERGE INTO [Setting].[SettingModule] AS Target +--USING (VALUES ( +-- ) +--AS Source([SettingModuleKey], [SettingKey], [ModuleKey]) +--ON Target.[SettingModuleKey] = Source.[SettingModuleKey] +---- Update +--WHEN MATCHED THEN +-- UPDATE SET [SettingKey] = Source.[SettingKey], [ModuleKey] = Source.[ModuleKey] +---- Insert +--WHEN NOT MATCHED BY TARGET THEN +-- INSERT ([SettingModuleKey], [SettingKey], [ModuleKey]) +-- Values (Source.[SettingModuleKey], Source.[SettingKey], Source.[ModuleKey]) +--; -- No delete, terminate + diff --git a/data/Entity.Database/Scripts/Data/Shared/TimeType.sql b/data/Entity.Database/Scripts/Data/Shared/TimeType.sql new file mode 100644 index 00000000..0eba3815 --- /dev/null +++ b/data/Entity.Database/Scripts/Data/Shared/TimeType.sql @@ -0,0 +1,20 @@ +-------------------------------------------------------------- +-- Time +-------------------------------------------------------------- +-- [TimeType] +MERGE INTO [Entity].[TimeType] AS Target +USING (VALUES + (N'00000000-0000-0000-0000-000000000000', N'Available', N'Available', 1), + (N'DAF555C1-ACD9-42AE-870D-8907B3A6D8DB', N'Unavailable', N'Unavailable for use', -1), + (N'A832400B-3F9C-4AD4-AF29-5BE50079201C', N'Holiday', N'Holiday time slot', -1) + ) +AS Source ([TimeTypeKey], [TimeTypeName], [TimeTypeDescription], [TimeBehavior]) +ON Target.[TimeTypeKey] = Source.[TimeTypeKey] +-- Update +WHEN MATCHED THEN +UPDATE SET [TimeTypeName] = Source.[TimeTypeName], [TimeTypeDescription] = Source.[TimeTypeDescription], [TimeBehavior] = Source.[TimeBehavior] +-- Insert +WHEN NOT MATCHED BY TARGET THEN +INSERT ([TimeTypeKey], [TimeTypeName], [TimeTypeDescription], [TimeBehavior]) + VALUES (Source.[TimeTypeKey], Source.[TimeTypeName], Source.[TimeTypeDescription], Source.[TimeBehavior]) +; \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Environment/Dev.sql b/data/Entity.Database/Scripts/Environment/Dev.sql new file mode 100644 index 00000000..8f1dde3f --- /dev/null +++ b/data/Entity.Database/Scripts/Environment/Dev.sql @@ -0,0 +1,2 @@ +PRINT N'Environment-specific script: Dev.sql'; +-- Good place to script test records, ensure data is obfuscated, reconfigure environmental records diff --git a/data/Entity.Database/Scripts/Environment/Production.sql b/data/Entity.Database/Scripts/Environment/Production.sql new file mode 100644 index 00000000..ed68104a --- /dev/null +++ b/data/Entity.Database/Scripts/Environment/Production.sql @@ -0,0 +1,2 @@ +PRINT N'Environment-specific script: Production.sql'; +-- Good place to remove any test records, ensure integrity of publish, ensure environmental records point to production \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Environment/SQA.sql b/data/Entity.Database/Scripts/Environment/SQA.sql new file mode 100644 index 00000000..1821612e --- /dev/null +++ b/data/Entity.Database/Scripts/Environment/SQA.sql @@ -0,0 +1,2 @@ +PRINT N'Environment-specific script: SQA.sql'; +-- Good place to script test records, ensure data is obfuscated, reconfigure environmental records \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Environment/Staging.sql b/data/Entity.Database/Scripts/Environment/Staging.sql new file mode 100644 index 00000000..2a0a80d0 --- /dev/null +++ b/data/Entity.Database/Scripts/Environment/Staging.sql @@ -0,0 +1,2 @@ +PRINT N'Environment-specific script: Staging.sql'; +-- Good place to script test records, ensure data is obfuscated, reconfigure environmental records \ No newline at end of file diff --git a/data/Entity.Database/Scripts/Script.PostDeployment.sql b/data/Entity.Database/Scripts/Script.PostDeployment.sql new file mode 100644 index 00000000..a04343bf --- /dev/null +++ b/data/Entity.Database/Scripts/Script.PostDeployment.sql @@ -0,0 +1,35 @@ +/* +Post-Deployment Script Template +-------------------------------------------------------------------------------------- + This file contains SQL statements that will be appended to the build script. + Use SQLCMD syntax to include a file in the post-deployment script. + Example: :r .\myfile.sql + Use SQLCMD syntax to reference a variable in the post-deployment script. + Example: :setvar TableName MyTable + SELECT * FROM [$(TableName)] +--------------------------------------------------------------------------------------*/ +-- Master Data (this project is the only one updating the table x.) +:r .\Data\Master\EventGroup.sql +:r .\Data\Master\Gender.sql +:r .\Data\Master\RecordState.sql +:r .\Data\Master\SettingType.sql +:r .\Data\Master\TimeCycle.sql +-- Shared Data (multiple projects updating same table with different x.) +:r .\Data\Shared\DetailType.sql +:r .\Data\Shared\EventType.sql +:r .\Data\Shared\Flow.sql +:r .\Data\Shared\FlowSequence.sql +:r .\Data\Shared\FlowStep.sql +:r .\Data\Shared\FlowType.sql +:r .\Data\Shared\Module.sql +:r .\Data\Shared\Option.sql +:r .\Data\Shared\OptionGroup.sql +:r .\Data\Shared\Setting.sql +:r .\Data\Shared\SettingModule.sql +:r .\Data\Shared\TimeType.sql + +-- Any environment specific changes go here +:r .\Environment\$(TargetEnvironment).sql + +---- To be re-factored to "Enter your company name: " to generate records and basic test data +:r .\Data\GoodToCodeData.sql diff --git a/data/Entity.Database/Scripts/Script.PreDeployment.sql b/data/Entity.Database/Scripts/Script.PreDeployment.sql new file mode 100644 index 00000000..6a4524bc --- /dev/null +++ b/data/Entity.Database/Scripts/Script.PreDeployment.sql @@ -0,0 +1,11 @@ +/* + Pre-Deployment Script Template +-------------------------------------------------------------------------------------- + This file contains SQL statements that will be executed before the build script. + Use SQLCMD syntax to include a file in the pre-deployment script. + Example: :r .\myfile.sql + Use SQLCMD syntax to reference a variable in the pre-deployment script. + Example: :setvar TableName MyTable + SELECT * FROM [$(TableName)] +-------------------------------------------------------------------------------------- +*/ diff --git a/data/Entity.Database/Security/Activity.sql b/data/Entity.Database/Security/Activity.sql new file mode 100644 index 00000000..ee5ddaee --- /dev/null +++ b/data/Entity.Database/Security/Activity.sql @@ -0,0 +1,3 @@ +CREATE SCHEMA [Activity] + AUTHORIZATION [dbo]; + diff --git a/data/Entity.Database/Security/DBA.sql b/data/Entity.Database/Security/DBA.sql new file mode 100644 index 00000000..330f7528 --- /dev/null +++ b/data/Entity.Database/Security/DBA.sql @@ -0,0 +1,3 @@ +CREATE SCHEMA [DBA] + AUTHORIZATION [dbo]; + diff --git a/data/Entity.Database/Security/Entity.sql b/data/Entity.Database/Security/Entity.sql new file mode 100644 index 00000000..a4951027 --- /dev/null +++ b/data/Entity.Database/Security/Entity.sql @@ -0,0 +1,3 @@ +CREATE SCHEMA [Entity] + AUTHORIZATION [dbo]; + diff --git a/data/Entity.Database/Security/EntityCode.sql b/data/Entity.Database/Security/EntityCode.sql new file mode 100644 index 00000000..6c9c9c45 --- /dev/null +++ b/data/Entity.Database/Security/EntityCode.sql @@ -0,0 +1,3 @@ +CREATE SCHEMA [EntityCode] + AUTHORIZATION [dbo]; + diff --git a/data/Entity.Database/Security/Identity.sql b/data/Entity.Database/Security/Identity.sql new file mode 100644 index 00000000..3215f441 --- /dev/null +++ b/data/Entity.Database/Security/Identity.sql @@ -0,0 +1,3 @@ +CREATE SCHEMA [Identity] + AUTHORIZATION [dbo]; + diff --git a/data/Entity.Database/Security/Role_db_executor.sql b/data/Entity.Database/Security/Role_db_executor.sql new file mode 100644 index 00000000..a7547d8f --- /dev/null +++ b/data/Entity.Database/Security/Role_db_executor.sql @@ -0,0 +1,5 @@ +-- New role that allows Stored Procedure execution +CREATE ROLE db_executor +Go +GRANT EXECUTE TO db_executor +Go \ No newline at end of file diff --git a/data/Entity.Database/Security/Setting.sql b/data/Entity.Database/Security/Setting.sql new file mode 100644 index 00000000..68a95b39 --- /dev/null +++ b/data/Entity.Database/Security/Setting.sql @@ -0,0 +1,3 @@ +CREATE SCHEMA [Setting] + AUTHORIZATION [dbo]; + diff --git a/data/Entity.Database/Security/TestUser-Login.sql b/data/Entity.Database/Security/TestUser-Login.sql new file mode 100644 index 00000000..4b3f152d --- /dev/null +++ b/data/Entity.Database/Security/TestUser-Login.sql @@ -0,0 +1,4 @@ +CREATE LOGIN [TestUser] WITH PASSWORD=N'57595709-9E9C-47EA-ABBF-4F3BAA1B0D37'; +GO +--CREATE LOGIN [publish@goodtocode.com] WITH PASSWORD=N''; +--GO \ No newline at end of file diff --git a/data/Entity.Database/Security/TestUser-Roles.sql b/data/Entity.Database/Security/TestUser-Roles.sql new file mode 100644 index 00000000..5d787276 --- /dev/null +++ b/data/Entity.Database/Security/TestUser-Roles.sql @@ -0,0 +1,13 @@ +-- +-- ALTER ROLE +-- +ALTER ROLE [db_datareader] ADD MEMBER [TestUser]; +GO +ALTER ROLE [db_datawriter] ADD MEMBER [TestUser]; +GO +ALTER ROLE [db_executor] ADD MEMBER [TestUser]; +GO +GRANT CONNECT TO [TestUser] +GO +--GRANT CONNECT TO [Publish@goodtocode.com] +--GO \ No newline at end of file diff --git a/data/Entity.Database/Security/TestUser-User.sql b/data/Entity.Database/Security/TestUser-User.sql new file mode 100644 index 00000000..c3b59631 --- /dev/null +++ b/data/Entity.Database/Security/TestUser-User.sql @@ -0,0 +1,4 @@ +CREATE USER [TestUser] FOR LOGIN [TestUser] WITH DEFAULT_SCHEMA=[dbo] +GO +--CREATE USER [Publish@goodtocode.com] FOR LOGIN [Publish@goodtocode.com] WITH DEFAULT_SCHEMA=[dbo] +--GO \ No newline at end of file diff --git a/data/Entity.Database/Setting/Tables/ApplicationSetting.sql b/data/Entity.Database/Setting/Tables/ApplicationSetting.sql new file mode 100644 index 00000000..38cc3cda --- /dev/null +++ b/data/Entity.Database/Setting/Tables/ApplicationSetting.sql @@ -0,0 +1,12 @@ +CREATE TABLE [Setting].[ApplicationSetting] ( + [ApplicationSettingId] INT IDENTITY(1, 1) CONSTRAINT [DF_ApplicationSetting_ApplicationSettingId] NOT NULL, + [ApplicationSettingKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ApplicationSetting_Key] DEFAULT(NewId()) NOT NULL, + [SettingKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ApplicationSetting_Setting] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ApplicationKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ApplicationSetting_Application] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ApplicationSetting_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ApplicationSetting] PRIMARY KEY CLUSTERED ([ApplicationSettingId] ASC), + CONSTRAINT [FK_ApplicationSetting_Setting] FOREIGN KEY ([SettingKey]) REFERENCES [Setting].[Setting] ([SettingKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ApplicationSetting_Key] ON [Setting].[ApplicationSetting] ([ApplicationSettingKey] Asc) +GO diff --git a/data/Entity.Database/Setting/Tables/ModuleSetting.sql b/data/Entity.Database/Setting/Tables/ModuleSetting.sql new file mode 100644 index 00000000..90816a95 --- /dev/null +++ b/data/Entity.Database/Setting/Tables/ModuleSetting.sql @@ -0,0 +1,13 @@ +CREATE TABLE [Setting].[ModuleSetting] ( + [ModuleSettingId] INT IDENTITY(1,1) CONSTRAINT [DF_ModuleSetting_Id] NOT NULL, + [ModuleSettingKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ModuleSetting_Key] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [SettingKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ModuleSetting_Setting] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [ModuleKey] UNIQUEIDENTIFIER CONSTRAINT [DF_ModuleSetting_Module] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_ModuleSetting_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_ModuleSetting] PRIMARY KEY CLUSTERED ([ModuleSettingId] ASC), + CONSTRAINT [FK_ModuleSetting_Setting] FOREIGN KEY ([SettingKey]) REFERENCES [Setting].[Setting] ([SettingKey]), + CONSTRAINT [FK_ModuleSetting_Module] FOREIGN KEY ([ModuleKey]) REFERENCES [Entity].[Module] ([ModuleKey]) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_ModuleSetting_Key] ON [Setting].[ModuleSetting] ([ModuleSettingKey] Asc) +GO \ No newline at end of file diff --git a/data/Entity.Database/Setting/Tables/Setting.sql b/data/Entity.Database/Setting/Tables/Setting.sql new file mode 100644 index 00000000..76885ebd --- /dev/null +++ b/data/Entity.Database/Setting/Tables/Setting.sql @@ -0,0 +1,13 @@ +CREATE TABLE [Setting].[Setting] ( + [SettingId] INT IDENTITY(1, 1) CONSTRAINT [DF_Setting_Id] NOT NULL, + [SettingKey] UNIQUEIDENTIFIER CONSTRAINT [DF_Setting_Key] DEFAULT(NewId()) NOT NULL, + [SettingTypeKey] INT CONSTRAINT [DF_Setting_SettingTypeKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [SettingName] NVARCHAR (50) CONSTRAINT [DF_Setting_SettingName] DEFAULT ('') NOT NULL, + [SettingValue] NVARCHAR (200) CONSTRAINT [DF_Setting_SettingValue] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_Setting_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + [ModifiedDate] DATETIME CONSTRAINT [DF_Setting_ModifiedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_Setting] PRIMARY KEY CLUSTERED ([SettingId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_Setting_Key] ON [Setting].[Setting] ([SettingKey] Asc) +GO diff --git a/data/Entity.Database/Setting/Tables/SettingType.sql b/data/Entity.Database/Setting/Tables/SettingType.sql new file mode 100644 index 00000000..2bad0d21 --- /dev/null +++ b/data/Entity.Database/Setting/Tables/SettingType.sql @@ -0,0 +1,10 @@ +CREATE TABLE [Setting].[SettingType] ( + [SettingTypeId] INT IDENTITY(1, 1) CONSTRAINT [DF_SettingType_SettingTypeId] NOT NULL, + [SettingTypeKey] UNIQUEIDENTIFIER CONSTRAINT [DF_SettingType_SettingTypeKey] DEFAULT('00000000-0000-0000-0000-000000000000') NOT NULL, + [SettingTypeName] NVARCHAR (50) CONSTRAINT [DF_SettingType_SettingTypeName] DEFAULT ('') NOT NULL, + [CreatedDate] DATETIME CONSTRAINT [DF_SettingType_CreatedDate] DEFAULT (getutcdate()) NOT NULL, + CONSTRAINT [PK_SettingType] PRIMARY KEY CLUSTERED ([SettingTypeId] ASC) +); +GO +CREATE UNIQUE NonCLUSTERED INDEX [IX_SettingType_Key] ON [Setting].[SettingType] ([SettingTypeKey] Asc) +GO diff --git a/src/Subjects/Specs/Application.Unit/Usings.cs b/data/Entity.Queries/Activity.ActivityContext.sql similarity index 100% rename from src/Subjects/Specs/Application.Unit/Usings.cs rename to data/Entity.Queries/Activity.ActivityContext.sql diff --git a/data/Entity.Queries/Activity.Exception.sql b/data/Entity.Queries/Activity.Exception.sql new file mode 100644 index 00000000..9363123d --- /dev/null +++ b/data/Entity.Queries/Activity.Exception.sql @@ -0,0 +1,11 @@ +-- +-- Exception log +-- +Use FoundationData +Select Top 100 * + From Activity.ExceptionLog + Order By CreatedDate Desc + +Begin Tran +Delete From Activity.ExceptionLog Where CreatedDate < GetUTCDate() +Commit diff --git a/data/Entity.Queries/Activity_ActivityContext.sql b/data/Entity.Queries/Activity_ActivityContext.sql new file mode 100644 index 00000000..db528265 --- /dev/null +++ b/data/Entity.Queries/Activity_ActivityContext.sql @@ -0,0 +1,7 @@ +-- +-- Activity +-- +Use EntityData +Select Top 10 * +From [EntityData].Activity.ActivityContext +Order By CreatedDate desc diff --git a/data/Entity.Queries/Activity_ActivityLog.sql b/data/Entity.Queries/Activity_ActivityLog.sql new file mode 100644 index 00000000..b94328c4 --- /dev/null +++ b/data/Entity.Queries/Activity_ActivityLog.sql @@ -0,0 +1,18 @@ +-- +-- Activity +-- +Use EntityData +Select Top 10 * +From [EntityData].Activity.Activity +Where ActivityID Not In (Select ActivityID From [EntityData].Activity.ActivitySessionflow) +Order By ActivityID Desc + +-- table +Select top 10 * +From [EntityData].Activity.Activity + +-- view +Select top 10 * +From [EntityData].BaseCode.ActivitySessionflow + +Select newid() \ No newline at end of file diff --git a/data/Entity.Queries/Activity_ActivityQueryflow.sql b/data/Entity.Queries/Activity_ActivityQueryflow.sql new file mode 100644 index 00000000..3c412be3 --- /dev/null +++ b/data/Entity.Queries/Activity_ActivityQueryflow.sql @@ -0,0 +1,6 @@ +-- +-- Activity +-- +Use EntityData +Select Top 10 * +From [EntityData].Activity.ActivityContext diff --git a/data/Entity.Queries/Activity_ActivitySessionflow.sql b/data/Entity.Queries/Activity_ActivitySessionflow.sql new file mode 100644 index 00000000..7392e98b --- /dev/null +++ b/data/Entity.Queries/Activity_ActivitySessionflow.sql @@ -0,0 +1,11 @@ +-- +-- Activity +-- +Use EntityData +Go +Select Top 10 * +From [EntityData].Activity.ActivitySessionflow +Order By ActivitySessionflowId Desc + +EXECUTE EntityCode.ActivitySessionflowInsert @Key = 'ad9db056-1588-47c0-b654-293c0f65fda3', @FlowKey = '71c39399-6976-4620-9f24-cfc7ffa64b45', @DeviceUuid = '', @ApplicationUuid = '00000000-0000-0000-0000-000000000000', @ApplicationKey = '00000000-0000-0000-0000-000000000000', @EntityKey = '0b8ca756-ba87-4f44-bf0e-faa194898dd1', @IdentityUserName = 'DEV\rjgood', @SessionflowData = '' +EXECUTE EntityCode.ActivitySessionflowInsert @Key = '7d94f76b-9455-4893-b7f9-22d30f9cd11f', @FlowKey = '71c39399-6976-4620-9f24-cfc7ffa64b45', @DeviceUuid = '', @ApplicationUuid = '00000000-0000-0000-0000-000000000000', @ApplicationKey = '00000000-0000-0000-0000-000000000000', @EntityKey = '8cdcf93c-8923-4050-9485-0c8559f46d51', @IdentityUserName = '', @SessionflowData = '' \ No newline at end of file diff --git a/data/Entity.Queries/Activity_ActivityWorkflow.sql b/data/Entity.Queries/Activity_ActivityWorkflow.sql new file mode 100644 index 00000000..3c412be3 --- /dev/null +++ b/data/Entity.Queries/Activity_ActivityWorkflow.sql @@ -0,0 +1,6 @@ +-- +-- Activity +-- +Use EntityData +Select Top 10 * +From [EntityData].Activity.ActivityContext diff --git a/data/Entity.Queries/Activity_ExceptionLog.sql b/data/Entity.Queries/Activity_ExceptionLog.sql new file mode 100644 index 00000000..604c8767 --- /dev/null +++ b/data/Entity.Queries/Activity_ExceptionLog.sql @@ -0,0 +1,9 @@ +-- +-- Exception +-- +Use EntityData +Select Top 10 ExceptionLogID, Message, CreatedDate + From [Activity].[ExceptionLog] + Order by ExceptionLogID Desc + + EXECUTE EntityCode.ActivityWorkflowInsert @ActivitySessionflowKey = '00000000-0000-0000-0000-000000000000', @FlowKey = '71c39399-6976-4620-9f24-cfc7ffa64b45', @FlowStepKey = '00000000-0000-0000-0000-000000000000', @EntityKey = '1452d230-bd70-4c9c-a75b-f72609b66e35'} \ No newline at end of file diff --git a/data/Entity.Queries/Auth_Role.sql b/data/Entity.Queries/Auth_Role.sql new file mode 100644 index 00000000..a3abc49d --- /dev/null +++ b/data/Entity.Queries/Auth_Role.sql @@ -0,0 +1,25 @@ +-- +--Roles +-- +-- Role Default +Select E.EventGroupName, R.RoleName, G.RoleGroupName +From [EntityData].Auth.RoleEventDefault RE +Left Join [EntityData].[Entity].EventGroup E On E.EventGroupID = RE.EventGroupID +Left Join [EntityData].Auth.RoleGroup G On RE.RoleGroupID = G.RoleGroupID +Left Join [EntityData].Auth.Role R On RE.RoleID = R.RoleID +-- Role Event +Select E.EventName, R.RoleName, G.RoleGroupName +From [EntityData].Auth.RoleEvent RE +Left Join [EntityData].[Entity].Event E On E.EventID = RE.EventID +Left Join [EntityData].Auth.RoleGroup G On RE.RoleGroupID = G.RoleGroupID +Left Join [EntityData].Auth.Role R On RE.RoleID = R.RoleID + +-- Raw +Use EntityData +Select Top 10 * From [EntityData].Auth.RoleGroup +Select Top 10 * From [EntityData].Auth.Role +Select Top 10 * From [EntityData].Auth.RoleEvent +Select Top 10 * From [EntityData].Auth.RoleEventDefault + + +Select newid(), newid(), newid(), newid() \ No newline at end of file diff --git a/data/Entity.Queries/Auth_UserProfile.sql b/data/Entity.Queries/Auth_UserProfile.sql new file mode 100644 index 00000000..3837dd98 --- /dev/null +++ b/data/Entity.Queries/Auth_UserProfile.sql @@ -0,0 +1,61 @@ +-- +-- User Profile +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].dbo.[AspNetUsers] UP +--Left Join [EntityData].[Entity].Entity C On UP.EntityID = C.EntityID +--Left Join [EntityData].[Entity].[Person] P On C.PersonID = P.PersonID + +-- +-- Logon +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Entity].Entity +Select * +From [EntityData].[Entity].Logon +Select * +From [EntityData].[Entity].[Person] +Select * +From [EntityData].[Entity].LogonType + +Select * +From [EntityData].[Entity].WorkflowStep +Select * +From [EntityData].[Entity].WorkflowType +Select * +From [EntityData].[Entity].Workflow + +-- +-- Single user record +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select P.FirstNAme, P.LastName, L.UserName, L.AcceptedTermsDate, WS.WorkflowStepName +From [EntityData].[Entity].Entity C +Left Join [EntityData].[Entity].[Person] P On C.PersonID = P.PersonID +Left Join [EntityData].[Entity].Logon L On C.EntityID = L.EntityID +Left Join [EntityData].[Entity].WorkflowStep WS On L.WorkflowStepID = WS.WorkflowStepID + +-- Web logos +-- Exec [EntityData].DBA.ApplicationImageUpdate '3C272F13-FB34-4550-BD09-6BE825ACB485', 'ApplicationLogoSite', 'C:\Backup\Uploads\ActiveSobersLogo.jpg' + +-- +-- Application +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Entity].Application + +-- +-- Application Log +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select Top 100 * +From [EntityData].Log.ApplicationLog +Order By CreatedDate Desc diff --git a/data/Entity.Queries/Auth_Users.sql b/data/Entity.Queries/Auth_Users.sql new file mode 100644 index 00000000..aa91cb29 --- /dev/null +++ b/data/Entity.Queries/Auth_Users.sql @@ -0,0 +1,3 @@ +-- Azure creates disabled logins, enable now +ALTER LOGIN [TestUser] ENABLE +GO diff --git a/data/Entity.Queries/Authorization_UserProfile.sql b/data/Entity.Queries/Authorization_UserProfile.sql new file mode 100644 index 00000000..90e2bc0d --- /dev/null +++ b/data/Entity.Queries/Authorization_UserProfile.sql @@ -0,0 +1,62 @@ +-- +-- Application +-- +Use vGoEntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From vGo[EntityData].[Entity].Application + +-- +-- Application Log +-- +Use vGoEntityData +Set Transaction Isolation Level Read Uncommitted +Select Top 100 * +From vGo[EntityData].Log.ApplicationLog +Order By CreatedDate Desc + +-- +-- User Profile +-- +Use VGOSecurity +Set Transaction Isolation Level Read Uncommitted +Select * +From vGo[EntityData].Auth.[AspNetUsers] UP +Left Join vGo[EntityData].[Entity].Contact C On UP.ContactID = C.ContactID +Left Join vGo[EntityData].[Entity].[Person] P On C.PersonID = P.PersonID + +Select NewID() +-- +-- Logon +-- +Use vGoEntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From vGo[EntityData].[Entity].Contact +Select * +From vGo[EntityData].[Entity].Logon +Select * +From vGo[EntityData].[Entity].[Person] +Select * +From vGo[EntityData].[Entity].LogonType + +Select * +From vGo[EntityData].[Entity].WorkflowStep +Select * +From vGo[EntityData].[Entity].WorkflowType +Select * +From vGo[EntityData].[Entity].Workflow + +-- +-- Single user record +-- +Use vGoEntityData +Set Transaction Isolation Level Read Uncommitted +Select P.FirstNAme, P.LastName, L.UserName, L.AcceptedTermsDate, WS.WorkflowStepName +From vGo[EntityData].[Entity].Contact C +Left Join vGo[EntityData].[Entity].[Person] P On C.PersonID = P.PersonID +Left Join vGo[EntityData].[Entity].Logon L On C.ContactID = L.ContactID +Left Join vGo[EntityData].[Entity].WorkflowStep WS On L.WorkflowStepID = WS.WorkflowStepID + +-- Web logos +-- Exec vGo[EntityData].DBA.ApplicationImageUpdate '3C272F13-FB34-4550-BD09-6BE825ACB485', 'ApplicationLogoSite', 'C:\Backup\Uploads\ActiveSobersLogo.jpg' diff --git a/data/Entity.Queries/Core_Application.sql b/data/Entity.Queries/Core_Application.sql new file mode 100644 index 00000000..9d3eef59 --- /dev/null +++ b/data/Entity.Queries/Core_Application.sql @@ -0,0 +1,16 @@ +-- +-- Application +-- +-- App +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Entity].[Application] A + +-- +-- Module +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Entity].[Module] A diff --git a/data/Entity.Queries/Core_Appointment.sql b/data/Entity.Queries/Core_Appointment.sql new file mode 100644 index 00000000..97ee2964 --- /dev/null +++ b/data/Entity.Queries/Core_Appointment.sql @@ -0,0 +1,14 @@ + +-- +-- Appointment +-- +-- Appointment +Use EntityData +Go +Select Top 100 * +From [EntityData].[Entity].[Appointment] + +-- +-- Srored Procs +-- +EXECUTE EntityCode.AppointmentInfoSave @Id = '-1', @Key = 'a0299179-cf82-4dfb-bbb3-e8299ca6447a', @Name = 'Tutor After School', @Description = 'Meet you at the library for a tutor session.', @EventKey = '00000000-0000-0000-0000-000000000000', @LocationKey = '00000000-0000-0000-0000-000000000000', @BeginDate = '1/1/1900 12:00:00 AM', @EndDate = '1/1/1900 12:00:00 AM', @ActivityContextKey = 'f4a1ab5e-b15c-497e-9004-75c6e2236a14' \ No newline at end of file diff --git a/data/Entity.Queries/Core_Business.sql b/data/Entity.Queries/Core_Business.sql new file mode 100644 index 00000000..c6e65637 --- /dev/null +++ b/data/Entity.Queries/Core_Business.sql @@ -0,0 +1,23 @@ +-- +-- Business +-- +-- Business raw +Use EntityData +Go +Select Top 100 * +From [EntityData].[Entity].Business + +-- Business joined +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Entity].Entity C +Join [EntityData].[Entity].Business B On C.EntityKey = B.EntityKey + +-- +-- EntityCode +-- +-- BusinessInfoSave +Use EntityData +Go +EXECUTE EntityCode.BusinessInfoSave @Id = '-1', @Key = '668b984c-4dc1-40ad-bf8b-805742b76f32', @Name = 'Databook', @TaxNumber = '2005-2019', @ActivityContextKey = 'd52a609e-642d-41b9-8a01-0c306283da78' \ No newline at end of file diff --git a/data/Entity.Queries/Core_Contact.sql b/data/Entity.Queries/Core_Contact.sql new file mode 100644 index 00000000..4e5174f0 --- /dev/null +++ b/data/Entity.Queries/Core_Contact.sql @@ -0,0 +1,33 @@ +-- +--Entity +-- +-- Person +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From Entity.Entity C +Join [Entity].[Person] P On C.EntityID = P.EntityID +-- Business +Select * +From Entity.Entity C +Join [Entity].Business B On C.EntityID = B.EntityID +Select Newid() +-- +-- Property +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select PG.PropertyGroupName, P.PropertyID, P.PropertyName--, P.PropertyCode +From [EntityData].[Entity].PropertyGroup PG +Left Join [EntityData].[Entity].Property P On PG.PropertyGroupID = P.PropertyGroupID + +-- +-- Property Entity +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Entity].[Person] P +Join [EntityData].[Entity].[PropertyEntity] PC on P.EntityID = PC.EntityID +Join [EntityData].[Entity].Property Pr on PC.PropertyID = Pr.PropertyID + diff --git a/data/Entity.Queries/Core_DateTime.sql b/data/Entity.Queries/Core_DateTime.sql new file mode 100644 index 00000000..e69de29b diff --git a/data/Entity.Queries/Core_Event.sql b/data/Entity.Queries/Core_Event.sql new file mode 100644 index 00000000..f93a1890 --- /dev/null +++ b/data/Entity.Queries/Core_Event.sql @@ -0,0 +1,77 @@ +-- +--Events and Types +-- +-- Event +Use EntityData +Select * +From [EntityData].[Entity].[Event] +Where EventKey = Upper('e12f9427-4cca-4e5e-ab91-fa84a7ac5a3f') + OR CreatedActivityKey = '5bc191a3-cd9b-4f80-a681-5e6b1a68a669' + OR ModifiedActivityKey = '5bc191a3-cd9b-4f80-a681-5e6b1a68a669' +Order By CreatedDate Desc +EXECUTE EntityCode.EventInfoSave @Id = '-1', @Key = 'e12f9427-4cca-4e5e-ab91-fa84a7ac5a3f', @EventGroupKey = '00000000-0000-0000-0000-000000000000', @EventTypeKey = '00000000-0000-0000-0000-000000000000', @CreatorKey = 'e8d92591-f1d7-4521-a00a-7c6581f922f7', @Name = 'Tutor After School', @Description = 'Meet you at the library for a tutor session.', @Slogan = '', @ActivityContextKey = '5bc191a3-cd9b-4f80-a681-5e6b1a68a669' + +-- Event Groups +Use EntityData +Select G.EventGroupID, G.EventGroupName, T.EventTypeID, T.EventTypeName +From [EntityData].[Entity].[EventType] T +Join [EntityData].[Entity].[EventGroup] G On G.EventGroupKey = T.EventGroupKey +Order By G.EventGroupName, T.EventTypeName + +-- Event Groups +Use EntityData +Select * +From [EntityData].[Entity].[EventGroup] + +-- Type +Use EntityData +Select EventTypeID, EventTypeName +From [EntityData].[Entity].[EventType] +Where EventGroupID = '26833573-F93C-47DC-9812-13A4FF7DDFB6' +Order By EventGroupID, EventTypeName +-- Type Raw +Use EntityData +Select * +From [Entity].EventType + +-- Fix int for 00000000-0000-0000-0000-000000000000 +SET IDENTITY_INSERT [Entity].[EventType] ON +Update [Entity].[EventType] +Set EventTypeID = -1 +Where EventTypeGuid = '00000000-0000-0000-0000-000000000000' +SET IDENTITY_INSERT [Entity].[EventType] OFF + +-- Transactional +Use EntityData +Select * +From [EntityData].[Entity].EventCoordinator +Use EntityData +Select R.*, e.*, g.* +From [EntityData].[Entity].EventRSVP R +Left Join [EntityData].[Entity].Event E On R.EventID = E.EventID +Left Join [EntityData].Active.GuestListEntity G On R.GuestListEntityID = G.GuestListEntityID +Order By R.EventID + +Use EntityData +Select * +From [EntityData].[Entity].EventRSVPStatus +-- +--Detail +-- +-- Type +Use EntityData +Select * +From [EntityData].[Entity].[EventDetailType] + +-- +-- Event Schedule +-- + +-- EventScheduleLocation +Use EntityData +Go +Select Top 100 * +From [EntityData].[Entity].[EventScheduleLocation] +--Where EventScheduleLocationKey = '917ec35f-093d-4c39-a04e-31eda9fe7858' +Go +EXECUTE EntityCode.EventScheduleLocationSave @Id = '-1', @Key = '917ec35f-093d-4c39-a04e-31eda9fe7858', @EventKey = '929b5f5f-7009-4883-94be-3ae217df6128', @BeginDate = '1/1/1900 12:00:00 AM', @EndDate = '1/1/1900 12:00:00 AM', @LocationName = 'Your House', @LocationDescription = 'Corner of Main and Drain', @ActivityContextKey = '626e2c8b-ccd5-4e5f-80cb-03ae180db87e' \ No newline at end of file diff --git a/data/Entity.Queries/Core_Flow.sql b/data/Entity.Queries/Core_Flow.sql new file mode 100644 index 00000000..d8485860 --- /dev/null +++ b/data/Entity.Queries/Core_Flow.sql @@ -0,0 +1,41 @@ +-- +-- Flow +-- +-- Raw table +Use EntityData +Go +Select Top 100 * +From [EntityData].[Entity].[Flow] +-- View +Use EntityData +Go +Select Top 100 * +From [EntityData].[EntityCode].[FlowInfo] + +-- +-- Flow Sequence +-- +-- Raw table +Use EntityData +Go +Select Top 100 * +From [EntityData].[Entity].[FlowSequence] + +-- +-- Flow Step +-- +-- Raw table +Use EntityData +Go +Select Top 100 * +From [EntityData].[Entity].[FlowStep] + +-- ActivitySessionflow +Use EntityData +Go +Select Top 100 * +From [EntityData].[Activity].[ActivitySessionflow] +Order By ActivitySessionflowID Desc +-- View +Select Top 100 * +From [EntityData].[Activity].[ActivitySessionflow] diff --git a/data/Entity.Queries/Core_Government.sql b/data/Entity.Queries/Core_Government.sql new file mode 100644 index 00000000..70f04bb2 --- /dev/null +++ b/data/Entity.Queries/Core_Government.sql @@ -0,0 +1,9 @@ +-- +--Entity +-- +-- Government +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Entity].Entity C +Join [EntityData].[Entity].Government G On C.EntityID = G.EntityID diff --git a/data/Entity.Queries/Core_Item.sql b/data/Entity.Queries/Core_Item.sql new file mode 100644 index 00000000..e69de29b diff --git a/data/Entity.Queries/Core_Legal.sql b/data/Entity.Queries/Core_Legal.sql new file mode 100644 index 00000000..59a21a51 --- /dev/null +++ b/data/Entity.Queries/Core_Legal.sql @@ -0,0 +1,10 @@ +-- +-- Unsubscrube +-- +Use EntityData +Select * +From [EntityData].[Entity].Unsubscribe +-- Log +Use EntityData +Select Top 100 * +FROM [EntityData].Log.[UnsubscribeDelete] diff --git a/data/Entity.Queries/Core_Location.sql b/data/Entity.Queries/Core_Location.sql new file mode 100644 index 00000000..e69de29b diff --git a/data/Entity.Queries/Core_Log.sql b/data/Entity.Queries/Core_Log.sql new file mode 100644 index 00000000..0a15f8e8 --- /dev/null +++ b/data/Entity.Queries/Core_Log.sql @@ -0,0 +1,20 @@ +-- +-- +-- +-- Activity log +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select Top 1000 * +From EntityData.Activity.ActivityContext +-- Exception log +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select Top 1000 * +From EntityData.Activity.ExceptionLog +Order By ExceptionLogId Desc + + + + +sp_who +kill 53 \ No newline at end of file diff --git a/data/Entity.Queries/Core_Module.sql b/data/Entity.Queries/Core_Module.sql new file mode 100644 index 00000000..35f9cb13 --- /dev/null +++ b/data/Entity.Queries/Core_Module.sql @@ -0,0 +1,6 @@ +-- +-- Module +-- +Use EntityData +Select * +From [Entity].Module diff --git a/data/Entity.Queries/Core_Person.sql b/data/Entity.Queries/Core_Person.sql new file mode 100644 index 00000000..32b3cbb4 --- /dev/null +++ b/data/Entity.Queries/Core_Person.sql @@ -0,0 +1,55 @@ +-- +-- Person +-- +-- Person full +Use [EntityData] +Go +Select Top 100 * +From [EntityData].[Entity].[Person] P +Left Join [EntityData].[Entity].Entity E On P.EntityID = E.EntityID +Left Join [EntityData].[Entity].[Gender] G On P.GenderID = G.GenderID +Order By P.Createddate desc + +-- Person raw +Use [EntityData] +Go +Select * +From [EntityData].[Entity].[Person] +-- Gender raw +Use [EntityData] +Go +Select * +From [EntityData].[Entity].[Gender] + +-- +-- EntiteCode.Person +-- +EXECUTE EntityCode.PersonInfoSave @Id = '-1', @Key = 'a2c2c76e-d43c-4670-907c-5ad088795ec8', @FirstName = 'FirstTest', @MiddleName = 'MiddleTest', @LastName = 'LastTest', @BirthDate = '3/30/1981 12:00:00 AM', @GenderCode = '', @ActivityContextKey = '7523641f-497d-47c6-8023-abbf98a27b20' + +-- Test quick save: Insert into activity, then save person +Declare @ActivityContextID int +Select @ActivityContextID = Max(ActivityID) From [EntityData].Activity.Activity +Exec [EntityData].[BaseCode].PersonInfoSave '00000000-0000-0000-0000-000000000000', 'FirstTest', 'MiddleTest', 'LastTest', '3/30/1981', 0, @ActivityContextID + +-- Person joined +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select Top 100 * +From [EntityData].[Entity].Entity C +Join [EntityData].[Entity].[Person] P On C.EntityID = P.EntityID +Order By P.Createddate desc + +-- Persons ActivityWorkflow +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select Top 100 * +From [EntityData].Activity.ActivityWorkflow WA +Join [EntityData].[Entity].[Person] P On WA.EntityID = P.EntityID +Order By WA.CreatedDate + + +-- Person Save +Use EntityData +Truncate Table EntityData.[DataTier].[ExceptionLog] +Exec [EntityData].[BaseCode].PersonInfoSave '00000000-0000-0000-0000-000000000000', 'FirstTest', 'MiddleTest', 'LastTest', '03/31/1981', 1 +Select * From EntityData.[DataTier].[ExceptionLog] diff --git a/data/Entity.Queries/Core_Property.sql b/data/Entity.Queries/Core_Property.sql new file mode 100644 index 00000000..e4074a16 --- /dev/null +++ b/data/Entity.Queries/Core_Property.sql @@ -0,0 +1,40 @@ +-- +-- Property +-- +Use EntityData +Select * +From [Entity].Property +Where PropertyKey = 'f57e9798-6e70-4887-9580-44cca5eed894' + +-- +-- EntityProperty +-- +Use EntityData +Select * +From [Entity].[PropertyEntity] PC +Join [Entity].[Person] P On PC.EntityID = P.EntityID +Join [Entity].[Property] Pr on PC.PropertyID = Pr.PropertyID +Where Pr.PropertyKey = 'f57e9798-6e70-4887-9580-44cca5eed894' + + + +-- +-- From PersonInfoSave +-- +-- Parameters +Declare @Gender As nvarchar(10) = '' +-- Locals +Declare @GenderPropertyID As int +Declare @MalePropertyID As Int +-- Look for @Gender match on code. If not, default to male PropertyID +Select @MalePropertyID = PropertyID From [EntityData].[Entity].[Property] Where PropertyKey = 'f57e9798-6e70-4887-9580-44cca5eed894' +Select @GenderPropertyID = IsNull(NullIf(P.PropertyID, ''), @MalePropertyID) + From [EntityData].[Entity].[Property] P + Join [EntityData].[Entity].[PropertyGroup] PG On P.PropertyGroupID = PG.PropertyGroupID + Where PG.PropertyGroupKey = N'b997d822-c6d1-4c0f-877b-5d8e8aa6cc99' And P.PropertyCode = @Gender +If @GenderPropertyID Is Null +Begin + Select 'isnull' +End + +Select @MalePropertyID As MaleID, IsNull(@GenderPropertyID, @MalePropertyID) PropID \ No newline at end of file diff --git a/data/Entity.Queries/Core_RecordState.sql b/data/Entity.Queries/Core_RecordState.sql new file mode 100644 index 00000000..7259223d --- /dev/null +++ b/data/Entity.Queries/Core_RecordState.sql @@ -0,0 +1,4 @@ +Use [EntityData] +Go +Select * +From EntityData.Entity.RecordState \ No newline at end of file diff --git a/data/Entity.Queries/Core_Resource.sql b/data/Entity.Queries/Core_Resource.sql new file mode 100644 index 00000000..670780fd --- /dev/null +++ b/data/Entity.Queries/Core_Resource.sql @@ -0,0 +1,27 @@ +-- +-- +-- +Use EntityData +Go +Select Top 10 * +From EntityData.Entity.ResourceItem +Order By ResourceItemId Desc + + +-- View +Select RP.ResourceItemId As [Id], + RP.ResourceItemKey As [Key], + R.ResourceKey, + R.ResourceName, + R.ResourceDescription, + P.ItemKey, + P.ItemName, + P.ItemDescription, + P.ItemGroupKey, + P.ItemTypeKey, + RP.CreatedActivityKey As ActivityContextKey, + RP.CreatedDate, + RP.ModifiedDate +From [Entity].[ResourceItem] RP + Join [Entity].[Resource] R On RP.ResourceKey = R.ResourceKey + Join [Entity].[Item] P On RP.ItemKey = P.ItemKey \ No newline at end of file diff --git a/data/Entity.Queries/Core_Schedule.sql b/data/Entity.Queries/Core_Schedule.sql new file mode 100644 index 00000000..87afe8ac --- /dev/null +++ b/data/Entity.Queries/Core_Schedule.sql @@ -0,0 +1,42 @@ + +-- +-- Event Schedule +-- +-- EventScheduleLocation +Use EntityData +Go +Select Top 100 * +From [EntityData].[Entity].[EventScheduleLocation] +--Where EventScheduleLocationKey = '917ec35f-093d-4c39-a04e-31eda9fe7858' +Go +EXECUTE EntityCode.EventScheduleLocationSave @Id = '-1', @Key = '917ec35f-093d-4c39-a04e-31eda9fe7858', @EventKey = '929b5f5f-7009-4883-94be-3ae217df6128', @BeginDate = '1/1/1900 12:00:00 AM', @EndDate = '1/1/1900 12:00:00 AM', @LocationName = 'Your House', @LocationDescription = 'Corner of Main and Drain', @ActivityContextKey = '626e2c8b-ccd5-4e5f-80cb-03ae180db87e' + +-- ScheduleLocation View +Use EntityData +Go +Select Top 10 * +From [EntityData].[EntityCode].[EventScheduleLocation] + +-- +-- Time +-- +-- TimeRange +-- ScheduleLocation View +Use EntityData +Go +Select Top 10 * +From [EntityData].[Entity].[TimeRange] + +-- TimeRecurring +Use EntityData +Go +Select Top 10 * +From [EntityData].[Entity].[TimeRecurring] + +-- TimeCycle +Use EntityData +Go +Select Top 10 * +From [EntityData].[Entity].[TimeCycle] + + diff --git a/data/Entity.Queries/Core_Settings.sql b/data/Entity.Queries/Core_Settings.sql new file mode 100644 index 00000000..457e27f6 Binary files /dev/null and b/data/Entity.Queries/Core_Settings.sql differ diff --git a/data/Entity.Queries/Core_Workflow.sql b/data/Entity.Queries/Core_Workflow.sql new file mode 100644 index 00000000..0e1eebe1 --- /dev/null +++ b/data/Entity.Queries/Core_Workflow.sql @@ -0,0 +1,41 @@ +Use EntityData +Set Transaction Isolation Level Read Uncommitted +-- Workflow +Use EntityData +Select * +From [EntityData].[Entity].Workflow +Where WorkflowID = '41bddedf-7037-44af-a132-2865b23d5ca2' +Order By WorkflowName, WorkflowTypeID + +-- Workflow Type +Use EntityData +Select * +From [EntityData].[Entity].WorkflowType +-- Workflow Step +Use EntityData +Select * +From [EntityData].[Entity].WorkflowStep +Use EntityData + +-- Joined Full +Set Transaction Isolation Level Read Uncommitted +Select WA.*, W.WorkflowName, WS.WorkflowStepName +From [EntityData].Activity.ActivityWorkflow WA + Left Join [EntityData].[Entity].Workflow W On WA.WorkflowID = W.WorkflowID + Left Join [EntityData].[Entity].WorkflowStep WS On WA.WorkflowStepID = WS.WorkflowStepID +Order By WA.CreatedDate Desc + +Use EntityData +Select * +From [EntityData].Activity.ActivityWorkflow WA +Join [EntityData].[Entity].WorkflowStep WS + On WA.WorkflowStepID = WS.WorkflowStepID +Join [EntityData].[Entity].Workflow W + On WA.WorkflowID = W.WorkflowID +Join [EntityData].[Entity].Application A + On WA.ApplicationID = A.ApplicationID +Order By WA.ModifiedDate Desc + +--Delete From ActivityWorkflow Where ActivityWorkflowID = '25C0A415-348C-429D-ABA2-B92F3AD96B1F' + + diff --git a/data/Entity.Queries/Geography_Addresses.sql b/data/Entity.Queries/Geography_Addresses.sql new file mode 100644 index 00000000..5eaf8574 --- /dev/null +++ b/data/Entity.Queries/Geography_Addresses.sql @@ -0,0 +1,147 @@ +--('00000000-0000-0000-0000-000000000000') +-- +--Address +-- +Use EntityData +Select * +From [EntityData].Geography.AddressEntity CA +Left Join [EntityData].Geography.Address A On CA.AddressID = A.AddressID +Left join [EntityData].Geography.PostalCode P On A.PostalCodeID = P.PostalCodeID +Left join [EntityData].Geography.LatLong L On A.LatLongID = L.LatLongID +Left Join [EntityData].Geography.AddressType AT on CA.AddressTypeID = AT.AddressTypeID +Where CA.EntityID = '24b9f599-eb60-479b-b640-4b9407d79f2f' +Select * +From [EntityData].[Entity].Event E +Left Join [EntityData].Geography.EventLocation A On E.EventID = A.EventID +Left join [EntityData].Geography.Address Ad On A.AddressID = Ad.AddressID +Left join [EntityData].Geography.PostalCode P On Ad.PostalCodeID = P.PostalCodeID +Left join [EntityData].Geography.LatLong L On Ad.LatLongID = L.LatLongID +Where E.EventCreatorID = '24b9f599-eb60-479b-b640-4b9407d79f2f' +Select * +From [EntityData].Geography.Address A +Left join [EntityData].Geography.PostalCode P On A.PostalCodeID = P.PostalCodeID +Left join [EntityData].Geography.LatLong L On A.LatLongID = L.LatLongID +Where AddressID = 'd1a4d6a6-aaa2-4e93-85b9-c74ac836c7de' +Select * +From [EntityData].Geography.LatLong +--Exec EntityLatLongInsert 'd75db17d-1bb1-4a0c-b079-7d1754b050a8', '6855469f-bcee-481d-9380-0882b1833057' +Select * +From [EntityData].Geography.AddressType + +-- +--Countries +-- +Use EntityData +Select * +From [EntityData].Geography.Country +Where CountryName Like 'unit%' + +Select * + From VGOConnect.[Entity].PostalCode P + Join VGOConnect.[Entity].Country C On P.CountryID = C.CountryID + Join VGOConnect.[Entity].State S On P.StateID = S.StateID +Where PostalCode In ('02568', '02568') + +-- +--States +-- +Use EntityData +Select * +From [EntityData].Geography.State S +Left Join [EntityData].Geography.Country C On S.CountryID = C.CountryID +Where StateName Like '%calif%' + +-- +--PostalCodes +-- +Select P.PostalCode, c.CountryName--, Count(*) --.PostalCode, S.StateName, C.CountryName +From [EntityData].Geography.PostalCode as P +Left Join [EntityData].Geography.State as S + On P.stateID = S.STateID +Left Join [EntityData].Geography.Country C + On P.countryID = C.countryID +--Where C.CountryName = 'France' +Order By C.CountryName + +-- +--Lat Long +-- +Use EntityData +Select Top 100 * +From [EntityData].Geography.LatLong L +Left Join [EntityData].Geography.Address A On L.LatLongID = A.LatLongID + +-- +--Raw +-- +Use EntityData +Select Top 100 * +From [EntityData].Geography.PostalCode +Use EntityData +Select Top 100 * +From [EntityData].Geography.Address +Order By CreatedDate Desc +Use EntityData +Select Top 100 * +From [EntityData].Geography.AddressEntity +Use EntityData +Select Top 100 * +From [EntityData].Geography.LatLongTable + +-- +--Phone +-- +Use EntityData +Select * +From [EntityData].Geography.PhoneNumberEntity +Select * +From [EntityData].Geography.PhoneNumber +Select * +From [EntityData].Geography.PhoneNumberType + +-- +--Email +-- +Use EntityData +Select * +From [EntityData].Geography.Email +Select * +From [EntityData].Geography.EmailEntity +Select * +From [EntityData].Geography.EmailType + +-- +--Language +-- +Use EntityData +Select * +From [EntityData].Geography.Language + +-- Importing Postal Codes + +-- +-- INSERT POSTAL CODES +-- +-- Initiate +Use EntityData +Go +Begin Tran +Declare @ActivityWorkflowID Uniqueidentifier = N'26D4CB2B-3645-43C2-B31E-1326B9FB54EF' +DECLARE @Data TABLE(PostalCodeID Uniqueidentifier, PostalCode varchar(30) NOT NULL); +-- Get dup field +INSERT INTO @Data +Select PostalCodeID, PostalCode + From VGOConnect.[Entity].PostalCode P +Where PostalCodeID Not In (Select Min(PostalCodeID) + From VGOConnect.[Entity].PostalCode + Group By PostalCode, City, CountryID, StateID) +-- Source dup cleanup +Delete From VGOConnect.[Entity].Address Where PostalCodeID In (Select PostalCodeID From @Data) +Delete From VGOConnect.[Entity].PostalCode Where PostalCodeID In (Select PostalCodeID From @Data) +-- destination +Delete From [EntityData].Geography.PostalCode +Insert Into [EntityData].Geography.PostalCode (PostalCodeID, PostalCode,StateID, City, CountryID, LatLongID, CreatedActivityID) +Select PostalCodeID, PostalCode,StateID, City, CountryID, LatLongID, @ActivityWorkflowID As CreatedActivityID + From VGOConnect.[Entity].PostalCode +Go +Rollback \ No newline at end of file diff --git a/data/Entity.Queries/Geography_IPAddress.sql b/data/Entity.Queries/Geography_IPAddress.sql new file mode 100644 index 00000000..adae0ee0 --- /dev/null +++ b/data/Entity.Queries/Geography_IPAddress.sql @@ -0,0 +1,49 @@ +Use Admin +Set Transaction Isolation Level Read Uncommitted +SELECT TOP 100 -- FROM [Admin].[dbo].[IP2LOCATION-LITE-DB11] Where [Column 2] = 'US' and [Column 5] = 'Valhalla' +SELECT TOP 100 -- FROM [Admin].[dbo].[GeoLiteCity-Location] Where country= 'US' And city = 'Valhalla' +SELECT TOP 100 -- FROM [EntityData].[dbo].[PostalCode] + +Use master +Select INET_NTOA() +-- +-- Mine:99.111.28.101 + +-- ******************** +-- **-- IP2Location *** +-- ******************** +--http://ipinfodb.com/ip_dataEntity.php +--ip = ((A*256+B)*256+C)*256 + D +--74.125.45.100 = ((74*256+125)*256+45)*256 + 100 = 1249717604 +-- DOES NOT WORK +--Key: 5698907256df529e3a2561a55297387f6e3ecf9e3c7874110886493d82a510d1 +--http://api.ipinfodb.com/v3/ip-city/?key=5698907256df529e3a2561a55297387f6e3ecf9e3c7874110886493d82a510d1&ip=99.111.28.101 +--http://api.ipinfodb.com/v3/ip-country/?key=5698907256df529e3a2561a55297387f6e3ecf9e3c7874110886493d82a510d1&ip=99.111.28.101 +SElect * +From [Admin].[dbo].[IP2LOCATION-LITE-DB11] +Where [Column 0] >= '1668226048' And [Column 1] <= '1668226048' +Select ((99*256+111)*256+28)*256 + 101 + +-- ******************** +-- **-- GeoLite *** +-- ******************** +-- http://www.maxmind.com/app/csv +--ipnum = 16777216*w + 65536*x + 256*y + z +--where +--IP Address = w.x.y.z +--The reverse of this formula is +--w = int ( ipnum / 16777216 ) % 256; +--x = int ( ipnum / 65536 ) % 256; +--y = int ( ipnum / 256 ) % 256; +--z = int ( ipnum ) % 256; +--Where % is the mod operator. +--I.e. (24.24.24.24 ) 404232216 = 16777216*24 + 65536*24 + 256*24 + 24 +Select 16777216*99 + 65536*111 + 256*28 + 101 +Select * +FROM [Admin].[dbo].[GeoLiteCity-Blocks] +Where startipnum >= '1668226149' And EndIPNum <= '1668226149' + +-- ******************** +-- ***-- Works, but is PHP +-- ******************** +--http://www.geoplugin.net/php.gp?ip=99.111.28.101-- \ No newline at end of file diff --git a/data/Entity.Queries/Localization_Languages.sql b/data/Entity.Queries/Localization_Languages.sql new file mode 100644 index 00000000..5fc48294 --- /dev/null +++ b/data/Entity.Queries/Localization_Languages.sql @@ -0,0 +1,18 @@ +-- +--Language +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Localization].[Language] +Order By CreatedDate +SELECT [LanguageID],[LanguageName],[LanguageDescription],[NativeName],[Locale],[SortOrder],[ISO693-1],[CreatedDate],[ModifiedDate],[ClusterID] + FROM [EntityData].[Localization].[Language] +-- +--Text +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].[Localization].[TextTable] +Order By CreatedDate \ No newline at end of file diff --git a/data/Entity.Queries/Media_Photo.sql b/data/Entity.Queries/Media_Photo.sql new file mode 100644 index 00000000..3e446030 --- /dev/null +++ b/data/Entity.Queries/Media_Photo.sql @@ -0,0 +1,26 @@ +-- +--Photo +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].Active.PhotoEntity PC +Left Join [EntityData].[Entity].Entity C On PC.EntityID = C.EntityID +Left Join [EntityData].[Entity].[Person] P On C.PersonID = P.PersonID +Left Join [EntityData].Active.Photo Ph On PC.PhotoID = PH.PhotoID + + +-- Photo +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From Photo + +-- Types +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].Active.PhotoType + + + diff --git a/data/Entity.Queries/Messaging_AssociateList.sql b/data/Entity.Queries/Messaging_AssociateList.sql new file mode 100644 index 00000000..d42b898c Binary files /dev/null and b/data/Entity.Queries/Messaging_AssociateList.sql differ diff --git a/data/Entity.Queries/Messaging_Rsvp.sql b/data/Entity.Queries/Messaging_Rsvp.sql new file mode 100644 index 00000000..b309d173 --- /dev/null +++ b/data/Entity.Queries/Messaging_Rsvp.sql @@ -0,0 +1,18 @@ + +-- +--RSVP +-- +-- EventRSVP +Use EntityData +Select * +From [EntityData].[Entity].EventRSVP R +Join [EntityData].Active.GuestListEntity G On R.GuestListEntityID = G.GuestListEntityID +-- Statuses +Use EntityData +Select * +From [EntityData].[Entity].EventRSVPStatus +-- EXEC DBA.RSVPStatusImageUpdate '7BE9F988-39D9-4278-9867-1A3419E06217', 'c:\backup\uploads\FaceQuestion.jpg' +--00000000-0000-0000-0000-000000000000 NoReply +--7BE9F988-39D9-4278-9867-1A3419E06217 Maybe +--1BD8C086-F0B4-4310-B1D2-3B80B9033399 Yes +--CB43D125-17BD-42A0-82A7-CE4DE56B2D1B No \ No newline at end of file diff --git a/data/Entity.Queries/Messaging_Templates.sql b/data/Entity.Queries/Messaging_Templates.sql new file mode 100644 index 00000000..08de3fe8 --- /dev/null +++ b/data/Entity.Queries/Messaging_Templates.sql @@ -0,0 +1,34 @@ +-- Messages +Select M.FromEntityID, M.MessageSubject As Subject, M.MessageBody As Body, M.CreatedDate, M.ModifiedDate, M.WorkflowStepID, MM.*, MP.*, MB.* +From [EntityData].[Entity].Message M +Left Join [EntityData].Active.MessageEvent MM On M.MessageID = MM.MessageID +Left Join [EntityData].Active.MessagePerson MP On M.MessageID = MP.MessageID +Left Join [EntityData].Active.MessageBusiness MB On M.MessageID = MB.MessageID + + +Select MM.MessageEventID As ID, M.ParentMessageID, MM.EventID, M.FromEntityID, M.MessageSubject As Subject, M.MessageBody As Body, M.CreatedDate, M.ModifiedDate, M.WorkflowStepID +From [EntityData].Active.MessageEvent MM +Join [EntityData].[Entity].Message M On MM.MessageID = M.MessageID + +Select -- +From EntityData200.[Entity].MessageTable + +-- Template Types +Use EntityData +Select TT.TemplateTypeID, TT.TemplateTypeName, TT.FieldCount, T.TemplateID, T.TemplateName, T.TemplateHTML +From [EntityData].[Entity].TemplateType TT +Left Join [EntityData].[Entity].Template T On TT.TemplateTypeID = T.TemplateTypeID +Order By TemplateTypeName, TemplateName + +-- Templates +Use EntityData +Select Tt.TemplateTypeID, TT.TemplateTypeName, T.TemplateID, T.TemplateName, T.TemplateHTML +From [EntityData].[Entity].Template T +Left Join [EntityData].[Entity].TemplateType TT On T.TemplateTypeID = TT.TemplateTypeID +Order By TT.TemplateTypeName, T.TemplateName + +-- EXEC [EntityData].DBA.TemplateHTMLUpdate '7CE4F76F-E705-49B0-A954-4DF69431586D', 'c:\backup\uploads\Reply.html' +-- EXEC [EntityData].DBA.TemplateImageUpdate '8C01F7EE-15D0-45D8-A82C-838E7F8C81C8', 'c:\backup\uploads\picnic.jpg' + +--INSERT [EntityData].[Entity].[Template] ([TemplateID], [TemplateTypeID], [TemplateName], [TemplateDescription]) Values (NewID(), '19CC0F01-E1C7-4EC9-B1B6-F7E11742EC50', 'Reply Message', 'Reply to any message sent to you.') + diff --git a/data/Entity.Queries/Profile_Interests.sql b/data/Entity.Queries/Profile_Interests.sql new file mode 100644 index 00000000..1e21af05 --- /dev/null +++ b/data/Entity.Queries/Profile_Interests.sql @@ -0,0 +1,100 @@ +Use EntityData +Set Transaction Isolation Level Read Uncommitted +-- +--Entity +-- +Use EntityData +Select * +From Entity.Entity C +Join [Entity].[Person] P On C.EntityID = P.EntityID +Select * +From [Entity].Business + +-- +--Properties +-- +Use EntityData +Select * +From [EntityData].[Entity].[Person] P +Join [EntityData].[Entity].[PropertyEntity] PC on P.EntityID = PC.EntityID +Join [EntityData].[Entity].Property Pr on PC.PropertyID = Pr.PropertyID + +-- +--Interest +-- +Select * +From InterestTable +Select * +From InterestEntity +Select * +From InterestEntity CI +Left Join Interest I + On CI.InterestID = I.InterestID + +Begin Tran +Delete +From InterestEntity +Rollback + +Use EntityData +Select * +From InterestGroup +Select * +From Interest +Select * +From InterestSubType + +-- +--Guest List +-- +Use EntityData +Select * +From GuestList +Select * +From GuestListEntity + + +-- +--Properties +-- +Use EntityData +Select * +From PropertyGroup +Select * +From Property +Select * +From PropertyEntity CP +Left Join Entity C + On CP.EntityID = C.EntityID +Select EntityID, Count(*) +From PropertyEntity +Group By EntityID +Having Count(*) > 1 + +Select * +From PropertyEntity CP +Join Property P On CP.PropertyID = P.PropertyID +Join PropertyGroup PG On P.PropertyGroupID = PG.PropertyGroupID +Order By EntityID +Select * +From PropertyGroup + +Select PG.PropertyGroupName, P.* +From Property P +Join PropertyGroup PG On P.PropertyGroupID = PG.PropertyGroupID +Order By P.PropertyGroupID + + +-- +--Unsubscribe +-- +Use EntityData +Select Top 100 * +From [EntityData].[Entity].Unsubscribe U +Join [EntityData].Activity.ActivityWorkflow WA On U.ActivityWorkflowID = WA.ActivityWorkflowID +Where U.UnsubscribeID = '48406D9F-5F7D-4D5C-889D-459048D8FCF2' + +Use EntityData +Select Top 100 * +From [EntityData].Log.UnsubscribeDelete + diff --git a/data/Entity.Queries/Provider_Queries.sql b/data/Entity.Queries/Provider_Queries.sql new file mode 100644 index 00000000..cf3c9e44 --- /dev/null +++ b/data/Entity.Queries/Provider_Queries.sql @@ -0,0 +1,43 @@ +-- +-- Office +-- +-- Singles +Use SchedulerData +Go +Select Top 100 * From [Provider].[Office] Order By CreatedDate Desc + +-- Full Join +Use SchedulerData +Go +Select Top 10 * From [Provider].[Office] O + Join [Entity].[Business] B On O.BusinessKey = B.BusinessKey + Join [Entity].[EntityLocation] EL On O.OfficeKey = EL.EntityKey + Join [Entity].[Location] L On EL.LocationKey = L.LocationKey +Order By O.CreatedDate Desc + +-- Stored Procedures +Use SchedulerData +Go +EXECUTE ProviderCode.OfficeInfoSave @Id = '-1', @Key = 'a3d054c2-fe55-46e9-9531-c8e998c9d6d1', @Name = 'AbcCo', @TaxNumber = '666-1', @BusinessKey = '00000000-0000-0000-0000-000000000000', @LocationKey = '00000000-0000-0000-0000-000000000000', @LocationName = '', @LocationDescription = '', @ActivityContextKey = '6329bdb4-0637-40c6-8bf1-f340672bbc80' + + +-- +-- Office Hours +-- +-- Single +Use SchedulerData +Go +Select Top 10 * From [ProviderCode].[OfficeHours] OH + +-- Full Join +Use SchedulerData +Go +Select Top 10 * From [Provider].[Office] O + Left Join [ProviderCode].[OfficeHours] OH On O.OfficeKey = OH.OfficeKey +Order By O.CreatedDate Desc + + +-- Stored Procedure +Use SchedulerData +Go +EXECUTE ProviderCode.OfficeHoursSave @Id = '-1', @Key = '0a3cf11c-8244-490f-b3c5-58d2cdbfb0a2', @OfficeKey = '5fd55e6f-3030-45e0-8d46-e2bd41268205', @BeginDay = '1', @EndDay = '1', @BeginTime = '1/1/1900 8:00:00 AM', @EndTime = '1/1/1900 5:00:00 PM', @ActivityContextKey = 'cb411066-d2de-47a0-9e16-9119a2593dd2' \ No newline at end of file diff --git a/data/Entity.Queries/eCommerce_Taxes.sql b/data/Entity.Queries/eCommerce_Taxes.sql new file mode 100644 index 00000000..b228e76b --- /dev/null +++ b/data/Entity.Queries/eCommerce_Taxes.sql @@ -0,0 +1,45 @@ +-- +-- Transactions +-- +-- Transaction +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].eCommerce.BankAccountTransaction +-- Transaction Type +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].eCommerce.BankAccountTransactionType + +-- +--Currency +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].eCommerce. + +-- +--Shipping +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].eCommerce. + +-- +--Taxes +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].eCommerce. + +-- +--Order History +-- +Use EntityData +Set Transaction Isolation Level Read Uncommitted +Select * +From [EntityData].eCommerce. diff --git a/data/Subjects/Entities.Subjects/Entities.Subjects.sqlproj b/data/Subjects/Entities.Subjects/Entities.Subjects.sqlproj new file mode 100644 index 00000000..810b6550 --- /dev/null +++ b/data/Subjects/Entities.Subjects/Entities.Subjects.sqlproj @@ -0,0 +1,16 @@ + + + + + Entities.Subjects + {2E65BE48-C962-4F0D-A293-744E21F0FFD3} + Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider + 1033, CI + + + + + + + + \ No newline at end of file diff --git a/src/Subjects/Common/Common.Application/Exceptions/ConflictException.cs b/src/Subjects/Common/Common.Application/Exceptions/ConflictException.cs new file mode 100644 index 00000000..181829a8 --- /dev/null +++ b/src/Subjects/Common/Common.Application/Exceptions/ConflictException.cs @@ -0,0 +1,23 @@ +namespace Goodtocode.Common.Application.Exceptions; + +public class ConflictException : Exception +{ + public ConflictException() + { + } + + public ConflictException(string message) + : base(message) + { + } + + public ConflictException(string message, Exception innerException) + : base(message, innerException) + { + } + + public ConflictException(string name, string duplicateReason) + : base($"Entity \"{name}\" is a duplicated by {duplicateReason}.") + { + } +} \ No newline at end of file diff --git a/src/Subjects/Common/Common.Domain/DomainEntity/DomainEntity.cs b/src/Subjects/Common/Common.Domain/DomainEntity/DomainEntity.cs index e5c32b4b..c644de60 100644 --- a/src/Subjects/Common/Common.Domain/DomainEntity/DomainEntity.cs +++ b/src/Subjects/Common/Common.Domain/DomainEntity/DomainEntity.cs @@ -1,4 +1,4 @@ -using Goodtocode.Common.Domain; +using Goodtocode.Common.Extensions; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; @@ -76,11 +76,11 @@ public override int GetHashCode() return (GetRealType().ToString() + Key).GetHashCode(); } - private Type GetRealType() + private Type GetRealType(string namespaceRoot = "") { var type = GetType(); - if (type.ToString().Contains("Goodtocode.Subjects")) + if (type.ToString().Contains(namespaceRoot)) return type.BaseType ?? type.GetType(); return type; diff --git a/src/Subjects/Common/Common.Domain/Extensions/ObjectExtensions.cs b/src/Subjects/Common/Common.Domain/Extensions/ObjectExtensions.cs new file mode 100644 index 00000000..781d975a --- /dev/null +++ b/src/Subjects/Common/Common.Domain/Extensions/ObjectExtensions.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Goodtocode.Common.Extensions +{ + /// + /// object Extensions + /// + public static class ObjectExtension + { + /// + /// Get list of properties decorated with the passed attribute + /// + /// + /// + /// + public static IEnumerable GetPropertiesByAttribute(this object item, Type myAttribute) + { + var returnValue = item.GetType().GetTypeInfo().DeclaredProperties.Where( + p => p.GetCustomAttributes(myAttribute, false).Any()); + + return returnValue; + } + + /// + /// Safe Type Casting based on .NET default() method + /// + /// default(DestinationType) + /// Item to default. + /// default(DestinationType) + public static TDestination? DefaultSafe(this object item) + { + var returnValue = TypeExtension.InvokeConstructorOrDefault(); + + try + { + if (item != null) + { + returnValue = (TDestination)item; + } + } + catch + { + returnValue = TypeExtension.InvokeConstructorOrDefault(); + } + + return returnValue; + } + + /// + /// Safe type casting via (TDestination)item method. + /// If cast fails, will return constructed object + /// + /// Type to default, or create new() + /// Item to cast + /// Cast result via (TDestination)item, or item.Fill(), or new TDestination(). + public static TDestination CastSafe(this object item) where TDestination : new() + { + var returnValue = new TDestination(); + + try + { + returnValue = item != null ? (TDestination)item : returnValue; + } + catch (InvalidCastException) + { + returnValue = new TDestination(); + } + + return returnValue; + } + + /// + /// Safe Type Casting based on Default.{Type} conventions. + /// If cast fails, will attempt the slower Fill() of data via reflection + /// + /// Type to default, or create new() + /// Item to cast + /// Defaulted type, or created new() + public static TDestination CastOrCopyProperties(this object item) where TDestination : new() + { + var returnValue = new TDestination(); + + try + { + returnValue = item != null ? (TDestination)item : returnValue; + } + catch (InvalidCastException) + { + returnValue.CopyPropertiesSafe(item); + } + + return returnValue; + } + + /// + /// Safe Type Casting based on Default.{Type} conventions. + /// If cast fails, will attempt the slower Fill() of data via reflection + /// + /// Type to default, or create new() + /// Item to cast + /// Defaulted type, or created new() + public static TDestination CopyPropertiesSafe(this object item) where TDestination : new() + { + var returnValue = new TDestination(); + returnValue.CopyPropertiesSafe(item); + return returnValue; + } + + /// + /// Item to exception-safe cast to string + /// + /// Item to cast + /// Converted string, or "" + public static string? ToStringSafe(this object item) + { + var returnValue = string.Empty; + + if (item == null == false) + { + returnValue = item.ToString(); + } + + return returnValue; + } + + + /// + /// Fills this object with another object's data, by matching property names + /// + /// Type of original object. + /// Destination object to fill + /// Source object + public static void CopyPropertiesSafe(this T item, object sourceItem) + { + var sourceType = sourceItem.GetType(); + + foreach (PropertyInfo sourceProperty in sourceType.GetRuntimeProperties()) + { + PropertyInfo? destinationProperty = typeof(T).GetRuntimeProperty(sourceProperty.Name); + if (destinationProperty != null && destinationProperty.CanWrite) + { + // Copy data only for Primitive-ish types including Value types, Guid, String, etc. + Type destinationPropertyType = destinationProperty.PropertyType; + if (destinationPropertyType.GetTypeInfo().IsPrimitive || destinationPropertyType.GetTypeInfo().IsValueType + || (destinationPropertyType == typeof(string)) || (destinationPropertyType == typeof(Guid))) + { + destinationProperty.SetValue(item, sourceProperty.GetValue(sourceItem, null), null); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Subjects/Common/Common.Domain/Extensions/TypeExtensions.cs b/src/Subjects/Common/Common.Domain/Extensions/TypeExtensions.cs new file mode 100644 index 00000000..f849a4bb --- /dev/null +++ b/src/Subjects/Common/Common.Domain/Extensions/TypeExtensions.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Goodtocode.Common.Extensions +{ + /// + /// Extends System.Type + /// + public static class TypeExtension + { + /// + /// Invokes the parameterless constructor. If no parameterless constructor, returns default() + /// + /// Type to invoke + public static T? InvokeConstructorOrDefault() + { + var returnValue = default(T); + + if (TypeExtension.HasParameterlessConstructor()) + { + returnValue = Activator.CreateInstance(); + } + + return returnValue; + } + + /// + /// Determines if type has a parameterless constructor + /// + /// Type to interrogate for parameterless constructor + /// + public static bool HasParameterlessConstructor() + { + IEnumerable constructors = typeof(T).GetTypeInfo().DeclaredConstructors; + return constructors.Where(x => x.GetParameters().Count() == 0).Any(); + } + + /// + /// Determines if type has a parameterless constructor + /// + /// Type to interrogate for parameterless constructor + /// + public static bool HasParameterlessConstructor(this Type item) + { + IEnumerable constructors = item.GetTypeInfo().DeclaredConstructors; + return constructors.Where(x => x.GetParameters().Count() == 0).Any(); + } + } +} \ No newline at end of file diff --git a/src/Subjects/Core/Application/Business/Commands/AddBusinessCommand.cs b/src/Subjects/Core.Application/Business/Commands/AddBusinessCommand.cs similarity index 50% rename from src/Subjects/Core/Application/Business/Commands/AddBusinessCommand.cs rename to src/Subjects/Core.Application/Business/Commands/AddBusinessCommand.cs index c842c6a2..7d04e514 100644 --- a/src/Subjects/Core/Application/Business/Commands/AddBusinessCommand.cs +++ b/src/Subjects/Core.Application/Business/Commands/AddBusinessCommand.cs @@ -1,16 +1,17 @@ -using Goodtocode.Subjects.Domain; +using CSharpFunctionalExtensions; +using Goodtocode.Subjects.Application.Common.Exceptions; +using Goodtocode.Subjects.Domain; using MediatR; namespace Goodtocode.Subjects.Application; -public class AddBusinessCommand : IRequest, IBusinessEntity +public class AddBusinessCommand : IRequest, IBusinessObject { - public Guid BusinessKey { get; set; } public string BusinessName { get; set; } = string.Empty; public string TaxNumber { get; set; } = string.Empty; } -public class AddBusinessCommandHandler : IRequestHandler +public class AddBusinessCommandHandler : IRequestHandler { private readonly IBusinessRepo _userBusinessRepo; @@ -19,12 +20,14 @@ public AddBusinessCommandHandler(IBusinessRepo BusinessRepo) _userBusinessRepo = BusinessRepo; } - public async Task Handle(AddBusinessCommand request, CancellationToken cancellationToken) + public async Task Handle(AddBusinessCommand request, CancellationToken cancellationToken) { - var AddResult = + var business = await _userBusinessRepo.AddBusinessAsync(request, cancellationToken); - if (AddResult.IsFailure) - throw new Exception(AddResult.Error); + return business.Match( + value => business.Value, + failure => throw new ConflictException(business.Error) + ); } } \ No newline at end of file diff --git a/src/Subjects/Core/Application/Business/Commands/AddBusinessCommandValidator.cs b/src/Subjects/Core.Application/Business/Commands/AddBusinessCommandValidator.cs similarity index 100% rename from src/Subjects/Core/Application/Business/Commands/AddBusinessCommandValidator.cs rename to src/Subjects/Core.Application/Business/Commands/AddBusinessCommandValidator.cs diff --git a/src/Subjects/Core.Application/Business/Commands/DeleteBusinessCommand.cs b/src/Subjects/Core.Application/Business/Commands/DeleteBusinessCommand.cs new file mode 100644 index 00000000..c9267498 --- /dev/null +++ b/src/Subjects/Core.Application/Business/Commands/DeleteBusinessCommand.cs @@ -0,0 +1,29 @@ +using Goodtocode.Subjects.Application.Common.Exceptions; +using Goodtocode.Subjects.Domain; +using MediatR; + +namespace Goodtocode.Subjects.Application; + +public class DeleteBusinessCommand : IRequest +{ + public Guid BusinessKey { get; set; } +} + +public class DeleteBusinessCommandHandler : IRequestHandler +{ + private readonly IBusinessRepo _userBusinessRepo; + + public DeleteBusinessCommandHandler(IBusinessRepo BusinessRepo) + { + _userBusinessRepo = BusinessRepo; + } + + public async Task Handle(DeleteBusinessCommand request, CancellationToken cancellationToken) + { + var DeleteResult = + await _userBusinessRepo.DeleteBusinessAsync(request.BusinessKey, cancellationToken); + + if (DeleteResult.IsFailure) + throw new NotFoundException(DeleteResult.Error); + } +} \ No newline at end of file diff --git a/src/Subjects/Core.Application/Business/Commands/DeleteBusinessCommandValidator.cs b/src/Subjects/Core.Application/Business/Commands/DeleteBusinessCommandValidator.cs new file mode 100644 index 00000000..46bd3567 --- /dev/null +++ b/src/Subjects/Core.Application/Business/Commands/DeleteBusinessCommandValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; + +namespace Goodtocode.Subjects.Application.Business.Commands; + +public class DeleteBusinessCommandValidator : AbstractValidator +{ + public DeleteBusinessCommandValidator() + { + RuleFor(y => y.BusinessKey).NotEmpty(); + } +} \ No newline at end of file diff --git a/src/Subjects/Core/Application/Business/Commands/UpdateBusinessCommand.cs b/src/Subjects/Core.Application/Business/Commands/UpdateBusinessCommand.cs similarity index 100% rename from src/Subjects/Core/Application/Business/Commands/UpdateBusinessCommand.cs rename to src/Subjects/Core.Application/Business/Commands/UpdateBusinessCommand.cs diff --git a/src/Subjects/Core/Application/Business/Commands/UpdateBusinessCommandValidator.cs b/src/Subjects/Core.Application/Business/Commands/UpdateBusinessCommandValidator.cs similarity index 100% rename from src/Subjects/Core/Application/Business/Commands/UpdateBusinessCommandValidator.cs rename to src/Subjects/Core.Application/Business/Commands/UpdateBusinessCommandValidator.cs diff --git a/src/Subjects/Core/Application/Business/Queries/GetBusinessQuery.cs b/src/Subjects/Core.Application/Business/Queries/GetBusinessQuery.cs similarity index 100% rename from src/Subjects/Core/Application/Business/Queries/GetBusinessQuery.cs rename to src/Subjects/Core.Application/Business/Queries/GetBusinessQuery.cs diff --git a/src/Subjects/Core/Application/Business/Queries/GetBusinessQueryValidator.cs b/src/Subjects/Core.Application/Business/Queries/GetBusinessQueryValidator.cs similarity index 100% rename from src/Subjects/Core/Application/Business/Queries/GetBusinessQueryValidator.cs rename to src/Subjects/Core.Application/Business/Queries/GetBusinessQueryValidator.cs diff --git a/src/Subjects/Core/Application/Business/Queries/GetBusinessesByNameQuery.cs b/src/Subjects/Core.Application/Business/Queries/GetBusinessesByNameQuery.cs similarity index 100% rename from src/Subjects/Core/Application/Business/Queries/GetBusinessesByNameQuery.cs rename to src/Subjects/Core.Application/Business/Queries/GetBusinessesByNameQuery.cs diff --git a/src/Subjects/Core/Application/Business/Queries/GetBusinessesByNameQueryValidator.cs b/src/Subjects/Core.Application/Business/Queries/GetBusinessesByNameQueryValidator.cs similarity index 100% rename from src/Subjects/Core/Application/Business/Queries/GetBusinessesByNameQueryValidator.cs rename to src/Subjects/Core.Application/Business/Queries/GetBusinessesByNameQueryValidator.cs diff --git a/src/Subjects/Core/Application/Common/Behaviours/LoggingBehaviour.cs b/src/Subjects/Core.Application/Common/Behaviours/LoggingBehaviour.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Behaviours/LoggingBehaviour.cs rename to src/Subjects/Core.Application/Common/Behaviours/LoggingBehaviour.cs diff --git a/src/Subjects/Core/Application/Common/Behaviours/PerformanceBehaviour.cs b/src/Subjects/Core.Application/Common/Behaviours/PerformanceBehaviour.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Behaviours/PerformanceBehaviour.cs rename to src/Subjects/Core.Application/Common/Behaviours/PerformanceBehaviour.cs diff --git a/src/Subjects/Core/Application/Common/Behaviours/UnhandledExceptionBehaviour.cs b/src/Subjects/Core.Application/Common/Behaviours/UnhandledExceptionBehaviour.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Behaviours/UnhandledExceptionBehaviour.cs rename to src/Subjects/Core.Application/Common/Behaviours/UnhandledExceptionBehaviour.cs diff --git a/src/Subjects/Core/Application/Common/Behaviours/ValidationBehaviour.cs b/src/Subjects/Core.Application/Common/Behaviours/ValidationBehaviour.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Behaviours/ValidationBehaviour.cs rename to src/Subjects/Core.Application/Common/Behaviours/ValidationBehaviour.cs diff --git a/src/Subjects/Core.Application/Common/Exceptions/ConflictException.cs b/src/Subjects/Core.Application/Common/Exceptions/ConflictException.cs new file mode 100644 index 00000000..57288d8e --- /dev/null +++ b/src/Subjects/Core.Application/Common/Exceptions/ConflictException.cs @@ -0,0 +1,23 @@ +namespace Goodtocode.Subjects.Application.Common.Exceptions; + +public class ConflictException : Exception +{ + public ConflictException() + { + } + + public ConflictException(string message) + : base(message) + { + } + + public ConflictException(string message, Exception innerException) + : base(message, innerException) + { + } + + public ConflictException(string name, string duplicateReason) + : base($"Entity \"{name}\" is a duplicated by {duplicateReason}.") + { + } +} \ No newline at end of file diff --git a/src/Subjects/Core/Application/Common/Exceptions/ForbiddenAccessException.cs b/src/Subjects/Core.Application/Common/Exceptions/ForbiddenAccessException.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Exceptions/ForbiddenAccessException.cs rename to src/Subjects/Core.Application/Common/Exceptions/ForbiddenAccessException.cs diff --git a/src/Subjects/Core/Application/Common/Exceptions/NotFoundException.cs b/src/Subjects/Core.Application/Common/Exceptions/NotFoundException.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Exceptions/NotFoundException.cs rename to src/Subjects/Core.Application/Common/Exceptions/NotFoundException.cs diff --git a/src/Subjects/Core/Application/Common/Exceptions/ValidationException.cs b/src/Subjects/Core.Application/Common/Exceptions/ValidationException.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Exceptions/ValidationException.cs rename to src/Subjects/Core.Application/Common/Exceptions/ValidationException.cs diff --git a/src/Subjects/Core/Application/Common/Mappings/IMapFrom.cs b/src/Subjects/Core.Application/Common/Mappings/IMapFrom.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Mappings/IMapFrom.cs rename to src/Subjects/Core.Application/Common/Mappings/IMapFrom.cs diff --git a/src/Subjects/Core/Application/Common/Mappings/MappingProfile.cs b/src/Subjects/Core.Application/Common/Mappings/MappingProfile.cs similarity index 100% rename from src/Subjects/Core/Application/Common/Mappings/MappingProfile.cs rename to src/Subjects/Core.Application/Common/Mappings/MappingProfile.cs diff --git a/src/Subjects/Core/Application/ConfigureServices.cs b/src/Subjects/Core.Application/ConfigureServices.cs similarity index 100% rename from src/Subjects/Core/Application/ConfigureServices.cs rename to src/Subjects/Core.Application/ConfigureServices.cs diff --git a/src/Subjects/Core/Application/Application.csproj b/src/Subjects/Core.Application/Core.Application.csproj similarity index 91% rename from src/Subjects/Core/Application/Application.csproj rename to src/Subjects/Core.Application/Core.Application.csproj index 1232c9e0..92c7380e 100644 --- a/src/Subjects/Core/Application/Application.csproj +++ b/src/Subjects/Core.Application/Core.Application.csproj @@ -14,6 +14,6 @@ - + \ No newline at end of file diff --git a/src/Subjects/Core/Application/Interfaces/IBusinessRepo.cs b/src/Subjects/Core.Application/Interfaces/IBusinessRepo.cs similarity index 75% rename from src/Subjects/Core/Application/Interfaces/IBusinessRepo.cs rename to src/Subjects/Core.Application/Interfaces/IBusinessRepo.cs index a77de162..b89afc31 100644 --- a/src/Subjects/Core/Application/Interfaces/IBusinessRepo.cs +++ b/src/Subjects/Core.Application/Interfaces/IBusinessRepo.cs @@ -11,9 +11,12 @@ public interface IBusinessRepo Task>> GetBusinessesByNameAsync(string businessName, CancellationToken cancellationToken); - Task AddBusinessAsync(IBusinessObject businessInfo, + Task> AddBusinessAsync(IBusinessObject businessInfo, CancellationToken cancellationToken); Task UpdateBusinessAsync(IBusinessEntity businessInfo, CancellationToken cancellationToken); + + Task DeleteBusinessAsync(Guid businessKey, + CancellationToken cancellationToken); } \ No newline at end of file diff --git a/src/Subjects/Core/Application/Interfaces/IPersonRepo.cs b/src/Subjects/Core.Application/Interfaces/IPersonRepo.cs similarity index 100% rename from src/Subjects/Core/Application/Interfaces/IPersonRepo.cs rename to src/Subjects/Core.Application/Interfaces/IPersonRepo.cs diff --git a/src/Subjects/Core/Application/Interfaces/ISubjectsDbContext.cs b/src/Subjects/Core.Application/Interfaces/ISubjectsDbContext.cs similarity index 100% rename from src/Subjects/Core/Application/Interfaces/ISubjectsDbContext.cs rename to src/Subjects/Core.Application/Interfaces/ISubjectsDbContext.cs diff --git a/src/Subjects/Core/Application/Person/UpdatePersonCommand.cs b/src/Subjects/Core.Application/Person/UpdatePersonCommand.cs similarity index 100% rename from src/Subjects/Core/Application/Person/UpdatePersonCommand.cs rename to src/Subjects/Core.Application/Person/UpdatePersonCommand.cs diff --git a/src/Subjects/Core/Application/Person/UpdatePersonCommandValidator.cs b/src/Subjects/Core.Application/Person/UpdatePersonCommandValidator.cs similarity index 100% rename from src/Subjects/Core/Application/Person/UpdatePersonCommandValidator.cs rename to src/Subjects/Core.Application/Person/UpdatePersonCommandValidator.cs diff --git a/src/Subjects/Core/Application/favicon.ico b/src/Subjects/Core.Application/favicon.ico similarity index 100% rename from src/Subjects/Core/Application/favicon.ico rename to src/Subjects/Core.Application/favicon.ico diff --git a/src/Subjects/Core/Application/storeicon.png b/src/Subjects/Core.Application/storeicon.png similarity index 100% rename from src/Subjects/Core/Application/storeicon.png rename to src/Subjects/Core.Application/storeicon.png diff --git a/src/Subjects/Core/Domain/Domain.csproj b/src/Subjects/Core.Domain/Core.Domain.csproj similarity index 80% rename from src/Subjects/Core/Domain/Domain.csproj rename to src/Subjects/Core.Domain/Core.Domain.csproj index 352e1839..a7ab76b5 100644 --- a/src/Subjects/Core/Domain/Domain.csproj +++ b/src/Subjects/Core.Domain/Core.Domain.csproj @@ -9,10 +9,11 @@ false + - + \ No newline at end of file diff --git a/src/Subjects/Core/Domain/Subjects/Associate/Associate.cs b/src/Subjects/Core.Domain/Subjects/Associate/Associate.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/Associate.cs rename to src/Subjects/Core.Domain/Subjects/Associate/Associate.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/BusinessCreatedEvent.cs b/src/Subjects/Core.Domain/Subjects/Associate/BusinessCreatedEvent.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/BusinessCreatedEvent.cs rename to src/Subjects/Core.Domain/Subjects/Associate/BusinessCreatedEvent.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/BusinessDeletedEvent.cs b/src/Subjects/Core.Domain/Subjects/Associate/BusinessDeletedEvent.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/BusinessDeletedEvent.cs rename to src/Subjects/Core.Domain/Subjects/Associate/BusinessDeletedEvent.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/BusinessEntity.cs b/src/Subjects/Core.Domain/Subjects/Associate/BusinessEntity.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/BusinessEntity.cs rename to src/Subjects/Core.Domain/Subjects/Associate/BusinessEntity.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/BusinessObject.cs b/src/Subjects/Core.Domain/Subjects/Associate/BusinessObject.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/BusinessObject.cs rename to src/Subjects/Core.Domain/Subjects/Associate/BusinessObject.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/BusinessUpdatedEvent.cs b/src/Subjects/Core.Domain/Subjects/Associate/BusinessUpdatedEvent.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/BusinessUpdatedEvent.cs rename to src/Subjects/Core.Domain/Subjects/Associate/BusinessUpdatedEvent.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/Gender.cs b/src/Subjects/Core.Domain/Subjects/Associate/Gender.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/Gender.cs rename to src/Subjects/Core.Domain/Subjects/Associate/Gender.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/Government.cs b/src/Subjects/Core.Domain/Subjects/Associate/Government.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/Government.cs rename to src/Subjects/Core.Domain/Subjects/Associate/Government.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IAssociate.cs b/src/Subjects/Core.Domain/Subjects/Associate/IAssociate.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IAssociate.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IAssociate.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IAssociateDetail.cs b/src/Subjects/Core.Domain/Subjects/Associate/IAssociateDetail.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IAssociateDetail.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IAssociateDetail.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IAssociateOption.cs b/src/Subjects/Core.Domain/Subjects/Associate/IAssociateOption.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IAssociateOption.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IAssociateOption.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IBusinessEntity.cs b/src/Subjects/Core.Domain/Subjects/Associate/IBusinessEntity.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IBusinessEntity.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IBusinessEntity.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IBusinessObject.cs b/src/Subjects/Core.Domain/Subjects/Associate/IBusinessObject.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IBusinessObject.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IBusinessObject.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IGender.cs b/src/Subjects/Core.Domain/Subjects/Associate/IGender.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IGender.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IGender.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IGovernment.cs b/src/Subjects/Core.Domain/Subjects/Associate/IGovernment.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IGovernment.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IGovernment.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IPerson.cs b/src/Subjects/Core.Domain/Subjects/Associate/IPerson.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IPerson.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IPerson.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/IPersonEntity.cs b/src/Subjects/Core.Domain/Subjects/Associate/IPersonEntity.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/IPersonEntity.cs rename to src/Subjects/Core.Domain/Subjects/Associate/IPersonEntity.cs diff --git a/src/Subjects/Core/Domain/Subjects/Associate/Person.cs b/src/Subjects/Core.Domain/Subjects/Associate/Person.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Associate/Person.cs rename to src/Subjects/Core.Domain/Subjects/Associate/Person.cs diff --git a/src/Subjects/Core/Domain/Subjects/Detail/AssociateDetail.cs b/src/Subjects/Core.Domain/Subjects/Detail/AssociateDetail.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Detail/AssociateDetail.cs rename to src/Subjects/Core.Domain/Subjects/Detail/AssociateDetail.cs diff --git a/src/Subjects/Core/Domain/Subjects/Detail/Detail.cs b/src/Subjects/Core.Domain/Subjects/Detail/Detail.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Detail/Detail.cs rename to src/Subjects/Core.Domain/Subjects/Detail/Detail.cs diff --git a/src/Subjects/Core/Domain/Subjects/Detail/DetailType.cs b/src/Subjects/Core.Domain/Subjects/Detail/DetailType.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Detail/DetailType.cs rename to src/Subjects/Core.Domain/Subjects/Detail/DetailType.cs diff --git a/src/Subjects/Core/Domain/Subjects/Detail/IDetail.cs b/src/Subjects/Core.Domain/Subjects/Detail/IDetail.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Detail/IDetail.cs rename to src/Subjects/Core.Domain/Subjects/Detail/IDetail.cs diff --git a/src/Subjects/Core/Domain/Subjects/Detail/IDetailType.cs b/src/Subjects/Core.Domain/Subjects/Detail/IDetailType.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Detail/IDetailType.cs rename to src/Subjects/Core.Domain/Subjects/Detail/IDetailType.cs diff --git a/src/Subjects/Core/Domain/Subjects/Item/IItem.cs b/src/Subjects/Core.Domain/Subjects/Item/IItem.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Item/IItem.cs rename to src/Subjects/Core.Domain/Subjects/Item/IItem.cs diff --git a/src/Subjects/Core/Domain/Subjects/Item/IItemGroup.cs b/src/Subjects/Core.Domain/Subjects/Item/IItemGroup.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Item/IItemGroup.cs rename to src/Subjects/Core.Domain/Subjects/Item/IItemGroup.cs diff --git a/src/Subjects/Core/Domain/Subjects/Item/IItemType.cs b/src/Subjects/Core.Domain/Subjects/Item/IItemType.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Item/IItemType.cs rename to src/Subjects/Core.Domain/Subjects/Item/IItemType.cs diff --git a/src/Subjects/Core/Domain/Subjects/Item/Item.cs b/src/Subjects/Core.Domain/Subjects/Item/Item.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Item/Item.cs rename to src/Subjects/Core.Domain/Subjects/Item/Item.cs diff --git a/src/Subjects/Core/Domain/Subjects/Item/ItemGroup.cs b/src/Subjects/Core.Domain/Subjects/Item/ItemGroup.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Item/ItemGroup.cs rename to src/Subjects/Core.Domain/Subjects/Item/ItemGroup.cs diff --git a/src/Subjects/Core/Domain/Subjects/Item/ItemType.cs b/src/Subjects/Core.Domain/Subjects/Item/ItemType.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Item/ItemType.cs rename to src/Subjects/Core.Domain/Subjects/Item/ItemType.cs diff --git a/src/Subjects/Core/Domain/Subjects/Option/AssociateOption.cs b/src/Subjects/Core.Domain/Subjects/Option/AssociateOption.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Option/AssociateOption.cs rename to src/Subjects/Core.Domain/Subjects/Option/AssociateOption.cs diff --git a/src/Subjects/Core/Domain/Subjects/Option/IOption.cs b/src/Subjects/Core.Domain/Subjects/Option/IOption.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Option/IOption.cs rename to src/Subjects/Core.Domain/Subjects/Option/IOption.cs diff --git a/src/Subjects/Core/Domain/Subjects/Option/IOptionGroup.cs b/src/Subjects/Core.Domain/Subjects/Option/IOptionGroup.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Option/IOptionGroup.cs rename to src/Subjects/Core.Domain/Subjects/Option/IOptionGroup.cs diff --git a/src/Subjects/Core/Domain/Subjects/Option/Option.cs b/src/Subjects/Core.Domain/Subjects/Option/Option.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Option/Option.cs rename to src/Subjects/Core.Domain/Subjects/Option/Option.cs diff --git a/src/Subjects/Core/Domain/Subjects/Option/OptionGroup.cs b/src/Subjects/Core.Domain/Subjects/Option/OptionGroup.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Option/OptionGroup.cs rename to src/Subjects/Core.Domain/Subjects/Option/OptionGroup.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/IResource.cs b/src/Subjects/Core.Domain/Subjects/Resource/IResource.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/IResource.cs rename to src/Subjects/Core.Domain/Subjects/Resource/IResource.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/IResourceItem.cs b/src/Subjects/Core.Domain/Subjects/Resource/IResourceItem.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/IResourceItem.cs rename to src/Subjects/Core.Domain/Subjects/Resource/IResourceItem.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/IResourcePerson.cs b/src/Subjects/Core.Domain/Subjects/Resource/IResourcePerson.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/IResourcePerson.cs rename to src/Subjects/Core.Domain/Subjects/Resource/IResourcePerson.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/IResourceType.cs b/src/Subjects/Core.Domain/Subjects/Resource/IResourceType.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/IResourceType.cs rename to src/Subjects/Core.Domain/Subjects/Resource/IResourceType.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/Resource.cs b/src/Subjects/Core.Domain/Subjects/Resource/Resource.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/Resource.cs rename to src/Subjects/Core.Domain/Subjects/Resource/Resource.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/ResourceItem.cs b/src/Subjects/Core.Domain/Subjects/Resource/ResourceItem.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/ResourceItem.cs rename to src/Subjects/Core.Domain/Subjects/Resource/ResourceItem.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/ResourcePerson.cs b/src/Subjects/Core.Domain/Subjects/Resource/ResourcePerson.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/ResourcePerson.cs rename to src/Subjects/Core.Domain/Subjects/Resource/ResourcePerson.cs diff --git a/src/Subjects/Core/Domain/Subjects/Resource/ResourceType.cs b/src/Subjects/Core.Domain/Subjects/Resource/ResourceType.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Resource/ResourceType.cs rename to src/Subjects/Core.Domain/Subjects/Resource/ResourceType.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/IVenture.cs b/src/Subjects/Core.Domain/Subjects/Venture/IVenture.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/IVenture.cs rename to src/Subjects/Core.Domain/Subjects/Venture/IVenture.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/IVentureAssociateOption.cs b/src/Subjects/Core.Domain/Subjects/Venture/IVentureAssociateOption.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/IVentureAssociateOption.cs rename to src/Subjects/Core.Domain/Subjects/Venture/IVentureAssociateOption.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/IVentureDetail.cs b/src/Subjects/Core.Domain/Subjects/Venture/IVentureDetail.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/IVentureDetail.cs rename to src/Subjects/Core.Domain/Subjects/Venture/IVentureDetail.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/IVentureOption.cs b/src/Subjects/Core.Domain/Subjects/Venture/IVentureOption.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/IVentureOption.cs rename to src/Subjects/Core.Domain/Subjects/Venture/IVentureOption.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/IVentureResource.cs b/src/Subjects/Core.Domain/Subjects/Venture/IVentureResource.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/IVentureResource.cs rename to src/Subjects/Core.Domain/Subjects/Venture/IVentureResource.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/Venture.cs b/src/Subjects/Core.Domain/Subjects/Venture/Venture.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/Venture.cs rename to src/Subjects/Core.Domain/Subjects/Venture/Venture.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/VentureAssociateOption.cs b/src/Subjects/Core.Domain/Subjects/Venture/VentureAssociateOption.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/VentureAssociateOption.cs rename to src/Subjects/Core.Domain/Subjects/Venture/VentureAssociateOption.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/VentureDetail.cs b/src/Subjects/Core.Domain/Subjects/Venture/VentureDetail.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/VentureDetail.cs rename to src/Subjects/Core.Domain/Subjects/Venture/VentureDetail.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/VentureOption.cs b/src/Subjects/Core.Domain/Subjects/Venture/VentureOption.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/VentureOption.cs rename to src/Subjects/Core.Domain/Subjects/Venture/VentureOption.cs diff --git a/src/Subjects/Core/Domain/Subjects/Venture/VentureResource.cs b/src/Subjects/Core.Domain/Subjects/Venture/VentureResource.cs similarity index 100% rename from src/Subjects/Core/Domain/Subjects/Venture/VentureResource.cs rename to src/Subjects/Core.Domain/Subjects/Venture/VentureResource.cs diff --git a/src/Subjects/Core/Domain/favicon.ico b/src/Subjects/Core.Domain/favicon.ico similarity index 100% rename from src/Subjects/Core/Domain/favicon.ico rename to src/Subjects/Core.Domain/favicon.ico diff --git a/src/Subjects/Core/Domain/storeicon.png b/src/Subjects/Core.Domain/storeicon.png similarity index 100% rename from src/Subjects/Core/Domain/storeicon.png rename to src/Subjects/Core.Domain/storeicon.png diff --git a/src/Subjects/Goodtocode.Subjects.sln b/src/Subjects/Goodtocode.Subjects.sln index d22bf6f1..4142f06b 100644 --- a/src/Subjects/Goodtocode.Subjects.sln +++ b/src/Subjects/Goodtocode.Subjects.sln @@ -3,37 +3,29 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.5.33414.496 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{AFB1C448-C01D-419A-94D4-5E43C2DC4FFA}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{F7C79A97-5E66-4753-A967-0FEBF5C4F6BD}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Specs", "Specs", "{3FC64677-0627-43FD-B3CB-070425CBBAB2}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{480B6912-14D8-4B43-A6FA-902A1C0631C3}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5D8887CA-2929-4E91-9409-B3366F968527}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Core\Application\Application.csproj", "{0D65058A-AE89-41F5-A46C-0A1D43336C57}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Application", "Common\Common.Application\Common.Application.csproj", "{D5BF79A6-68B3-41B0-AB63-28E30DD87018}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "Core\Domain\Domain.csproj", "{9F755689-238D-4B0F-B980-A73F5E300762}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Domain", "Common\Common.Domain\Common.Domain.csproj", "{DCD762D0-8543-4436-969C-975A94833F20}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application.Unit", "Specs\Application.Unit\Application.Unit.csproj", "{E2B035C3-46D3-4624-ADE0-4933ED8D2083}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Infrastructure.ApiClient", "Common\Common.Infrastructure.ApiClient\Common.Infrastructure.ApiClient.csproj", "{38DDD951-3F89-41FE-A225-326DA46A39CF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "Infrastructure\Persistence\Persistence.csproj", "{40D2528E-1BB9-4994-ADED-F663E68CB762}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Application", "Core.Application\Core.Application.csproj", "{859E4300-2DB5-431A-9319-5AEA12552D85}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application.Integration", "Specs\Application.Integration\Application.Integration.csproj", "{AD03FBD9-E114-417F-A013-1B0970E318C4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Domain", "Core.Domain\Core.Domain.csproj", "{45163683-2F3E-400C-A4C3-8730ED889371}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api.WebApi", "Presentation\Api.WebApi\Api.WebApi.csproj", "{90C40206-51B2-468D-9DDF-ABEDA9910126}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure.Persistence", "Infrastructure.Persistence\Infrastructure.Persistence.csproj", "{6A5A99A9-AE09-4310-A332-FCE1D7E3BED8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web.BlazorServer", "Presentation\Web.BlazorServer\Web.BlazorServer.csproj", "{54E11167-6104-4007-A7BA-4569F2999F76}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Presentation.Api.WebApi", "Presentation.Api.WebApi\Presentation.Api.WebApi.csproj", "{F77242BC-0FEB-4921-8AA1-4C21ADFD61CC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web.BlazorStatic", "Presentation\Web.BlazorStatic\Web.BlazorStatic.csproj", "{2448A3C7-1BC1-4BE9-8608-08152D126704}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Presentation.Web.BlazorServer", "Presentation.Web.BlazorServer\Presentation.Web.BlazorServer.csproj", "{34AE3733-6973-4679-AE56-272A6C0FA17E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Application", "Common\Common.Application\Common.Application.csproj", "{D5BF79A6-68B3-41B0-AB63-28E30DD87018}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Presentation.Web.BlazorStatic", "Presentation.Web.BlazorStatic\Presentation.Web.BlazorStatic.csproj", "{3BCED1B9-9EFA-4835-9D41-28BBD8297075}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Domain", "Common\Common.Domain\Common.Domain.csproj", "{DCD762D0-8543-4436-969C-975A94833F20}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Specs.Integration", "Specs.Integration\Specs.Integration.csproj", "{38803827-63A1-4466-94D4-D52E9EA1DA4A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Infrastructure.ApiClient", "Common\Common.Infrastructure.ApiClient\Common.Infrastructure.ApiClient.csproj", "{38DDD951-3F89-41FE-A225-326DA46A39CF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Specs.Unit", "Specs.Unit\Specs.Unit.csproj", "{B1912655-E309-4886-A882-1C384ACFB165}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -41,38 +33,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0D65058A-AE89-41F5-A46C-0A1D43336C57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0D65058A-AE89-41F5-A46C-0A1D43336C57}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D65058A-AE89-41F5-A46C-0A1D43336C57}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D65058A-AE89-41F5-A46C-0A1D43336C57}.Release|Any CPU.Build.0 = Release|Any CPU - {9F755689-238D-4B0F-B980-A73F5E300762}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F755689-238D-4B0F-B980-A73F5E300762}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F755689-238D-4B0F-B980-A73F5E300762}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F755689-238D-4B0F-B980-A73F5E300762}.Release|Any CPU.Build.0 = Release|Any CPU - {E2B035C3-46D3-4624-ADE0-4933ED8D2083}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E2B035C3-46D3-4624-ADE0-4933ED8D2083}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E2B035C3-46D3-4624-ADE0-4933ED8D2083}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E2B035C3-46D3-4624-ADE0-4933ED8D2083}.Release|Any CPU.Build.0 = Release|Any CPU - {40D2528E-1BB9-4994-ADED-F663E68CB762}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {40D2528E-1BB9-4994-ADED-F663E68CB762}.Debug|Any CPU.Build.0 = Debug|Any CPU - {40D2528E-1BB9-4994-ADED-F663E68CB762}.Release|Any CPU.ActiveCfg = Release|Any CPU - {40D2528E-1BB9-4994-ADED-F663E68CB762}.Release|Any CPU.Build.0 = Release|Any CPU - {AD03FBD9-E114-417F-A013-1B0970E318C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AD03FBD9-E114-417F-A013-1B0970E318C4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AD03FBD9-E114-417F-A013-1B0970E318C4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AD03FBD9-E114-417F-A013-1B0970E318C4}.Release|Any CPU.Build.0 = Release|Any CPU - {90C40206-51B2-468D-9DDF-ABEDA9910126}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {90C40206-51B2-468D-9DDF-ABEDA9910126}.Debug|Any CPU.Build.0 = Debug|Any CPU - {90C40206-51B2-468D-9DDF-ABEDA9910126}.Release|Any CPU.ActiveCfg = Release|Any CPU - {90C40206-51B2-468D-9DDF-ABEDA9910126}.Release|Any CPU.Build.0 = Release|Any CPU - {54E11167-6104-4007-A7BA-4569F2999F76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {54E11167-6104-4007-A7BA-4569F2999F76}.Debug|Any CPU.Build.0 = Debug|Any CPU - {54E11167-6104-4007-A7BA-4569F2999F76}.Release|Any CPU.ActiveCfg = Release|Any CPU - {54E11167-6104-4007-A7BA-4569F2999F76}.Release|Any CPU.Build.0 = Release|Any CPU - {2448A3C7-1BC1-4BE9-8608-08152D126704}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2448A3C7-1BC1-4BE9-8608-08152D126704}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2448A3C7-1BC1-4BE9-8608-08152D126704}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2448A3C7-1BC1-4BE9-8608-08152D126704}.Release|Any CPU.Build.0 = Release|Any CPU {D5BF79A6-68B3-41B0-AB63-28E30DD87018}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D5BF79A6-68B3-41B0-AB63-28E30DD87018}.Debug|Any CPU.Build.0 = Debug|Any CPU {D5BF79A6-68B3-41B0-AB63-28E30DD87018}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -85,19 +45,43 @@ Global {38DDD951-3F89-41FE-A225-326DA46A39CF}.Debug|Any CPU.Build.0 = Debug|Any CPU {38DDD951-3F89-41FE-A225-326DA46A39CF}.Release|Any CPU.ActiveCfg = Release|Any CPU {38DDD951-3F89-41FE-A225-326DA46A39CF}.Release|Any CPU.Build.0 = Release|Any CPU + {859E4300-2DB5-431A-9319-5AEA12552D85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {859E4300-2DB5-431A-9319-5AEA12552D85}.Debug|Any CPU.Build.0 = Debug|Any CPU + {859E4300-2DB5-431A-9319-5AEA12552D85}.Release|Any CPU.ActiveCfg = Release|Any CPU + {859E4300-2DB5-431A-9319-5AEA12552D85}.Release|Any CPU.Build.0 = Release|Any CPU + {45163683-2F3E-400C-A4C3-8730ED889371}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45163683-2F3E-400C-A4C3-8730ED889371}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45163683-2F3E-400C-A4C3-8730ED889371}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45163683-2F3E-400C-A4C3-8730ED889371}.Release|Any CPU.Build.0 = Release|Any CPU + {6A5A99A9-AE09-4310-A332-FCE1D7E3BED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A5A99A9-AE09-4310-A332-FCE1D7E3BED8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A5A99A9-AE09-4310-A332-FCE1D7E3BED8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A5A99A9-AE09-4310-A332-FCE1D7E3BED8}.Release|Any CPU.Build.0 = Release|Any CPU + {F77242BC-0FEB-4921-8AA1-4C21ADFD61CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F77242BC-0FEB-4921-8AA1-4C21ADFD61CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F77242BC-0FEB-4921-8AA1-4C21ADFD61CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F77242BC-0FEB-4921-8AA1-4C21ADFD61CC}.Release|Any CPU.Build.0 = Release|Any CPU + {34AE3733-6973-4679-AE56-272A6C0FA17E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {34AE3733-6973-4679-AE56-272A6C0FA17E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {34AE3733-6973-4679-AE56-272A6C0FA17E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {34AE3733-6973-4679-AE56-272A6C0FA17E}.Release|Any CPU.Build.0 = Release|Any CPU + {3BCED1B9-9EFA-4835-9D41-28BBD8297075}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3BCED1B9-9EFA-4835-9D41-28BBD8297075}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3BCED1B9-9EFA-4835-9D41-28BBD8297075}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3BCED1B9-9EFA-4835-9D41-28BBD8297075}.Release|Any CPU.Build.0 = Release|Any CPU + {38803827-63A1-4466-94D4-D52E9EA1DA4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {38803827-63A1-4466-94D4-D52E9EA1DA4A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {38803827-63A1-4466-94D4-D52E9EA1DA4A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {38803827-63A1-4466-94D4-D52E9EA1DA4A}.Release|Any CPU.Build.0 = Release|Any CPU + {B1912655-E309-4886-A882-1C384ACFB165}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B1912655-E309-4886-A882-1C384ACFB165}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1912655-E309-4886-A882-1C384ACFB165}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B1912655-E309-4886-A882-1C384ACFB165}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {0D65058A-AE89-41F5-A46C-0A1D43336C57} = {AFB1C448-C01D-419A-94D4-5E43C2DC4FFA} - {9F755689-238D-4B0F-B980-A73F5E300762} = {AFB1C448-C01D-419A-94D4-5E43C2DC4FFA} - {E2B035C3-46D3-4624-ADE0-4933ED8D2083} = {3FC64677-0627-43FD-B3CB-070425CBBAB2} - {40D2528E-1BB9-4994-ADED-F663E68CB762} = {F7C79A97-5E66-4753-A967-0FEBF5C4F6BD} - {AD03FBD9-E114-417F-A013-1B0970E318C4} = {3FC64677-0627-43FD-B3CB-070425CBBAB2} - {90C40206-51B2-468D-9DDF-ABEDA9910126} = {480B6912-14D8-4B43-A6FA-902A1C0631C3} - {54E11167-6104-4007-A7BA-4569F2999F76} = {480B6912-14D8-4B43-A6FA-902A1C0631C3} - {2448A3C7-1BC1-4BE9-8608-08152D126704} = {480B6912-14D8-4B43-A6FA-902A1C0631C3} {D5BF79A6-68B3-41B0-AB63-28E30DD87018} = {5D8887CA-2929-4E91-9409-B3366F968527} {DCD762D0-8543-4436-969C-975A94833F20} = {5D8887CA-2929-4E91-9409-B3366F968527} {38DDD951-3F89-41FE-A225-326DA46A39CF} = {5D8887CA-2929-4E91-9409-B3366F968527} diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/AssociateConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/AssociateConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/AssociateConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/AssociateConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/AssociateDetailConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/AssociateDetailConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/AssociateDetailConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/AssociateDetailConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/AssociateOptionConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/AssociateOptionConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/AssociateOptionConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/AssociateOptionConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/BusinessConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/BusinessConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/BusinessConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/BusinessConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/DetailConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/DetailConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/DetailConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/DetailConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/DetailTypeConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/DetailTypeConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/DetailTypeConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/DetailTypeConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/GenderConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/GenderConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/GenderConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/GenderConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/GovernmentConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/GovernmentConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/GovernmentConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/GovernmentConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/ItemConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/ItemConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/ItemConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/ItemConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/ItemGroupConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/ItemGroupConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/ItemGroupConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/ItemGroupConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/ItemTypeConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/ItemTypeConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/ItemTypeConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/ItemTypeConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/OptionConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/OptionConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/OptionConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/OptionConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/OptionGroupConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/OptionGroupConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/OptionGroupConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/OptionGroupConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/PersonConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/PersonConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/PersonConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/PersonConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/ResourceConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/ResourceConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/ResourceConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/ResourceConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/ResourceItemConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/ResourceItemConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/ResourceItemConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/ResourceItemConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/ResourcePersonConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/ResourcePersonConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/ResourcePersonConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/ResourcePersonConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/ResourceTypeConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/ResourceTypeConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/ResourceTypeConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/ResourceTypeConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/VentureAssociateOptionConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/VentureAssociateOptionConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/VentureAssociateOptionConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/VentureAssociateOptionConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/VentureConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/VentureConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/VentureConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/VentureConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/VentureDetailConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/VentureDetailConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/VentureDetailConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/VentureDetailConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/VentureOptionConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/VentureOptionConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/VentureOptionConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/VentureOptionConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/Configurations/VentureResourceConfig.cs b/src/Subjects/Infrastructure.Persistence/Configurations/VentureResourceConfig.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Configurations/VentureResourceConfig.cs rename to src/Subjects/Infrastructure.Persistence/Configurations/VentureResourceConfig.cs diff --git a/src/Subjects/Infrastructure/Persistence/ConfigureServices.cs b/src/Subjects/Infrastructure.Persistence/ConfigureServices.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/ConfigureServices.cs rename to src/Subjects/Infrastructure.Persistence/ConfigureServices.cs diff --git a/src/Subjects/Infrastructure/Persistence/Contexts/SubjectsDbContext.cs b/src/Subjects/Infrastructure.Persistence/Contexts/SubjectsDbContext.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Contexts/SubjectsDbContext.cs rename to src/Subjects/Infrastructure.Persistence/Contexts/SubjectsDbContext.cs diff --git a/src/Subjects/Infrastructure/Persistence/Persistence.csproj b/src/Subjects/Infrastructure.Persistence/Infrastructure.Persistence.csproj similarity index 91% rename from src/Subjects/Infrastructure/Persistence/Persistence.csproj rename to src/Subjects/Infrastructure.Persistence/Infrastructure.Persistence.csproj index 61262111..7d1228a7 100644 --- a/src/Subjects/Infrastructure/Persistence/Persistence.csproj +++ b/src/Subjects/Infrastructure.Persistence/Infrastructure.Persistence.csproj @@ -23,7 +23,6 @@ - - + \ No newline at end of file diff --git a/src/Subjects/Infrastructure/Persistence/Repositories/BusinessRepo.cs b/src/Subjects/Infrastructure.Persistence/Repositories/BusinessRepo.cs similarity index 53% rename from src/Subjects/Infrastructure/Persistence/Repositories/BusinessRepo.cs rename to src/Subjects/Infrastructure.Persistence/Repositories/BusinessRepo.cs index a09bba9d..226c8263 100644 --- a/src/Subjects/Infrastructure/Persistence/Repositories/BusinessRepo.cs +++ b/src/Subjects/Infrastructure.Persistence/Repositories/BusinessRepo.cs @@ -1,6 +1,7 @@ using CSharpFunctionalExtensions; using Goodtocode.Subjects.Application; using Goodtocode.Subjects.Domain; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using System.Data; @@ -30,12 +31,31 @@ public async Task>> GetBusinessesByNameAsync(string return Result.Success(businessResult); } - public async Task AddBusinessAsync(IBusinessObject businessInfo, CancellationToken cancellationToken) + public async Task> AddBusinessAsync(IBusinessObject businessInfo, CancellationToken cancellationToken) { if (businessInfo == null) - return Result.Failure("Cannot add. Business is null."); - var businessResult = await _context.Business.AddAsync((BusinessEntity)businessInfo, cancellationToken); - return Result.Success(businessResult); + return Result.Failure("Cannot add. Business is null."); + + var businessEntity = new BusinessEntity + { + BusinessName = businessInfo.BusinessName, + TaxNumber = businessInfo.TaxNumber + }; + + var businessResult = await _context.Business.AddAsync(businessEntity, cancellationToken); + + try + { + await _context.SaveChangesAsync(cancellationToken); + } + catch (DbUpdateException e) + when (e.InnerException?.InnerException is SqlException sqlEx && + (sqlEx.Number == 2601 || sqlEx.Number == 2627)) + { + return Result.Failure("Cannot add. Duplicate record exists."); + } + + return Result.Success(businessResult.Entity); } public async Task UpdateBusinessAsync(IBusinessEntity businessInfo, CancellationToken cancellationToken) @@ -45,7 +65,17 @@ public async Task UpdateBusinessAsync(IBusinessEntity businessInfo, Canc return Result.Failure("Cannot update. Business not found."); businessResult.BusinessName = businessInfo.BusinessName; businessResult.TaxNumber = businessInfo.TaxNumber; - var result = await _context.SaveChangesAsync(cancellationToken); + await _context.SaveChangesAsync(cancellationToken); + return Result.Success(); + } + + public async Task DeleteBusinessAsync(Guid businessKey, CancellationToken cancellationToken) + { + var businessResult = await _context.Business.FindAsync(new object?[] { businessKey, cancellationToken }, cancellationToken: cancellationToken); + if (businessResult == null) + return Result.Failure("Cannot delete. Business not found."); + _context.Business.Remove(businessResult); + await _context.SaveChangesAsync(cancellationToken); return Result.Success(); } } \ No newline at end of file diff --git a/src/Subjects/Infrastructure/Persistence/Repositories/PersonRepo.cs b/src/Subjects/Infrastructure.Persistence/Repositories/PersonRepo.cs similarity index 100% rename from src/Subjects/Infrastructure/Persistence/Repositories/PersonRepo.cs rename to src/Subjects/Infrastructure.Persistence/Repositories/PersonRepo.cs diff --git a/src/Subjects/Infrastructure/Persistence/favicon.ico b/src/Subjects/Infrastructure.Persistence/favicon.ico similarity index 100% rename from src/Subjects/Infrastructure/Persistence/favicon.ico rename to src/Subjects/Infrastructure.Persistence/favicon.ico diff --git a/src/Subjects/Infrastructure/Persistence/storeicon.png b/src/Subjects/Infrastructure.Persistence/storeicon.png similarity index 100% rename from src/Subjects/Infrastructure/Persistence/storeicon.png rename to src/Subjects/Infrastructure.Persistence/storeicon.png diff --git a/src/Subjects/Presentation/Api.WebApi/Common/ApiExceptionFilterAttribute.cs b/src/Subjects/Presentation.Api.WebApi/Common/ApiExceptionFilterAttribute.cs similarity index 88% rename from src/Subjects/Presentation/Api.WebApi/Common/ApiExceptionFilterAttribute.cs rename to src/Subjects/Presentation.Api.WebApi/Common/ApiExceptionFilterAttribute.cs index c3a5f016..6e9ba3d8 100644 --- a/src/Subjects/Presentation/Api.WebApi/Common/ApiExceptionFilterAttribute.cs +++ b/src/Subjects/Presentation.Api.WebApi/Common/ApiExceptionFilterAttribute.cs @@ -22,6 +22,7 @@ public ApiExceptionFilterAttribute() _exceptionHandlers = new Dictionary> { {typeof(ValidationException), HandleValidationException}, + {typeof(ConflictException), HandleConflictException}, {typeof(NotFoundException), HandleNotFoundException}, {typeof(UnauthorizedAccessException), HandleUnauthorizedAccessException}, {typeof(ForbiddenAccessException), HandleForbiddenAccessException} @@ -83,6 +84,22 @@ private void HandleInvalidModelStateException(ExceptionContext context) context.ExceptionHandled = true; } + private void HandleConflictException(ExceptionContext context) + { + var exception = context.Exception as ConflictException ?? new ConflictException(); + + var details = new ProblemDetails + { + Type = "https://tools.ietf.org/html/rfc7231#section-6.5.8", + Title = "The specified resource has a conflict.", + Detail = exception.Message + }; + + context.Result = new ConflictObjectResult(details); + + context.ExceptionHandled = true; + } + private void HandleNotFoundException(ExceptionContext context) { var exception = context.Exception as NotFoundException ?? new NotFoundException(); diff --git a/src/Subjects/Presentation/Api.WebApi/Common/BaseController.cs b/src/Subjects/Presentation.Api.WebApi/Common/BaseController.cs similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/Common/BaseController.cs rename to src/Subjects/Presentation.Api.WebApi/Common/BaseController.cs diff --git a/src/Subjects/Presentation/Api.WebApi/Common/ConfigureSwaggerOptions.cs b/src/Subjects/Presentation.Api.WebApi/Common/ConfigureSwaggerOptions.cs similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/Common/ConfigureSwaggerOptions.cs rename to src/Subjects/Presentation.Api.WebApi/Common/ConfigureSwaggerOptions.cs diff --git a/src/Subjects/Presentation/Api.WebApi/Controllers/BusinessController.cs b/src/Subjects/Presentation.Api.WebApi/Controllers/BusinessController.cs similarity index 66% rename from src/Subjects/Presentation/Api.WebApi/Controllers/BusinessController.cs rename to src/Subjects/Presentation.Api.WebApi/Controllers/BusinessController.cs index 5818a359..54f88e13 100644 --- a/src/Subjects/Presentation/Api.WebApi/Controllers/BusinessController.cs +++ b/src/Subjects/Presentation.Api.WebApi/Controllers/BusinessController.cs @@ -1,4 +1,5 @@ -using Goodtocode.Subjects.Application; +using Goodtocode.Common.Extensions; +using Goodtocode.Subjects.Application; using Goodtocode.Subjects.Domain; using Goodtocode.Subjects.WebApi.Common; using Microsoft.AspNetCore.Mvc; @@ -57,21 +58,23 @@ public async Task Get(Guid key) /// /// Sample request: /// "api-version": 1 - /// HttpPost Body + /// HttpPut Body /// { /// "BusinessName": "My Business", /// "TaxNumber": "12-445666" /// } /// - /// bool + /// Created Item URI and Object [HttpPut(Name = "AddBusinessCommand")] [ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task Put([FromBody] AddBusinessCommand command) + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task Put([FromBody] BusinessObject business) { - await Mediator.Send(command); + var command = business.CopyPropertiesSafe(); + var createdEntity = await Mediator.Send(command); - return Ok(); + return Created(new Uri($"{Request.Path}/{createdEntity.Key}", UriKind.Relative), createdEntity); } /// @@ -79,7 +82,7 @@ public async Task Put([FromBody] AddBusinessCommand command) /// /// /// Sample request: - /// "BusinessKey": d3d42e6e-87c5-49d6-aec0-7995711d6612, + /// "BusinessKey": d3d42e6e-87c5-49d6-aec0-7995711d6612, /// "api-version": 1 /// HttpPost Body /// { @@ -91,10 +94,41 @@ public async Task Put([FromBody] AddBusinessCommand command) [HttpPost(Name = "UpdateBusinessCommand")] [ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public async Task Post(Guid businessKey, [FromBody] UpdateBusinessCommand command) + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task Post(Guid businessKey, [FromBody] BusinessObject business) { - await Mediator.Send(command); + var command = business.CopyPropertiesSafe(); + command.BusinessKey = businessKey; + await Mediator.Send(command); + return Ok(); } + + /// + /// Delete a Business + /// + /// + /// Sample request: + /// "BusinessKey": d3d42e6e-87c5-49d6-aec0-7995711d6612, + /// "api-version": 1 + /// HttpDelete Body + /// { + /// } + /// + /// bool + [HttpDelete(Name = "DeleteBusinessCommand")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task Delete(Guid businessKey) + { + + var command = new DeleteBusinessCommand + { + BusinessKey = businessKey + }; + await Mediator.Send(command); + + return NoContent(); + } } \ No newline at end of file diff --git a/src/Subjects/Presentation/Api.WebApi/Controllers/BusinessesController.cs b/src/Subjects/Presentation.Api.WebApi/Controllers/BusinessesController.cs similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/Controllers/BusinessesController.cs rename to src/Subjects/Presentation.Api.WebApi/Controllers/BusinessesController.cs diff --git a/src/Subjects/Presentation/Api.WebApi/Goodtocode.Subjects.WebApi.xml b/src/Subjects/Presentation.Api.WebApi/Goodtocode.Subjects.WebApi.xml similarity index 87% rename from src/Subjects/Presentation/Api.WebApi/Goodtocode.Subjects.WebApi.xml rename to src/Subjects/Presentation.Api.WebApi/Goodtocode.Subjects.WebApi.xml index a7384d24..9b27486d 100644 --- a/src/Subjects/Presentation/Api.WebApi/Goodtocode.Subjects.WebApi.xml +++ b/src/Subjects/Presentation.Api.WebApi/Goodtocode.Subjects.WebApi.xml @@ -70,28 +70,28 @@ BusinessEntity - + Add Business Sample request: "api-version": 1 - HttpPost Body + HttpPut Body { "BusinessName": "My Business", "TaxNumber": "12-445666" } - bool + Created Item URI and Object - + Update Business Sample request: - "BusinessKey": d3d42e6e-87c5-49d6-aec0-7995711d6612, + "BusinessKey": d3d42e6e-87c5-49d6-aec0-7995711d6612, "api-version": 1 HttpPost Body { @@ -101,6 +101,20 @@ bool + + + Delete a Business + + + Sample request: + "BusinessKey": d3d42e6e-87c5-49d6-aec0-7995711d6612, + "api-version": 1 + HttpDelete Body + { + } + + bool + Businesses Controller V1.0 diff --git a/src/Subjects/Presentation/Api.WebApi/Api.WebApi.csproj b/src/Subjects/Presentation.Api.WebApi/Presentation.Api.WebApi.csproj similarity index 95% rename from src/Subjects/Presentation/Api.WebApi/Api.WebApi.csproj rename to src/Subjects/Presentation.Api.WebApi/Presentation.Api.WebApi.csproj index f72136c2..c88d2c67 100644 --- a/src/Subjects/Presentation/Api.WebApi/Api.WebApi.csproj +++ b/src/Subjects/Presentation.Api.WebApi/Presentation.Api.WebApi.csproj @@ -28,6 +28,6 @@ - + diff --git a/src/Subjects/Presentation/Api.WebApi/Program.cs b/src/Subjects/Presentation.Api.WebApi/Program.cs similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/Program.cs rename to src/Subjects/Presentation.Api.WebApi/Program.cs diff --git a/src/Subjects/Presentation/Api.WebApi/Properties/ServiceDependencies/local/appInsights1.arm.json b/src/Subjects/Presentation.Api.WebApi/Properties/ServiceDependencies/local/appInsights1.arm.json similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/Properties/ServiceDependencies/local/appInsights1.arm.json rename to src/Subjects/Presentation.Api.WebApi/Properties/ServiceDependencies/local/appInsights1.arm.json diff --git a/src/Subjects/Presentation/Api.WebApi/Properties/serviceDependencies.json b/src/Subjects/Presentation.Api.WebApi/Properties/serviceDependencies.json similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/Properties/serviceDependencies.json rename to src/Subjects/Presentation.Api.WebApi/Properties/serviceDependencies.json diff --git a/src/Subjects/Presentation/Api.WebApi/Properties/serviceDependencies.local.json b/src/Subjects/Presentation.Api.WebApi/Properties/serviceDependencies.local.json similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/Properties/serviceDependencies.local.json rename to src/Subjects/Presentation.Api.WebApi/Properties/serviceDependencies.local.json diff --git a/src/Subjects/Presentation/Api.WebApi/appsettings.Development.json b/src/Subjects/Presentation.Api.WebApi/appsettings.Development.json similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/appsettings.Development.json rename to src/Subjects/Presentation.Api.WebApi/appsettings.Development.json diff --git a/src/Subjects/Presentation/Api.WebApi/appsettings.Production.json b/src/Subjects/Presentation.Api.WebApi/appsettings.Production.json similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/appsettings.Production.json rename to src/Subjects/Presentation.Api.WebApi/appsettings.Production.json diff --git a/src/Subjects/Presentation/Api.WebApi/appsettings.json b/src/Subjects/Presentation.Api.WebApi/appsettings.json similarity index 100% rename from src/Subjects/Presentation/Api.WebApi/appsettings.json rename to src/Subjects/Presentation.Api.WebApi/appsettings.json diff --git a/src/Subjects/Presentation/Web.BlazorServer/.config/dotnet-tools.json b/src/Subjects/Presentation.Web.BlazorServer/.config/dotnet-tools.json similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/.config/dotnet-tools.json rename to src/Subjects/Presentation.Web.BlazorServer/.config/dotnet-tools.json diff --git a/src/Subjects/Presentation/Web.BlazorServer/App.razor b/src/Subjects/Presentation.Web.BlazorServer/App.razor similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/App.razor rename to src/Subjects/Presentation.Web.BlazorServer/App.razor diff --git a/src/Subjects/Presentation.Web.BlazorServer/Data/BusinessService.cs b/src/Subjects/Presentation.Web.BlazorServer/Data/BusinessService.cs new file mode 100644 index 00000000..3d920d04 --- /dev/null +++ b/src/Subjects/Presentation.Web.BlazorServer/Data/BusinessService.cs @@ -0,0 +1,90 @@ +using Goodtocode.Common.Extensions; +using Goodtocode.Subjects.Application; +using Goodtocode.Subjects.BlazorServer.Models; +using Goodtocode.Subjects.BlazorServer.Pages.Business; +using Goodtocode.Subjects.Domain; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using System.Net; +using System.Text.Json; + +namespace Goodtocode.Subjects.BlazorServer.Data; + +public class BusinessService +{ + private readonly IHttpClientFactory _clientFactory; + + public BusinessService(IHttpClientFactory clientFactory) + { + _clientFactory = clientFactory; + } + + public async Task GetBusinessAsync(Guid businessKey) + { + var httpClient = _clientFactory.CreateClient("SubjectsApiClient"); + var response = await httpClient.GetAsync($"{httpClient.BaseAddress}/Business?key={businessKey}&api-version=1"); + var business = new BusinessEntity(); + if (response.StatusCode != HttpStatusCode.NotFound) + { + response.EnsureSuccessStatusCode(); + business = JsonSerializer.Deserialize(response.Content.ReadAsStream()); + if (business == null) + throw new Exception(); + } + return business; + } + + public async Task> GetBusinessesAsync(string name) + { + var business = new List(); + var httpClient = _clientFactory.CreateClient("SubjectsApiClient"); + var response = await httpClient.GetAsync($"{httpClient.BaseAddress}/Businesses?name={name}&api-version=1"); + if (response.StatusCode != HttpStatusCode.NotFound) + { + response.EnsureSuccessStatusCode(); + business = JsonSerializer.Deserialize>(response.Content.ReadAsStream()) ?? throw new Exception("Deserialization failed."); + } + + return business; + } + + public async Task CreateBusinessAsync(BusinessObject business) + { + BusinessEntity? businessCreated = new(); + var httpClient = _clientFactory.CreateClient("SubjectsApiClient"); + var response = await httpClient.PutAsJsonAsync($"{httpClient.BaseAddress}/Business?api-version=1", business); + + if (response.StatusCode == HttpStatusCode.Created) + businessCreated = JsonSerializer.Deserialize(await response.Content.ReadAsStreamAsync()) ?? throw new Exception("Deserialization failed."); + + response.EnsureSuccessStatusCode(); + + return businessCreated; + } + + public async Task UpdateBusinessAsync(BusinessUpdateModel business) + { + BusinessEntity? businessUpdated = null; + var httpClient = _clientFactory.CreateClient("SubjectsApiClient"); + var response = await httpClient.PostAsJsonAsync($"{httpClient.BaseAddress}/Business?key={business.BusinessKey}api-version=1", business.CopyPropertiesSafe()); + + if (response.StatusCode == HttpStatusCode.OK) + businessUpdated = JsonSerializer.Deserialize(await response.Content.ReadAsStreamAsync()); + if (businessUpdated == null) + throw new Exception(); + + response.EnsureSuccessStatusCode(); + + return businessUpdated; + } + + public async Task DeleteBusinessAsync(Guid businessKey) + { + BusinessEntity? businessUpdated = null; + var httpClient = _clientFactory.CreateClient("SubjectsApiClient"); + var response = await httpClient.DeleteAsync($"{httpClient.BaseAddress}/Business?key={businessKey}api-version=1"); + + response.EnsureSuccessStatusCode(); + + return businessUpdated; + } +} \ No newline at end of file diff --git a/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessCreateModel.cs b/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessCreateModel.cs new file mode 100644 index 00000000..67464e9d --- /dev/null +++ b/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessCreateModel.cs @@ -0,0 +1,11 @@ +using Goodtocode.Subjects.Domain; +using System.ComponentModel.DataAnnotations; + +namespace Goodtocode.Subjects.BlazorServer.Models; + +public class BusinessCreateModel : BusinessObject +{ + [Required] + public string BusinessName { get; set; } = string.Empty; + public string TaxNumber { get; set; } = string.Empty; +} diff --git a/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessSearchModel.cs b/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessSearchModel.cs new file mode 100644 index 00000000..26efd455 --- /dev/null +++ b/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessSearchModel.cs @@ -0,0 +1,9 @@ +using System.ComponentModel.DataAnnotations; + +namespace Goodtocode.Subjects.BlazorServer.Models; + +public class BusinessSearchModel +{ + [Required] + public string Name { get; set; } = string.Empty; +} diff --git a/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessUpdateModel.cs b/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessUpdateModel.cs new file mode 100644 index 00000000..b0f8a193 --- /dev/null +++ b/src/Subjects/Presentation.Web.BlazorServer/Models/BusinessUpdateModel.cs @@ -0,0 +1,13 @@ +using Goodtocode.Subjects.Domain; +using System.ComponentModel.DataAnnotations; + +namespace Goodtocode.Subjects.BlazorServer.Models; + +public class BusinessUpdateModel : BusinessEntity +{ + [Required] + public Guid BusinessKey { get; set; } = default; + [Required] + public string BusinessName { get; set; } = string.Empty; + public string TaxNumber { get; set; } = string.Empty; +} diff --git a/src/Subjects/Presentation.Web.BlazorServer/Pages/Business/BusinessCreate.razor b/src/Subjects/Presentation.Web.BlazorServer/Pages/Business/BusinessCreate.razor new file mode 100644 index 00000000..85d06c63 --- /dev/null +++ b/src/Subjects/Presentation.Web.BlazorServer/Pages/Business/BusinessCreate.razor @@ -0,0 +1,54 @@ +@page "/businesscreate" +@using Goodtocode.Subjects.BlazorServer.Data; +@using Goodtocode.Subjects.BlazorServer.Models; +@using Goodtocode.Subjects.Domain; +@using System.ComponentModel.DataAnnotations; + +@inject BusinessService Service + +Create a Business + +

Business Create

+ +

Create a businesses

+ + + +
+ + +
+
+ + +
+ + + +
+ +@code { + private BusinessCreateModel business = new BusinessCreateModel(); + private string alertMessage = string.Empty; + private CancellationTokenSource cts = new CancellationTokenSource(); + private async Task CreateBusineses() + { + if (!Validator.TryValidateObject(business, + new ValidationContext(business, serviceProvider: null, items: null), new List(), true)) return; + + if (cts != null) cts.Cancel(); + cts = new CancellationTokenSource(); + try + { + await Task.Delay(500, cts.Token); + alertMessage = string.Empty; + await Service.CreateBusinessAsync(business); + alertMessage = $"{business.BusinessName} created"; + } + catch (TaskCanceledException) + { + // Ignore exception if task was cancelled + } + } +} diff --git a/src/Subjects/Presentation.Web.BlazorServer/Pages/Business/BusinessList.razor b/src/Subjects/Presentation.Web.BlazorServer/Pages/Business/BusinessList.razor new file mode 100644 index 00000000..01596e3d --- /dev/null +++ b/src/Subjects/Presentation.Web.BlazorServer/Pages/Business/BusinessList.razor @@ -0,0 +1,82 @@ +@page "/businesssearch" +@using Goodtocode.Subjects.BlazorServer.Data; +@using Goodtocode.Subjects.BlazorServer.Models; +@using Goodtocode.Subjects.Domain; +@using System.ComponentModel.DataAnnotations; + +@inject BusinessService Service + +Business Search + + + +
+ + +
+ + + +
+ + +@if (businesses.Count() > 0) +{ + + + + + + + + + + @foreach (var business in businesses) + { + + + + + + } + +
KeyNameTax Number
@business.BusinessKey@business.BusinessName@business.TaxNumber
+} + +@code { + private string alertMessage = string.Empty; + private BusinessSearchModel businessSearch = new BusinessSearchModel(); + private IEnumerable businesses = new List(); + private CancellationTokenSource cts = new CancellationTokenSource(); + private bool processing; + + private async Task GetBusineses() + { + alertMessage = string.Empty; + + if (!Validator.TryValidateObject(businessSearch, + new ValidationContext(businessSearch, serviceProvider: null, items: null), new List(), true)) return; + + if (cts != null) cts.Cancel(); + cts = new CancellationTokenSource(); + try + { + processing = true; + await Task.Delay(500, cts.Token); + businesses = await Service.GetBusinessesAsync(businessSearch.Name); + if (businesses.Count() == 0) + alertMessage = "No businesses found"; + } + catch (TaskCanceledException) + { + // Ignore exception if task was cancelled + } + finally + { + processing = false; + } + } +} diff --git a/src/Subjects/Presentation/Web.BlazorServer/Pages/Error.cshtml b/src/Subjects/Presentation.Web.BlazorServer/Pages/Error.cshtml similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Pages/Error.cshtml rename to src/Subjects/Presentation.Web.BlazorServer/Pages/Error.cshtml diff --git a/src/Subjects/Presentation/Web.BlazorServer/Pages/Error.cshtml.cs b/src/Subjects/Presentation.Web.BlazorServer/Pages/Error.cshtml.cs similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Pages/Error.cshtml.cs rename to src/Subjects/Presentation.Web.BlazorServer/Pages/Error.cshtml.cs diff --git a/src/Subjects/Presentation/Web.BlazorServer/Pages/Index.razor b/src/Subjects/Presentation.Web.BlazorServer/Pages/Index.razor similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Pages/Index.razor rename to src/Subjects/Presentation.Web.BlazorServer/Pages/Index.razor diff --git a/src/Subjects/Presentation/Web.BlazorServer/Pages/_Host.cshtml b/src/Subjects/Presentation.Web.BlazorServer/Pages/_Host.cshtml similarity index 84% rename from src/Subjects/Presentation/Web.BlazorServer/Pages/_Host.cshtml rename to src/Subjects/Presentation.Web.BlazorServer/Pages/_Host.cshtml index 8f696ff2..eb79cf81 100644 --- a/src/Subjects/Presentation/Web.BlazorServer/Pages/_Host.cshtml +++ b/src/Subjects/Presentation.Web.BlazorServer/Pages/_Host.cshtml @@ -9,7 +9,8 @@ - + + diff --git a/src/Subjects/Presentation/Web.BlazorServer/Web.BlazorServer.csproj b/src/Subjects/Presentation.Web.BlazorServer/Presentation.Web.BlazorServer.csproj similarity index 72% rename from src/Subjects/Presentation/Web.BlazorServer/Web.BlazorServer.csproj rename to src/Subjects/Presentation.Web.BlazorServer/Presentation.Web.BlazorServer.csproj index 36fda27b..bc28100d 100644 --- a/src/Subjects/Presentation/Web.BlazorServer/Web.BlazorServer.csproj +++ b/src/Subjects/Presentation.Web.BlazorServer/Presentation.Web.BlazorServer.csproj @@ -11,6 +11,14 @@ 0 + + + + + + + + @@ -23,8 +31,14 @@ - - + + + + + + + true + diff --git a/src/Subjects/Presentation/Web.BlazorServer/Program.cs b/src/Subjects/Presentation.Web.BlazorServer/Program.cs similarity index 90% rename from src/Subjects/Presentation/Web.BlazorServer/Program.cs rename to src/Subjects/Presentation.Web.BlazorServer/Program.cs index a9362219..acf7715e 100644 --- a/src/Subjects/Presentation/Web.BlazorServer/Program.cs +++ b/src/Subjects/Presentation.Web.BlazorServer/Program.cs @@ -32,6 +32,11 @@ builder.Services.AddServerSideBlazor() .AddMicrosoftIdentityConsentHandler(); +if (builder.Environment.IsDevelopment() || string.Equals(builder.Environment.EnvironmentName, "local", StringComparison.InvariantCultureIgnoreCase)) +{ + builder.WebHost.UseStaticWebAssets(); +} + builder.Services.AddApplicationInsightsTelemetry(options => { options.ConnectionString = builder.Configuration["ApplicationInsights:ConnectionString"]; @@ -40,19 +45,18 @@ builder.Services.AddApiClientServices("SubjectsApiClient", builder.Configuration["Subjects:Url"], new ClientCredentialSetting( builder.Configuration["Subjects:ClientId"], - builder.Configuration["SubjectsClientSecret"], + builder.Configuration["Subjects:ClientSecret"], builder.Configuration["Subjects:TokenUrl"], builder.Configuration["Subjects:Scope"]) ); -builder.Services.AddSingleton(); builder.Services.AddSingleton(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) -{ +{ app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); diff --git a/src/Subjects/Presentation/Web.BlazorServer/Properties/serviceDependencies.json b/src/Subjects/Presentation.Web.BlazorServer/Properties/serviceDependencies.json similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Properties/serviceDependencies.json rename to src/Subjects/Presentation.Web.BlazorServer/Properties/serviceDependencies.json diff --git a/src/Subjects/Presentation/Web.BlazorServer/Properties/serviceDependencies.local.json b/src/Subjects/Presentation.Web.BlazorServer/Properties/serviceDependencies.local.json similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Properties/serviceDependencies.local.json rename to src/Subjects/Presentation.Web.BlazorServer/Properties/serviceDependencies.local.json diff --git a/src/Subjects/Presentation/Web.BlazorServer/Shared/LoginDisplay.razor b/src/Subjects/Presentation.Web.BlazorServer/Shared/LoginDisplay.razor similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Shared/LoginDisplay.razor rename to src/Subjects/Presentation.Web.BlazorServer/Shared/LoginDisplay.razor diff --git a/src/Subjects/Presentation/Web.BlazorServer/Shared/MainLayout.razor b/src/Subjects/Presentation.Web.BlazorServer/Shared/MainLayout.razor similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Shared/MainLayout.razor rename to src/Subjects/Presentation.Web.BlazorServer/Shared/MainLayout.razor diff --git a/src/Subjects/Presentation/Web.BlazorServer/Shared/MainLayout.razor.css b/src/Subjects/Presentation.Web.BlazorServer/Shared/MainLayout.razor.css similarity index 100% rename from src/Subjects/Presentation/Web.BlazorServer/Shared/MainLayout.razor.css rename to src/Subjects/Presentation.Web.BlazorServer/Shared/MainLayout.razor.css diff --git a/src/Subjects/Presentation/Web.BlazorServer/Shared/NavMenu.razor b/src/Subjects/Presentation.Web.BlazorServer/Shared/NavMenu.razor similarity index 75% rename from src/Subjects/Presentation/Web.BlazorServer/Shared/NavMenu.razor rename to src/Subjects/Presentation.Web.BlazorServer/Shared/NavMenu.razor index 540f37f0..e28fca0d 100644 --- a/src/Subjects/Presentation/Web.BlazorServer/Shared/NavMenu.razor +++ b/src/Subjects/Presentation.Web.BlazorServer/Shared/NavMenu.razor @@ -1,6 +1,6 @@