Exemplo n.º 1
0
        protected override async Task <bool> OnExecuteStepAsync(IContext context)
        {
            bool returnValue = false;

            //
            // Get a repository for IEmployeeEntity.
            //
            IQueryableRepository <IEmployeeEntity> repository = await this.RepositoryFactory.GetQueryableAsync <IEmployeeEntity>();

            //
            // Get the context. This can be disposed because it is defined as transient
            // in the container.
            //
            using (IRepositoryContext db = await repository.GetContextAsync())
            {
                //
                // Delete the database
                //
                this.Logger.LogInformation("Deleting existing database.");
                await db.EnsureDeletedAsync();

                //
                // Create the database
                //
                this.Logger.LogInformation($"Creating new empty database.");
                if (await db.EnsureCreatedAsync())
                {
                    returnValue = true;
                    this.Logger.LogInformation("Database was successfully created.");
                }
                else
                {
                    await this.StepFailedAsync(context, "Failed to create new database.");
                }
            }

            //
            // Since we are using transient lifetimes, we need to dispose.
            //
            await repository.TryDisposeAsync();

            return(returnValue);
        }