public PluginPermissionsManager GetPermissionsManager(string connectionString) { var contextFactory = new DigitalOceanDbContextFactory(); var context = contextFactory.CreateDbContext(new[] { connectionString }); return(new PluginPermissionsManager(context)); }
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 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()); } }