Guest User

Untitled

a guest
May 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {IsolationLevel = IsolationLevel.RepeatableRead}))
  2. {
  3. PersonDayStatisticsUnit pdsu = db.PersonDayStatisticsUnits.FirstOrDefault(x => x.UnitId == su.Id && x.Date == now && x.PersonAnonimousGuid == personGuid);
  4. if (pdsu == null)
  5. {
  6. pdsu = new PersonDayStatisticsUnit()
  7. {
  8. UnitId = su.Id,
  9. Count = 1,
  10. Date = now,
  11. PersonAnonimousGuid = personGuid
  12. };
  13. db.PersonDayStatisticsUnits.Add(pdsu);
  14. ret = true;
  15. }
  16. else
  17. {
  18. pdsu.Count++;
  19. ret = false;
  20. }
  21.  
  22. db.SaveChanges();
  23.  
  24. scope.Complete();
  25. }
Add Comment
Please, Sign In to add comment