Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static MobileServiceClient MobileService = new
- MobileServiceClient("URL");
- private IMobileServiceSyncTable<User_Cred> todoGetTable =
- App.MobileService.GetSyncTable<User_Cred>();
- private async Task InitLocalStoreAsync()
- {
- if (!App.MobileService.SyncContext.IsInitialized)
- {
- var store = new MobileServiceSQLiteStore("Tale-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: User Name
- Already exists.");
- await dialog.ShowAsync();
- }
- }
- IMobileServiceTable<TodoItem> todoTable =
- App.MobileService.GetTable<TodoItem>();
- MobileServiceCollection<TodoItem, TodoItem> items;
- public class TodoItem
- {
- public string Id { get; set; }
- public string Title { get; set; }
- public bool Complete { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string ISBN { get; set; }
- public string PublicationDate { get; set; }
- }
- async private void Submit_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- TodoItem item = new TodoItem
- {
- Title = txtBxTitle.Text,
- FirstName = txtBxFName.Text,
- LastName = txtBxLName.Text,
- ISBN = txtBxISBN.Text,
- PublicationDate = txtBxPubDate.Text,
- Complete = false
- };
- await App.MobileService.GetTable<TodoItem>().InsertAsync(item);
- var dialog = new MessageDialog("Successful!");
- await dialog.ShowAsync();
- }
- catch (Exception em)
- {
- var dialog = new MessageDialog("An Error Occured: " +
- em.Message);
- await dialog.ShowAsync();
- }
- }
- private async Task RefreshTodoItems()
- {
- MobileServiceInvalidOperationException exception = null;
- try
- {
- // This code refreshes the entries in the list view by querying
- the TodoItems table.
- // The query excludes completed TodoItems
- items = await todoTable
- .Where(TodoItem => TodoItem.Complete == false)
- .ToCollectionAsync();
- }
- catch (MobileServiceInvalidOperationException e)
- {
- exception = e;
- }
- if (exception != null)
- {
- await new MessageDialog(exception.Message, "Error loading
- items").ShowAsync();
- }
- else
- {
- ListItems.ItemsSource = items;
- this.btnRefresh.IsEnabled = true;
- }
- }
- private async void CheckBoxComplete_Checked(object sender, RoutedEventArgs
- e)
- {
- CheckBox cb = (CheckBox)sender;
- TodoItem item = cb.DataContext as TodoItem;
- await UpdateCheckedTodoItem(item);
- }
- private async Task UpdateCheckedTodoItem(TodoItem item)
- {
- // This code takes a freshly completed TodoItem and updates the
- database. When the MobileService
- // responds, the item is removed from the list
- await todoTable.UpdateAsync(item);
- items.Remove(item);
- ListItems.Focus(Windows.UI.Xaml.FocusState.Unfocused);
- //await SyncAsync(); // offline sync
- }
Add Comment
Please, Sign In to add comment