Пример #1
0
        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;
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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;
                }
            }
        }