Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public async Task<int> SaveChangesAsync(string userName, string impersonatorId)
  2. {
  3. try
  4. {
  5. AddMetadataToEntity(userName, impersonatorId);
  6. var audit = new Audit();
  7.  
  8. audit.CreatedBy = impersonatorId != null ? impersonatorId : userName;
  9.  
  10. audit.PreSaveChanges(this);
  11. int rowAffected = await base.SaveChangesAsync().ConfigureAwait(false);
  12. audit.PostSaveChanges();
  13.  
  14. if (audit.Configuration.AutoSavePreAction != null)
  15. {
  16. audit.Configuration.AutoSavePreAction(this, audit);
  17. await base.SaveChangesAsync().ConfigureAwait(false);
  18. }
  19.  
  20. return rowAffected;
  21. }
  22. catch (DbUpdateConcurrencyException ex)
  23. {
  24. foreach (EntityEntry entry in ex.Entries)
  25. {
  26. System.Diagnostics.Debug.WriteLine(entry.GetType().Name);
  27. foreach (Microsoft.EntityFrameworkCore.Metadata.IProperty prop in entry.CurrentValues.Properties)
  28. {
  29. System.Diagnostics.Debug.WriteLine("t" + prop.Name);
  30. System.Diagnostics.Debug.WriteLine("t" + entry.CurrentValues[prop]);
  31. }
  32. }
  33. throw ex;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement