public void ConfigureDbContext(IServiceCollection services, string connectionString) { var customersConnectionString = connectionString.Replace("angular-my-microting-plugin", "eform-angular-basecustomer-plugin"); var orgConnectionString = connectionString.Replace("angular-my-microting-plugin", "angular-my-microting-organizations-plugin"); // todo: connection string, seed customers db, same for my microting db context services.AddDbContext <DigitalOceanDbContext>(o => o.UseMySql(connectionString, b => b.MigrationsAssembly(PluginAssembly().FullName))); services.AddDbContext <CustomersPnDbAnySql>(o => o.UseMySql(customersConnectionString, b => b.MigrationsAssembly(PluginAssembly().FullName))); services.AddDbContext <MyMicrotingDbContext>(o => o.UseMySql(orgConnectionString, b => b.MigrationsAssembly(PluginAssembly().FullName))); DigitalOceanDbContextFactory contextFactory = new DigitalOceanDbContextFactory(); using (DigitalOceanDbContext context = contextFactory.CreateDbContext(new[] { connectionString })) context.Database.Migrate(); CustomersPnContextFactory customersPnContextFactory = new CustomersPnContextFactory(); using (CustomersPnDbAnySql context = customersPnContextFactory.CreateDbContext(new[] { customersConnectionString })) context.Database.Migrate(); MyMicrotingDbContextFactory myMicrotingDbContextFactory = new MyMicrotingDbContextFactory(); using (MyMicrotingDbContext context = myMicrotingDbContextFactory.CreateDbContext(new[] { orgConnectionString })) context.Database.Migrate(); // Seed database SeedDatabase(connectionString); }
public MyMicrotingSettingsService(ILogger <MyMicrotingSettingsService> logger, ILocalizationService localizationService, IPluginDbOptions <MyMicrotingSettings> options, IHttpContextAccessor httpContextAccessor, DigitalOceanDbContext dbContext) { this.logger = logger; this.localizationService = localizationService; this.options = options; this.httpContextAccessor = httpContextAccessor; this.dbContext = dbContext; }
public DropletsService(ILocalizationService localizationService, ILogger <DropletsService> logger, DigitalOceanDbContext dbContext, IMapper mapper, IDigitalOceanManager digitalOceanManager, IHttpContextAccessor httpContextAccessor) { this.localizationService = localizationService; this.logger = logger; this.dbContext = dbContext; this.mapper = mapper; this.digitalOceanManager = digitalOceanManager; this.httpContextAccessor = httpContextAccessor; }
public OrganizationsService(ILocalizationService localizationService, ILogger <OrganizationsService> logger, DigitalOceanDbContext doDbContext, MyMicrotingDbContext myMicrotingDbContext, CustomersPnDbAnySql customersDbContext, IHttpContextAccessor httpContextAccessor, IMapper mapper) { this.localizationService = localizationService; this.doDbContext = doDbContext; this.customersDbContext = customersDbContext; this.mapper = mapper; this.myMicrotingDbContext = myMicrotingDbContext; this.httpContextAccessor = httpContextAccessor; this.logger = logger; }
protected async Task SetUp() { Mapper = new Mapper(AutomaperConfiguration.MapperConfiguration); DbContext = new DigitalOceanDbContextFactory().CreateDbContext(new string[] { }); await DbContext.PluginConfigurationValues.AddAsync( new PluginConfigurationValue() { Name = "MyMicrotingSettings:DigitalOceanToken" }); await DbContext.SaveChangesAsync(); }
private async Task UpdateInternal <T>(DigitalOceanDbContext dbContext, string state = null) where T : BaseEntity { using (var ctx = new DigitalOceanDbContextFactory().CreateDbContext(new string[] { dbContext.Database.GetDbConnection().ConnectionString })) { var record = await ctx.Set <T>().FirstOrDefaultAsync(x => x.Id == Id); if (record == null) { throw new NullReferenceException($"Could not find {this.GetType().Name} with ID: {Id}"); } Mapper.Map(this, record); if (state != null) { record.WorkflowState = state; } if (ctx.ChangeTracker.HasChanges()) { Id = 0; UpdatedAt = DateTime.UtcNow; UpdatedByUserId = UpdatedByUserId; Version = record.Version + 1; CreatedAt = record.CreatedAt; CreatedByUserId = record.CreatedByUserId; if (state != null) { WorkflowState = state; } await dbContext.AddAsync(this); await dbContext.SaveChangesAsync(); var res = MapVersion(this); if (res != null) { await dbContext.AddAsync(res); await dbContext.SaveChangesAsync(); } } } }
public async Task Create(DigitalOceanDbContext dbContext) { CreatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow; Version = 1; WorkflowState = Constants.WorkflowStates.Created; await dbContext.AddAsync(this); await dbContext.SaveChangesAsync(); var res = MapVersion(this); if (res != null) { await dbContext.AddAsync(res); await dbContext.SaveChangesAsync(); } }
private async Task UpdateInternal(DigitalOceanDbContext dbContext, string state = null) { if (state != null) { WorkflowState = state; } if (dbContext.ChangeTracker.HasChanges()) { Version += 1; UpdatedAt = DateTime.UtcNow; await dbContext.SaveChangesAsync(); var res = MapVersion(this); if (res != null) { await dbContext.AddAsync(res); await dbContext.SaveChangesAsync(); } } }
public DigitalOceanManager(DigitalOceanDbContext dbContext, IApiClient apiClient, IMapper mapper) { _dbContext = dbContext; _apiClient = apiClient; _mapper = mapper; }
public async Task Delete(DigitalOceanDbContext dbContext) { await UpdateInternal(dbContext, Constants.WorkflowStates.Removed); }
public async Task Update(DigitalOceanDbContext dbContext) { await UpdateInternal(dbContext); }
public async Task Delete <T>(DigitalOceanDbContext dbContext) where T : BaseEntity { await UpdateInternal <T>(dbContext, Constants.WorkflowStates.Removed); }
public async Task Update <T>(DigitalOceanDbContext dbContext) where T : BaseEntity { await UpdateInternal <T>(dbContext); }
public DigitalOceanManager(DigitalOceanDbContext dbContext, IApiClient apiClient) { _dbContext = dbContext; _apiClient = apiClient; }