Guest User

Untitled

a guest
Jan 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public virtual T Update(T item, int id)
  2. {
  3. if (item == null)
  4. throw new ArgumentNullException(string.Format("El {0} no puede ser nulo!", typeof(T).Name.ToString()));
  5.  
  6. SessionManager.BeginTransaction();
  7. try
  8. {
  9. SessionManager.CurrentSession.Update(item);
  10. SessionManager.CommitTransaction();
  11. return item;
  12. }
  13. catch (Exception ex)
  14. {
  15. SessionManager.RollbackTransaction();
  16. throw ex;
  17. }
  18. }
  19.  
  20. public static void BeginTransaction()
  21. {
  22. CurrentSession.BeginTransaction();
  23. }
  24.  
  25. public static void CommitTransaction()
  26. {
  27. if (CurrentSession.Transaction != null && CurrentSession.Transaction.IsActive)
  28. CurrentSession.Transaction.Commit();
  29. CurrentSessionContext.Unbind(Factory);
  30. CurrentSession.Close();
  31. }
  32.  
  33. public static void RollbackTransaction()
  34. {
  35. if (CurrentSession.Transaction != null && CurrentSession.Transaction.IsActive)
  36. CurrentSession.Transaction.Rollback();
  37. CurrentSessionContext.Unbind(Factory);
  38. CurrentSession.Close();
  39. }
Add Comment
Please, Sign In to add comment