protected virtual void AuditDelete(DataStoreContext context, DbEntityEntry targetEntity, DataOperation operation) { var transactionId = Guid.NewGuid(); foreach (var prop in targetEntity.OriginalValues.PropertyNames) { var property = targetEntity.Property(prop); var auditTrail = InitEntity(targetEntity, operation, property, prop, transactionId); context.Entry(auditTrail).State = EntityState.Added; } }
public async Task <Order> UpdateOrderAsync(Order order) { if (_context.Orders.Local.All(o => o.Id != order.Id)) { _context.Orders.Attach(order); } _context.Entry(order).State = EntityState.Modified; await _context.SaveChangesAsync(); return(order); }
public async Task <Customer> UpdateCustomerAsync(Customer customer) { if (_context.Customers.Local.All(c => c.Id != customer.Id)) { _context.Customers.Attach(customer); } _context.Entry(customer).State = EntityState.Modified; await _context.SaveChangesAsync(); return(customer); }
protected virtual void AuditUpdate(DataStoreContext context, DbEntityEntry targetEntity) { var transactionId = Guid.NewGuid(); foreach (var propertyName in targetEntity.OriginalValues.PropertyNames) { var property = targetEntity.Property(propertyName); var oldData = property.OriginalValue != null?property.OriginalValue.ToString() : "null"; var newData = property.CurrentValue != null?property.CurrentValue.ToString() : "null"; if (property.IsModified && !oldData.Equals(newData)) { var auditTrail = InitEntity(targetEntity, DataOperation.Update, property, propertyName, transactionId); context.Entry(auditTrail).State = EntityState.Added; } } }