Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int IsAuth { get; set; }
- //[DataTable("User_Cred")]
- public class User_Cred
- {
- public string id { get; set; }
- public string Username { get; set; }
- public string Password { get; set; }
- }
- private IMobileServiceSyncTable<User_Cred> todoGetTable = App.MobileService.GetSyncTable<User_Cred>();
- private async Task InitLocalStoreAsync()
- {
- if (!App.MobileService.SyncContext.IsInitialized)
- {
- var store = new MobileServiceSQLiteStore("CIS4910C-DB");
- store.DefineTable<User_Cred>();
- await App.MobileService.SyncContext.InitializeAsync(store);
- }
- await SyncAsync();
- }
- private async Task SyncAsync()
- {
- await App.MobileService.SyncContext.PushAsync();
- await todoGetTable.PullAsync("User_Cred", todoGetTable.CreateQuery());
- }
- async public void submitAuthBtn_Click(object sender, RoutedEventArgs e)
- {
- await InitLocalStoreAsync();
- GetAuthentication();
- }
- async public void GetAuthentication()
- {
- try
- {
- //IMobileServiceTable<User_Cred> todoTable = App.MobileService.GetTable<User_Cred>();
- List<User_Cred> items = await todoGetTable
- .Where(User_Cred => User_Cred.Username == textBoxUsername.Text)
- .ToListAsync();
- IsAuth = items.Count();
- // Return a List UI control value back to the form
- foreach (var value in items)
- {
- var dialog = new MessageDialog("Welcome Back " + value.Username);
- await dialog.ShowAsync();
- this.Frame.Navigate(typeof(home));
- }
- if (IsAuth > 0)
- {
- var dialog = new MessageDialog("You are Authenticated");
- await dialog.ShowAsync();
- }
- else
- {
- var dialog = new MessageDialog(" Account Does Not Exist, please Register to get Started.");
- await dialog.ShowAsync();
- }
- }
- catch (Exception em)
- {
- var dialog = new MessageDialog("An Error Occured: " + em.Message);
- await dialog.ShowAsync();
- }
- }
- async private void submitAuthBtn_Copy_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- User_Cred itemReg = new User_Cred
- {
- Username = textBoxUsername.Text,
- Password = textBoxPassword.Text
- };
- await App.MobileService.GetTable<User_Cred>().InsertAsync(itemReg);
- var dialog = new MessageDialog("Thank you for Registering! Now just hit log in");
- await dialog.ShowAsync();
- }
- catch (Exception em)
- {
- var dialog = new MessageDialog("An Error Occured: " +em.Message);
- await dialog.ShowAsync();
- }
- }
- public string globalUserLabel;
- public void SaveSetting(string userLabel, string userNamelabel)
- {
- globalUserLabel = userLabel;
- ApplicationDataContainer localSettings =
- ApplicationData.Current.LocalSettings;
- //Saving your setting
- localSettings.Values[userLabel] = textBoxUsername.Text;
- }
- public home()
- {
- this.InitializeComponent();
- UserNameLabelBox.Text = ReadSetting(MainPage.globalUserLabel );
- }
- private string ReadSetting(string userLabel)
- {
- Windows.Storage.ApplicationDataContainer localSettings =
- Windows.Storage.ApplicationData.Current.LocalSettings;
- //Reading and returning your setting value
- var value = localSettings.Values[userLabel];
- if (value != null)
- return value.ToString();
- else
- return userLabel;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement