public async Task Update(eFormDashboardPnDbContext dbContext) { var dashboardItemCompare = await dbContext.DashboardItemCompares .FirstOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false); if (dashboardItemCompare == null) { throw new NullReferenceException($"Could not find dashboardItemCompare with id: {Id}"); } dashboardItemCompare.DashboardItemId = DashboardItemId; dashboardItemCompare.LocationId = LocationId; dashboardItemCompare.Position = Position; dashboardItemCompare.TagId = TagId; if (dbContext.ChangeTracker.HasChanges()) { dashboardItemCompare.UpdatedAt = DateTime.UtcNow; dashboardItemCompare.Version += 1; await dbContext.DashboardItemCompareVersions.AddAsync(MapVersion(dashboardItemCompare)).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }
public async Task Update(eFormDashboardPnDbContext dbContext) { DashboardItem dashboardItem = await dbContext.DashboardItems.FirstOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false); if (dashboardItem == null) { throw new NullReferenceException($"Could not find item with id: {Id}"); } dashboardItem.WorkflowState = WorkflowState; dashboardItem.UpdatedAt = UpdatedAt; dashboardItem.UpdatedByUserId = UpdatedByUserId; dashboardItem.Position = Position; dashboardItem.ChartType = ChartType; dashboardItem.Period = Period; dashboardItem.FieldId = FieldId; dashboardItem.FilterFieldId = FilterFieldId; dashboardItem.FilterFieldOptionId = FilterFieldOptionId; dashboardItem.CalculateAverage = CalculateAverage; dashboardItem.CompareEnabled = CompareEnabled; if (dbContext.ChangeTracker.HasChanges()) { dashboardItem.UpdatedAt = DateTime.UtcNow; dashboardItem.Version += 1; await dbContext.DashboardItemVersions.AddAsync(MapVersion(dashboardItem)).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }
public async Task Update(eFormDashboardPnDbContext dbContext) { Dashboard dashboard = await dbContext.Dashboards.FirstOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false); if (dashboard == null) { throw new NullReferenceException($"Could not find item with id: {Id}"); } dashboard.WorkflowState = WorkflowState; dashboard.UpdatedAt = UpdatedAt; dashboard.UpdatedByUserId = UpdatedByUserId; dashboard.Name = Name; dashboard.eFormId = eFormId; dashboard.LocationId = LocationId; dashboard.TagId = TagId; dashboard.DateFrom = DateFrom; dashboard.DateTo = DateTo; dashboard.Today = Today; if (dbContext.ChangeTracker.HasChanges()) { dashboard.UpdatedAt = DateTime.UtcNow; dashboard.Version += 1; await dbContext.DashboardVersions.AddAsync(MapVersion(dashboard)).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }
private void GetContext(string connectionStr) { eFormDashboardPnDbContextFactory contextFactory = new eFormDashboardPnDbContextFactory(); DbContext = contextFactory.CreateDbContext(new[] { connectionStr }); DbContext.Database.Migrate(); DbContext.Database.EnsureCreated(); }
public async Task Create(eFormDashboardPnDbContext dbContext) { WorkflowState = Constants.WorkflowStates.Created; Version = 1; CreatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow; await dbContext.DashboardItemIgnoredFieldValues.AddAsync(this); await dbContext.SaveChangesAsync().ConfigureAwait(false); await dbContext.DashboardItemIgnoredFieldValueVersions.AddAsync(MapVersion(this)); await dbContext.SaveChangesAsync().ConfigureAwait(false); }
public async Task Create(eFormDashboardPnDbContext dbContext) { CreatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow; Version = 1; WorkflowState = Constants.WorkflowStates.Created; await dbContext.Dashboards.AddAsync(this).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); await dbContext.DashboardVersions.AddAsync(MapVersion(this)).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); }
public async Task Delete(eFormDashboardPnDbContext dbContext) { DashboardItem dashboardItem = await dbContext.DashboardItems.FirstOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false); if (dashboardItem == null) { throw new NullReferenceException($"Could not find item with id: {Id}"); } dashboardItem.WorkflowState = Constants.WorkflowStates.Removed; if (dbContext.ChangeTracker.HasChanges()) { dashboardItem.UpdatedAt = DateTime.UtcNow; dashboardItem.Version += 1; await dbContext.DashboardItemVersions.AddAsync(MapVersion(dashboardItem)).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }
public async Task Update(eFormDashboardPnDbContext dbContext) { var dashboardItemIgnoredFieldValue = await dbContext.DashboardItemIgnoredFieldValues .FirstOrDefaultAsync(x => x.Id == Id); if (dashboardItemIgnoredFieldValue == null) { throw new NullReferenceException($"Could not find ignoredAnswer with id: {Id}"); } dashboardItemIgnoredFieldValue.FieldOptionId = FieldOptionId; dashboardItemIgnoredFieldValue.FieldValue = FieldValue; dashboardItemIgnoredFieldValue.DashboardItemId = DashboardItemId; if (dbContext.ChangeTracker.HasChanges()) { dashboardItemIgnoredFieldValue.UpdatedAt = DateTime.UtcNow; dashboardItemIgnoredFieldValue.Version += 1; await dbContext.DashboardItemIgnoredFieldValueVersions.AddAsync(MapVersion(dashboardItemIgnoredFieldValue)).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); } }