public static void SeedDatabase(AuditLogDbContext context) { var customers = new List <Customer> { new Customer { FirstName = "Test1", LastName = "Test1", Salary = 10000 }, new Customer { FirstName = "Test2", LastName = "Test2", Salary = 20000 } }; context.Database.Migrate(); //return customers; if (!context.Customers.Any()) { context.Customers.AddRange(customers); context.SaveChanges(); } }
public void CreateLog(int entityId, string entityType, int operationTypeId, Object oldRecord, Object newRecord) { AuditLog auditLog = new AuditLog(); auditLog.EntityId = entityId; auditLog.EntityType = entityType; auditLog.OperationTypeId = operationTypeId; auditLog.LoggedInUserName = "******"; auditLog.Timestamp = DateTime.Now; var changes = CompareObjects(oldRecord, newRecord); auditLog.Changes = changes; auditLog.ChangeLogs = JsonConvert.SerializeObject(changes); _auditLogDbContext.AuditLogs.Add(auditLog); _auditLogDbContext.SaveChanges(); }
public void CreateCustomer(Customer customer) { _auditLogDbContext.Add(customer); _auditLogDbContext.SaveChanges(); _auditLogRepository.CreateLog(customer.Id, "Customer", Convert.ToInt16(OperationTypeEnum.Create), new Customer(), customer); }