minafaw3

queryDatabase

Dec 5th, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. public async Task<List<Database.Models.Caregiver>> GetCaregivers()
  2. {
  3. await SEMAPHORE.WaitAsync();
  4. try
  5. {
  6. List<Database.Models.Caregiver> caregivers = await _dbConnection.QueryAsync<Database.Models.Caregiver>("select * from Caregiver where CircleId = (select Patient.CircleId from Profile inner join Patient ON Profile.ProfileId = Patient.ProfileId)");
  7. return caregivers;
  8. }
  9. catch (Exception)
  10. {
  11. return null;
  12. }
  13. finally
  14. {
  15. SEMAPHORE.Release();
  16. }
  17. }
  18.  
  19. public async Task<List<Database.Models.Patient>> GetPatients()
  20. {
  21. await SEMAPHORE.WaitAsync();
  22. try
  23. {
  24. List<Database.Models.Patient> patients = await _dbConnection.QueryAsync<Database.Models.Patient>("select * from Patient where CircleId != (select Patient.CircleId from Profile inner join Patient ON Profile.ProfileId = Patient.ProfileId)");
  25. return patients;
  26. }
  27. catch (Exception)
  28. {
  29. return null;
  30. }
  31. finally
  32. {
  33. SEMAPHORE.Release();
  34. }
  35. }
  36.  
  37. public async Task AddOrUpdatePatient(Database.Models.Patient patient)
  38. {
  39. await SEMAPHORE.WaitAsync();
  40. try
  41. {
  42. int rowsAffected = await _dbConnection.UpdateAsync(patient);
  43. if (rowsAffected == 0)
  44. {
  45. await _dbConnection.InsertAsync(patient);
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. System.Diagnostics.Debug.WriteLine($"PyxDatabase.AddOrUpdatePatient() Exception: { ex }");
  51. }
  52. finally
  53. {
  54. SEMAPHORE.Release();
  55. }
  56. }
  57.  
  58.  
  59.  
  60.  
  61. public async Task<List<Database.Models.Patient>> GetCaregiversPatients()
  62. {
  63. await SEMAPHORE.WaitAsync();
  64. try
  65. {
  66. List<Database.Models.Patient> patients = await _dbConnection.QueryAsync<Database.Models.Patient>("select * from Patient where CircleId = (select Patient.CircleId from Profile inner join Patient ON Profile.ProfileId != Patient.ProfileId)");
  67. return patients;
  68. }
  69. catch (Exception)
  70. {
  71. return null;
  72. }
  73. finally
  74. {
  75. SEMAPHORE.Release();
  76. }
  77. }
  78.  
  79.  
  80. public async Task<int> GetCurrentUserProfileCircleId()
  81. {
  82. await SEMAPHORE.WaitAsync();
  83. try
  84. {
  85. int circleId = await _dbConnection.ExecuteAsync("select Patient.CircleId from Profile inner join Patient ON Profile.ProfileId = Patient.ProfileId");
  86. return circleId;
  87. }
  88. catch (Exception)
  89. {
  90. return -1;
  91. }
  92. finally
  93. {
  94. SEMAPHORE.Release();
  95. }
  96. }
Add Comment
Please, Sign In to add comment