Exemple #1
0
            public async Task <Unit> Handle(ClearAndReinitializeAllDataCommand request, CancellationToken cancellationToken)
            {
                await queryFacade.ExecuteAsync(@"
                    DELETE FROM EmployeeManagers
                    DELETE FROM Employees
                    IF EXISTS (SELECT * FROM sys.identity_columns WHERE OBJECT_NAME(OBJECT_ID) = 'Employees' AND last_value IS NOT NULL) DBCC CHECKIDENT (Employees, RESEED, 0);");

                return(Unit.Value);
            }
Exemple #2
0
            public async Task <DeleteTenantViewModel> Handle(DeleteTenantCommand request, CancellationToken cancellationToken)
            {
                var tenantViewModel = request.DeleteTenant;
                var tenantName      = await facade.QueryFirstOrDefaultAsync <string>(@"SELECT TOP 1 Name From Tenants WITH(NOLOCK) WHERE Id = @TenantId", tenantViewModel);

                if (tenantName.ToUpper() != tenantViewModel.ConfirmationCode.ToUpper())
                {
                    throw new ApplicationLayerException("Invalid confirmation provided for delete tenant command.");
                }

                using (var transaction = await context.Database.BeginTransactionAsync())
                {
                    var sqlTransaction = transaction.GetDbTransaction();
                    await facade.ExecuteAsync(
                        string.Join("\r\n", from t in facade.GetTenantTables() select $"DELETE FROM {t} WHERE TenantId = @TenantId")
                        + "\r\nDELETE FROM Tenants WHERE Id = @TenantId", tenantViewModel, sqlTransaction);

                    await transaction.CommitAsync();
                }
                return(tenantViewModel);
            }
 public static Task TurnOnIdentityIncrementAsync(this IApplicationWriteDbFacade facade, string tableName, IDbTransaction?transaction = null)
 => facade.ExecuteAsync(GetIdentityIncrementStatement(tableName, false), transaction: transaction);
 public static Task SetIdentitySeedForAllAspNetCoreTablesAsync(this IApplicationWriteDbFacade facade, int seedValue, IDbTransaction?transaction = null)
 => facade.ExecuteAsync(string.Join(Environment.NewLine, from t in aspNetCoreTablesOrderedByRelation select GetReseedStatement(t, seedValue)), transaction: transaction);
 public static Task SetIdentitySeedAsync(this IApplicationWriteDbFacade facade, string tableName, int seedValue, IDbTransaction?transaction = null)
 => facade.ExecuteAsync(GetReseedStatement(tableName, seedValue), transaction: transaction);
 public static Task ClearAllTablesAsync(this IApplicationWriteDbFacade facade, IDbTransaction?transaction = null)
 => facade.ExecuteAsync(string.Join(Environment.NewLine, from t in tablesOrderedByRelation select GetDeleteStatement(t)), transaction: transaction);