Esempio n. 1
0
        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();
                    }
                }
            }
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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();
                }
            }
        }