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(); }
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(); } }