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);
        }
Пример #2
0
        public async Task Update(MyMicrotingDbContext dbContext)
        {
            Organization organization = dbContext.Organizations.FirstOrDefault(x => x.Id == Id);

            if (organization == null)
            {
                throw new NullReferenceException($"Could not find Organization with {Id}");
            }

            organization.CustomerId           = CustomerId;
            organization.DomainName           = DomainName;
            organization.ServiceEmail         = ServiceEmail;
            organization.NumberOfLicenses     = NumberOfLicenses;
            organization.NumberOfLicensesUsed = NumberOfLicensesUsed;
            organization.UpToDateStatus       = UpToDateStatus;
            organization.NextUpgrade          = NextUpgrade;
            organization.InstanceStatus       = InstanceStatus;
            organization.InstanceId           = InstanceId;

            if (dbContext.ChangeTracker.HasChanges())
            {
                organization.UpdatedAt = DateTime.Now;
                organization.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.OrganizationVersions.Add(MapVersions(organization));
                await dbContext.SaveChangesAsync();
            }
        }
Пример #3
0
 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;
 }
Пример #4
0
        public async Task Create(MyMicrotingDbContext dbContext)
        {
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;
            Version       = 1;
            WorkflowState = Constants.WorkflowStates.Created;

            dbContext.Organizations.Add(this);
            await dbContext.SaveChangesAsync();

            dbContext.OrganizationVersions.Add(MapVersions(this));
            await dbContext.SaveChangesAsync();
        }
Пример #5
0
        public async Task Create(MyMicrotingDbContext 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();
            }
        }
Пример #6
0
        public async Task Delete(MyMicrotingDbContext dbContext)
        {
            Organization organization = dbContext.Organizations.FirstOrDefault(x => x.Id == Id);

            if (organization == null)
            {
                throw new NullReferenceException($"Could not find Organization with {Id}");
            }

            organization.WorkflowState = Constants.WorkflowStates.Removed;

            if (dbContext.ChangeTracker.HasChanges())
            {
                organization.UpdatedAt = DateTime.Now;
                organization.Version  += 1;
                await dbContext.SaveChangesAsync();

                dbContext.OrganizationVersions.Add(MapVersions(organization));
                await dbContext.SaveChangesAsync();
            }
        }
Пример #7
0
        private async Task UpdateInternal(MyMicrotingDbContext 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();
                }
            }
        }
Пример #8
0
 public async Task Delete(MyMicrotingDbContext dbContext)
 {
     await UpdateInternal(dbContext, Constants.WorkflowStates.Removed);
 }
Пример #9
0
 public async Task Update(MyMicrotingDbContext dbContext)
 {
     await UpdateInternal(dbContext);
 }