public void RegisterAuditTypeTwiceExceptionTest() { AuditDbContext context = new AuditDbContext("test"); AuditDbContext.RegisterAuditType(typeof(TestEntity), typeof(TestEntityAudit)); AuditDbContext.RegisterAuditType(typeof(TestEntity), typeof(TestEntityAudit)); }
public FullLifeModel GetFullLife(int id, FullLifeIndex pageIndex) { var res = new FullLifeModel { Details = Gettongs_entity(id) }; var ToolManagedbContext = new ToolManageDbContext(); var AuditdbContext = new AuditDbContext(); IQueryable <InTable> InTables = ToolManagedbContext.InTables; IQueryable <OutTable> OutTables = ToolManagedbContext.OutTables; IQueryable <Warehouse> WarehouseTables = AuditdbContext.Warehouses; IQueryable <Scrap> ScrapTables = AuditdbContext.Scraps; IQueryable <RepairTable> RepairTables = ToolManagedbContext.RepairTables; InTables = InTables.Where(u => u.Code.Contains(res.Details.Code)); InTables = InTables.Where(u => u.SeqID == res.Details.SeqID); OutTables = OutTables.Where(u => u.Code.Contains(res.Details.Code)); OutTables = OutTables.Where(u => u.SeqID == res.Details.SeqID); WarehouseTables = WarehouseTables.Where(u => u.Code.Contains(res.Details.Code)); WarehouseTables = WarehouseTables.Where(u => u.SeqID == res.Details.SeqID); ScrapTables = ScrapTables.Where(u => u.Code.Contains(res.Details.Code)); ScrapTables = ScrapTables.Where(u => u.SeqID == res.Details.SeqID); RepairTables = RepairTables.Where(u => u.Code.Contains(res.Details.Code)); RepairTables = RepairTables.Where(u => u.SeqID == res.Details.SeqID); res.InDetails = InTables.OrderByDescending(u => u.ID).ToPagedList(pageIndex.pageIndex1, 12); res.OutDetails = OutTables.OrderByDescending(u => u.ID).ToPagedList(pageIndex.pageIndex2, 12); res.WarehouseDetails = WarehouseTables.OrderByDescending(u => u.ID).ToPagedList(pageIndex.pageIndex3, 12); res.ScrapDetails = ScrapTables.OrderByDescending(u => u.ID).ToPagedList(pageIndex.pageIndex4, 12); res.RepairDetails = RepairTables.OrderByDescending(u => u.ID).ToPagedList(pageIndex.pageIndex5, 12); return(res); }
public void UpdateByAuditTestMethod() { var repository = LocalIoCContainer.Resolve <ISimpleDataEntityRepository>(); Assert.IsTrue(AuditDbContext.AuditEnabled); AuditDbContext.RegisterAuditType(typeof(SimpleDataEntity), typeof(SimpleDataEntityAudit)); var itemToUpdate = repository.Find(2); itemToUpdate.Name = "Updated Name 3"; repository.Update(itemToUpdate, x => x.Id == 2); repository.Save("UserName2"); var actual = repository.Find(2); var auditactual = repository.GetExistingContext().SimpleDataEntityAudits.Where(x => x.AuditSourceId == 2).FirstOrDefault(); Assert.AreEqual("Updated Name 3", actual.Name); Assert.AreEqual("Test 2", auditactual?.Name); Assert.AreEqual("UserName2", auditactual?.AuditUser); repository.Dispose(); }
private static void Main(string[] args) { AuditDbContext.RegisterAuditableEntity(typeof(Customer)); using (var dbContext = new TestDbContext("AuditDbContext")) { var customer = new Customer() { Name = "TestCustomer" }; dbContext.Customers.Add(customer); dbContext.SaveChanges(); var customerInDb = dbContext.Customers.FirstOrDefault(ct => ct.Name == customer.Name); customerInDb.Name = "TestCustomerUpdate"; dbContext.Customers.Attach(customerInDb); dbContext.Entry(customerInDb).State = EntityState.Modified; dbContext.SaveChanges(); } Console.ReadKey(); }
public GenericsDatabaseChangesAuditService( IAuthentificationContext authentificationContext, IAuditSerializer auditSerializer, AuditConfiguration auditConfiguration, AuditDbContext auditDbContext, YourDbContext dbContext) : base(authentificationContext, auditSerializer, auditConfiguration, auditDbContext, dbContext) { }
public void Add(AuditEntry entry) { using (var context = new AuditDbContext()) { var entity = AuditEntityMap.ToDataEntity(entry); context.AuditEntities.Add(entity); context.SaveChanges(); } }
public DatabaseChangesAuditService( IAuthentificationContext authentificationContext, IAuditSerializer auditSerializer, AuditConfiguration auditConfiguration, AuditDbContext auditDbContext, TDbContext dbContextToAudit) { _authentificationContext = authentificationContext; _dbContextToAudit = dbContextToAudit; _auditSerializer = auditSerializer; _auditConfiguration = auditConfiguration; _auditDbContext = auditDbContext; }
public override void ReplaceEvent(object eventId, AuditEvent auditEvent) { var json = auditEvent.ToJson(); using (var ctx = new AuditDbContext(_connectionString)) { var ludScript = _lastUpdatedDateColumnName != null?string.Format(", [{0}] = GETUTCDATE()", _lastUpdatedDateColumnName) : string.Empty; var cmdText = string.Format("UPDATE {0} SET [{1}] = @json{2} WHERE [{3}] = @eventId", FullTableName, _jsonColumnName, ludScript, _idColumnName); ctx.Database.ExecuteSqlCommand(cmdText, new SqlParameter("@json", json), new SqlParameter("@eventId", eventId)); } }
static void Main(string[] args) { #region Insert var person = new Person { FirstName = "some", LastName = "Name", Age = 13, Gender = "M", Deleted = false }; using (var db = new AuditDbContext()) { db.Persons.Add(person); db.SaveChanges(); AuditTrail.CreateTrail(person.Id, typeof(Person).Name, new Person(), person, AuditAction.Create); } #endregion #region Update //using (var db = new AuditDbContext()) //{ // var person = db.Persons.Find(1); // if (person != null) // { // var updateperson=new Person // { // Id = person.Id, // Gender = "M", // Age =11, // FirstName = person.FirstName, // LastName = person.LastName // }; // db.Persons.Attach(person); // AuditTrail.CreateTrail(person.Id, typeof(Person).Name,person, updateperson, AuditAction.Update); // } //} #endregion }
public override object InsertEvent(AuditEvent auditEvent) { var json = new SqlParameter("json", auditEvent.ToJson()); using (var ctx = new AuditDbContext(_connectionString)) { var cmdText = string.Format("INSERT INTO {0} ([{1}]) OUTPUT CONVERT(NVARCHAR(MAX), INSERTED.[{2}]) AS [Id] VALUES (@json)", FullTableName, _jsonColumnName, _idColumnName); #if NET45 var result = ctx.Database.SqlQuery <string>(cmdText, json); return(result.FirstOrDefault()); #elif NETCOREAPP1_0 var result = ctx.FakeIdSet.FromSql(cmdText, json); return(result.FirstOrDefault().Id); #endif } }
public void Configure(IWebJobsBuilder builder) { builder.Services.AddScoped <IAuditRepository, AuditRepository>(); builder.Services.AddDbContext <AuditDbContext>((serviceProvider, options) => { var config = serviceProvider.GetService <IConfiguration>(); var connectionString = config["AuditDbConnection"]; options.UseNpgsql(connectionString, x => x.MigrationsAssembly("Insolvency.Data")); }); var connectionString = Environment.GetEnvironmentVariable("AuditDbConnection"); var optionsBuilder = new DbContextOptionsBuilder <AuditDbContext>(); optionsBuilder.UseNpgsql(connectionString, x => x.MigrationsAssembly("Insolvency.Data")); var context = new AuditDbContext(optionsBuilder.Options); AuditDbInitialise.Init(context); }
public EFDbContext(AuditDbContext context) { _context = context; }
public AuditorProfileRepository(AuditDbContext context) : base(context) { }
public AuditTrailRepository(AuditDbContext context) : base(context) { this.Context = context; }
public SeverityRepo(AuditDbContext auditDbContext) { _auditDbContext = auditDbContext; }
public ErrorLogRepository(AuditDbContext context) : base(context) { Context = context; }
public ActionRepository(AuditDbContext context) : base(context) { context = context; }
public static async Task Seed(AuditDbContext dbContext) { await dbContext.SaveChangesAsync(); }
public Context(AuditDbContext db) { DbContext = db; DbSet = DbContext.Set <TEntity>(); }
public NotificationRepository(AuditDbContext context) : base(context) { Context = context; }
public AuditEventHandler(IAuthentificationContext authentificationContext, AuditDbContext auditDbContext, IAuditSerializer auditSerializer) { _authentificationContext = authentificationContext; _dbContext = auditDbContext; _auditSerializer = auditSerializer; }
/// <summary> /// Force EF to generate the Model Metadata. /// </summary> public static void GenerateViews(string viewCachePath, ILog log = null) { // Use the provided ILog instance or create our own. log = log ?? LogProvider.Get(typeof(ContextPreloader)); log.Debug("View Cache Directory set to: {0}", viewCachePath); var admin = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new AdministrationDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\AdministrationDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Agency>().ToString(); timer.Stop(); log.Debug("AdministrationDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var reports = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new ReportsDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\ReportsDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Report>().ToString(); timer.Stop(); log.Debug("ReportsDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var summaries = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new SummariesDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\SummariesDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Summary>().ToString(); timer.Stop(); log.Debug("SummariesDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var recentInfo = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new RecentInfoDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\RecentInfoDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <RecentEvent>().ToString(); timer.Stop(); log.Debug("RecentInfoDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var messaging = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new MessagingDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\MessagingDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <MessageLog>().ToString(); timer.Stop(); log.Debug("MessagingDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var audit = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new AuditDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\AuditDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.AuditEntities.ToString(); timer.Stop(); log.Debug("AuditDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); Task.WaitAll(admin, reports, summaries, recentInfo, messaging, audit); }