public void Create(IPluginDbContext dbContext) { CreatedAt = DateTime.UtcNow; UpdatedAt = DateTime.UtcNow; Version = 1; WorkflowState = Constants.WorkflowStates.Created; dbContext.PluginGroupPermissions.Add(this); dbContext.SaveChanges(); dbContext.PluginGroupPermissionVersions.Add(MapVersions(this)); dbContext.SaveChanges(); }
public void Update(IPluginDbContext dbContext) { PluginGroupPermission pluginGroupPermission = dbContext.PluginGroupPermissions.FirstOrDefault(x => x.Id == Id); if (pluginGroupPermission == null) { throw new NullReferenceException($"Could not find pluginGroupPermission with id {Id}"); } pluginGroupPermission.WorkflowState = WorkflowState; pluginGroupPermission.GroupId = pluginGroupPermission.GroupId; pluginGroupPermission.PermissionId = pluginGroupPermission.PermissionId; pluginGroupPermission.IsEnabled = pluginGroupPermission.IsEnabled; pluginGroupPermission.CreatedByUserId = CreatedByUserId; pluginGroupPermission.UpdatedByUserId = UpdatedByUserId; if ((dbContext as DbContext).ChangeTracker.HasChanges()) { pluginGroupPermission.UpdatedAt = DateTime.UtcNow; pluginGroupPermission.Version += 1; dbContext.PluginGroupPermissionVersions.Add(MapVersions(this)); dbContext.SaveChanges(); } }
public static void SeedData(IPluginDbContext dbContext, IPluginConfigurationSeedData data) { foreach (var configurationItem in data.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 = CustomersPermissionsSeedData.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(); }
public void Delete(IPluginDbContext dbContext) { PluginGroupPermission pluginGroupPermission = dbContext.PluginGroupPermissions.FirstOrDefault(x => x.Id == Id); if (pluginGroupPermission == null) { throw new NullReferenceException($"Could not find pluginGroupPermission with id {Id}"); } pluginGroupPermission.WorkflowState = Constants.WorkflowStates.Removed; if ((dbContext as DbContext).ChangeTracker.HasChanges()) { pluginGroupPermission.UpdatedAt = DateTime.UtcNow; pluginGroupPermission.Version += 1; dbContext.PluginGroupPermissionVersions.Add(MapVersions(this)); dbContext.SaveChanges(); } }
public static void SeedPermissions(IPluginDbContext dbContext, IPluginPermissionsSeedData data) { // Seed plugin permissions var newPermissions = data.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(); }