Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. public static MobileServiceClient MobileService = new
  2. MobileServiceClient("http://tale-server1.database.windows.net");
  3.  
  4. catch (Exception em)
  5. {
  6. var dialog = new MessageDialog("An Error Occured: " +
  7. em.Message);
  8. await dialog.ShowAsync();
  9. }
  10.  
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Runtime.InteropServices.WindowsRuntime;
  16. using Windows.Foundation;
  17. using Windows.Foundation.Collections;
  18. using Windows.UI.Xaml;
  19. using Windows.UI.Xaml.Controls;
  20. using Windows.UI.Xaml.Controls.Primitives;
  21. using Windows.UI.Xaml.Data;
  22. using Windows.UI.Xaml.Input;
  23. using Windows.UI.Xaml.Media;
  24. using Windows.UI.Xaml.Navigation;
  25. using Microsoft.WindowsAzure.MobileServices;
  26. using System.Threading.Tasks;
  27. using Windows.UI.Popups;
  28. using Windows.Storage;
  29. using System.Net.Http;
  30. using Newtonsoft.Json;
  31. using SQLite;
  32. using SQLite.Net;
  33. using SQLite.Net.Async;
  34. using Microsoft.WindowsAzure.MobileServices.Sync;
  35. using Microsoft.WindowsAzure.MobileServices.SQLiteStore;
  36. using SQLitePCL;
  37.  
  38.  
  39. // The Blank Page item template is documented at
  40. http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
  41.  
  42. namespace TALE_Capstone
  43. {
  44. /// <summary>
  45. /// An empty page that can be used on its own or navigated to within a
  46. Frame.
  47. /// </summary>
  48. public sealed partial class MainPage : Page
  49. {
  50. public MainPage()
  51. {
  52. this.InitializeComponent();
  53. }
  54.  
  55. public int IsAuth { get; set; }
  56.  
  57. //[DataTable("User_Cred")]
  58. public class User_Cred
  59. {
  60. public string id { get; set; }
  61. public string userName { get; set; }
  62. public string Password { get; set; }
  63.  
  64. }
  65.  
  66. private IMobileServiceSyncTable<User_Cred> todoGetTable =
  67. App.MobileService.GetSyncTable<User_Cred>();
  68.  
  69.  
  70.  
  71. private async Task InitLocalStoreAsync()
  72. {
  73. if (!App.MobileService.SyncContext.IsInitialized)
  74. {
  75. var store = new MobileServiceSQLiteStore("Tale-DB");
  76. store.DefineTable<User_Cred>();
  77. await App.MobileService.SyncContext.InitializeAsync(store);
  78. }
  79. await SyncAsync();
  80. }
  81.  
  82. private async Task SyncAsync()
  83. {
  84. await App.MobileService.SyncContext.PushAsync();
  85. await todoGetTable.PullAsync("User_Cred",
  86. todoGetTable.CreateQuery());
  87. }
  88.  
  89.  
  90.  
  91. async public void submitAuthBtn_Click(object sender, RoutedEventArgs e)
  92. {
  93. await InitLocalStoreAsync();
  94.  
  95. GetAuthentication();
  96.  
  97. }
  98.  
  99. async public void GetAuthentication()
  100. {
  101. try
  102. {
  103.  
  104. //IMobileServiceTable<User_Cred> todoTable = App.MobileService.GetTable<User_Cred>();
  105.  
  106. List<User_Cred> items = await todoGetTable
  107. .Where(User_Cred => User_Cred.userName == UserNameEnter.Text)
  108. .ToListAsync();
  109.  
  110. IsAuth = items.Count();
  111.  
  112. // Return a List UI control value back to the form
  113.  
  114. foreach (var value in items)
  115. {
  116. var dialog = new MessageDialog("Welcome Back " + value.userName);
  117. await dialog.ShowAsync();
  118. }
  119.  
  120.  
  121. if (IsAuth > 0)
  122. {
  123. var dialog = new MessageDialog("You are Authenticated");
  124. await dialog.ShowAsync();
  125.  
  126. }
  127. else
  128. {
  129. var dialog = new MessageDialog(" Account Does Not Exist, please Register to get Started.");
  130. await dialog.ShowAsync();
  131. }
  132. }
  133. catch (Exception em)
  134. {
  135. var dialog = new MessageDialog("An Error Occured: " + em.Message);
  136. await dialog.ShowAsync();
  137. }
  138. }
  139.  
  140. async private void submitAuthBtn_Copy_Click(object sender, RoutedEventArgs e)
  141. {
  142. try
  143. {
  144. User_Cred itemReg = new User_Cred
  145. {
  146. userName = UserNameEnter.Text,
  147. Password = PWEnter.Text
  148. };
  149. await App.MobileService.GetTable<User_Cred>().InsertAsync(itemReg);
  150. var dialog = new MessageDialog("Thank you for Registering! Lets begin");
  151. await dialog.ShowAsync();
  152. }
  153. catch (Exception em)
  154. {
  155. var dialog = new MessageDialog("An Error Occured: " + em.Message);
  156. await dialog.ShowAsync();
  157. }
  158. }
  159.  
  160.  
  161.  
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement