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 PluginPermissionsManager GetPermissionsManager(string connectionString) { var contextFactory = new DigitalOceanDbContextFactory(); var context = contextFactory.CreateDbContext(new[] { connectionString }); return(new PluginPermissionsManager(context)); }
public void AddPluginConfig(IConfigurationBuilder builder, string connectionString) { var seedData = new MyMicrotingDropletsConfigurationSeedData(); var contextFactory = new DigitalOceanDbContextFactory(); builder.AddPluginConfiguration( connectionString, seedData, contextFactory); }
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 void SeedDatabase(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"); DigitalOceanDbContextFactory contextFactory = new DigitalOceanDbContextFactory(); using (var context = contextFactory.CreateDbContext(new[] { connectionString })) MyMicrotingPluginSeed.SeedData(context, new MyMicrotingDropletsConfigurationSeedData()); MyMicrotingDbContextFactory myMicrotingDbContextFactory = new MyMicrotingDbContextFactory(); using (var context = myMicrotingDbContextFactory.CreateDbContext(new[] { orgConnectionString })) MyMicrotingPluginSeed.SeedData(context, new MyMicrotingOrganizationsConfigurationSeedData()); CustomersPnContextFactory customersPnContextFactory = new CustomersPnContextFactory(); using (CustomersPnDbAnySql context = customersPnContextFactory.CreateDbContext(new[] { customersConnectionString })) { // Add data List <string> customerFields = new Customer().GetPropList(); //Find all attributes for cusomers and puts them in a list customerFields.Remove(nameof(Customer .RelatedEntityId)); // removes the related entity, because it's not relevant for fields foreach (string name in customerFields) { if (!context.Fields.Any(x => x.Name == name)) { Field newField = new Field { Name = name }; newField.Create(context); } } context.SaveChanges(); Field fieldForRemove = context.Fields.FirstOrDefault(x => x.Name == nameof(Customer.RelatedEntityId)); if (fieldForRemove != null) { context.Fields.Remove(fieldForRemove); context.SaveChanges(); } List <Field> fields = context.Fields.ToList(); foreach (Field field in fields) { CustomerField customerField = new CustomerField { FieldId = field.Id, FieldStatus = 1 }; if (!context.CustomerFields.Any(x => x.FieldId == field.Id)) { context.CustomerFields.Add(customerField); } } context.SaveChanges(); // Seed configuration MyMicrotingPluginSeed.SeedData(context, new MyMicrotingCustomersConfigurationSeedData()); MyMicrotingPluginSeed.SeedPermissions(context, new MyMicrotingCustomersPermissionsSeedData()); } }