private void GetContext(string connectionStr)
        {
            InsightDashboardPnDbContextFactory contextFactory = new InsightDashboardPnDbContextFactory();

            DbContext = contextFactory.CreateDbContext(new[] { connectionStr });

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
        public static async Task <DashboardItem> CreateDashboardItem(InsightDashboardPnDbContext dbContext)
        {
            // Dashboard
            var dashboard = GetNewDashboard();
            await dashboard.Create(dbContext);

            // Dashboard item
            var dashboardItem = GetNewDashboardItem(dashboard.Id);
            await dashboardItem.Create(dbContext);

            return(dashboardItem);
        }
 public InsightDashboardPnSettingsService(ILogger <InsightDashboardPnSettingsService> logger,
                                          IInsightDashboardLocalizationService localizationService,
                                          InsightDashboardPnDbContext dbContext,
                                          IPluginDbOptions <InsightDashboardBaseSettings> options,
                                          IHttpContextAccessor httpContextAccessor)
 {
     _logger              = logger;
     _dbContext           = dbContext;
     _options             = options;
     _httpContextAccessor = httpContextAccessor;
     _localizationService = localizationService;
 }
Ejemplo n.º 4
0
        public async Task Create(InsightDashboardPnDbContext dbContext)
        {
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;
            Version       = 1;
            WorkflowState = eForm.Infrastructure.Constants.Constants.WorkflowStates.Created;

            await dbContext.AddAsync(this).ConfigureAwait(false);

            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            var res = MapVersion(this);

            if (res != null)
            {
                await dbContext.AddAsync(res).ConfigureAwait(false);

                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Ejemplo n.º 5
0
        public static void SeedData(InsightDashboardPnDbContext dbContext)
        {
            var configurationSeedData = new InsightDashboardConfigurationSeedData();

            foreach (var configurationItem in configurationSeedData.Data)
            {
                if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name))
                {
                    var newConfigValue = new PluginConfigurationValue()
                    {
                        Name            = configurationItem.Name,
                        Value           = configurationItem.Value,
                        CreatedAt       = DateTime.UtcNow,
                        Version         = 1,
                        WorkflowState   = Constants.WorkflowStates.Created,
                        CreatedByUserId = 1
                    };
                    dbContext.PluginConfigurationValues.Add(newConfigValue);
                    dbContext.SaveChanges();
                }
            }

            // Seed plugin permissions
            var newPermissions = InsightDashboardPermissionsSeedData.Data
                                 .Where(p => dbContext.PluginPermissions.All(x => x.ClaimName != p.ClaimName))
                                 .Select(p => new PluginPermission
            {
                PermissionName  = p.PermissionName,
                ClaimName       = p.ClaimName,
                CreatedAt       = DateTime.UtcNow,
                Version         = 1,
                WorkflowState   = Constants.WorkflowStates.Created,
                CreatedByUserId = 1
            }
                                         );

            dbContext.PluginPermissions.AddRange(newPermissions);

            dbContext.SaveChanges();
        }
Ejemplo n.º 6
0
        private async Task UpdateInternal(InsightDashboardPnDbContext 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).ConfigureAwait(false);

                    await dbContext.SaveChangesAsync().ConfigureAwait(false);
                }
            }
        }
        public static async Task <DashboardItemCompare> CreateDashboardItemCompare(InsightDashboardPnDbContext dbContext)
        {
            var dashboardItem = await CreateDashboardItem(dbContext);

            Random rnd = new Random();

            DashboardItemCompare dashboardItemCompare = new DashboardItemCompare
            {
                UpdatedByUserId = rnd.Next(1, 255),
                CreatedByUserId = rnd.Next(1, 255),
                CreatedAt       = DateTime.UtcNow,
                UpdatedAt       = DateTime.UtcNow,
                WorkflowState   = Constants.WorkflowStates.Created,
                Position        = 1,
                TagId           = 1,
                LocationId      = 1,
                DashboardItemId = dashboardItem.Id,
            };

            await dashboardItemCompare.Create(dbContext);;

            return(dashboardItemCompare);
        }
Ejemplo n.º 8
0
 public async Task Delete(InsightDashboardPnDbContext dbContext)
 {
     await UpdateInternal(dbContext, eForm.Infrastructure.Constants.Constants.WorkflowStates.Removed);
 }
Ejemplo n.º 9
0
 public async Task Update(InsightDashboardPnDbContext dbContext)
 {
     await UpdateInternal(dbContext);
 }
        public static async Task <DashboardItemIgnoredAnswer> CreateDashboardItemIgnoredAnswer(InsightDashboardPnDbContext dbContext)
        {
            var dashboardItem = await CreateDashboardItem(dbContext);

            Random rnd = new Random();

            DashboardItemIgnoredAnswer dashboardItemIgnoredAnswer = new DashboardItemIgnoredAnswer
            {
                UpdatedByUserId = rnd.Next(1, 255),
                CreatedByUserId = rnd.Next(1, 255),
                CreatedAt       = DateTime.UtcNow,
                UpdatedAt       = DateTime.UtcNow,
                WorkflowState   = Constants.WorkflowStates.Created,
                DashboardItemId = dashboardItem.Id,
                AnswerId        = 1,
            };

            await dashboardItemIgnoredAnswer.Create(dbContext);;

            return(dashboardItemIgnoredAnswer);
        }