Exemplo n.º 1
0
        public async Task Create(NginxManagemenDbContext dbContext)
        {
            CreatedAt     = DateTime.Now;
            UpdatedAt     = DateTime.Now;
            Version       = 1;
            WorkflowState = Constants.WorkflowStates.Created;

            await dbContext.AddAsync(this);

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 2
0
        private async Task UpdateInternal <T>(NginxManagemenDbContext dbContext, string state = null) where T : BaseEntity
        {
            var record = await dbContext.Set <T>().FirstOrDefaultAsync(x => x.Id == Id);

            if (record == null)
            {
                throw new NullReferenceException($"Could not find {this.GetType().Name} with ID: {Id}");
            }

            var initialState = record.WorkflowState;

            if (state != null)
            {
                record.WorkflowState = state;
            }

            if (dbContext.ChangeTracker.HasChanges())
            {
                record.WorkflowState = initialState;

                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();
            }
        }
Exemplo n.º 3
0
 public async Task Delete <T>(NginxManagemenDbContext dbContext) where T : BaseEntity
 {
     await UpdateInternal <T>(dbContext, Constants.WorkflowStates.Removed);
 }
Exemplo n.º 4
0
 public async Task Update <T>(NginxManagemenDbContext dbContext) where T : BaseEntity
 {
     await UpdateInternal <T>(dbContext);
 }
Exemplo n.º 5
0
 public HostsManager(ILogger <HostsManager> logger, NginxManagemenDbContext dbContext, ITemplateStorage templateStorage)
 {
     this.logger          = logger;
     this.dbContext       = dbContext;
     this.templateStorage = templateStorage;
 }
 public AuthorizationFilter(NginxManagemenDbContext dbContext)
 {
     this.dbContext = dbContext;
 }