Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. public static class DBHelper
  2. {
  3. public static MobileServiceClient MobileService =
  4. new MobileServiceClient("https://proevents.azurewebsites.net");
  5.  
  6. public static async void InsertNewUser(users u)
  7. {
  8. CurrentPlatform.Init();
  9. await MobileService.GetTable<users>().InsertAsync(u);
  10.  
  11. }
  12. public static async void InsertNewUser(string userName, string password)
  13. {
  14. CurrentPlatform.Init();
  15. string hashedPassword = PasswordStorage.CreateHash(password);
  16. //CurrentPlatform.Init();
  17. users u = new users { username = userName, password = hashedPassword };
  18. await MobileService.GetTable<users>().InsertAsync(u);
  19. }
  20. public static async Task<users> GetUser(string userName)
  21. {
  22. CurrentPlatform.Init();
  23. List<users> ls = await MobileService.GetTable<users>().ToListAsync();
  24. users u = ls.FirstOrDefault(x => x.username == userName);
  25. return u;
  26. }
  27. public static async Task<List<users>> GetAllUsers()
  28. {
  29. CurrentPlatform.Init();
  30. List<users> ls = await MobileService.GetTable<users>().ToListAsync();
  31. return ls;
  32. }
  33. public static async Task<bool> DoesUserExist(string userName)
  34. {
  35. CurrentPlatform.Init();
  36. //List<users> ls = await MobileService.GetTable<users>().ToListAsync();
  37. //users u = ls.FirstOrDefault(x => x.username == userName);
  38. var u = await MobileService.GetTable<users>().Where(x => x.username == userName).ToListAsync();
  39. if (u != null)
  40. {
  41. return true;
  42. }
  43. else
  44. {
  45. return false;
  46. }
  47. }
  48. public static void InsertUserProf(UserProf up)
  49. {
  50. CurrentPlatform.Init();
  51. MobileService.GetTable<UserProf>().InsertAsync(up);
  52. }
  53. public static void InsertUserProf(string username, string firstName, string lastName, string profession, string county, string description)
  54. {
  55. CurrentPlatform.Init();
  56. UserProf up = new UserProf
  57. {
  58. Username = username,
  59. Firstname = firstName,
  60. Lastname = lastName,
  61. Profession = profession,
  62. County = county,
  63. Description = description
  64. };
  65. MobileService.GetTable<UserProf>().InsertAsync(up);
  66. }
  67. public static async Task<UserProf> GetUserProfile(string zUsername)
  68. {
  69. CurrentPlatform.Init();
  70. List<UserProf> ls = await MobileService.GetTable<UserProf>().ToListAsync();
  71. UserProf u = ls.FirstOrDefault(x => x.userID == zUsername);
  72. return u;
  73. }
  74. public static async Task<bool> IsUserProfileCreated(string zUsername)
  75. {
  76. CurrentPlatform.Init();
  77. List<UserProf> ls = await MobileService.GetTable<UserProf>().ToListAsync();
  78. UserProf u = ls.FirstOrDefault(x => x.userID == zUsername);
  79. if (u != null)
  80. {
  81. return true;
  82. }
  83. else
  84. {
  85. return false;
  86. }
  87. }
  88. public static async Task<UserProf> ProfileSetUp(string username)
  89. {
  90. CurrentPlatform.Init();
  91. List<UserProf> ls = await MobileService.GetTable<UserProf>().ToListAsync();
  92. UserProf prof = ls.FirstOrDefault(x => x.Username == username);
  93. return prof;
  94. //return Client.GetTable<UserProf>(x => x.Username == username);
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement