public async void SubmitCartToAzureLocalDB() { try { List <OrderItems> Items = new List <OrderItems>(); for (int i = 0; i < CartItems.Count; i++) { Items.Add(new OrderItems() { ItemCount = CartItems[i].Count, ItemID = CartItems[i].ID, OrderID = OrderID, Id = Guid.NewGuid().ToString() }); } Order order = new Order() { SubmittedOffline = true, ID = OrderID, UserID = SharedUser.ID, }; await client.InsertOfflineSyncObjectAsync <Order>(order, OrdersTable); for (int i = 0; i < Items.Count; i++) { await client.InsertOfflineSyncObjectAsync <OrderItems>(Items[i], OrdersItemsTable); } } catch (Exception) { await PopUpsHelper.DisplayMessage("Connection Error", "Error While Submitting To Local DB", "OK"); } }
private async Task SyncAllTables() { var ItemsTable = OfflineManager.GetOfflineSyncTableReference <Item>(); var UsersTable = OfflineManager.GetOfflineSyncTableReference <User>(); var OrdersTable = OfflineManager.GetOfflineSyncTableReference <Order>(); var OrderItemsTable = OfflineManager.GetOfflineSyncTableReference <OrderItems>(); if (Connectivity.NetworkAccess == NetworkAccess.Internet) { await OfflineManager.PushAsync(); await OfflineManager.PullAsync <Item>(ItemsTable); await OfflineManager.PullAsync <User>(UsersTable); await OfflineManager.PullAsync <Order>(OrdersTable); await OfflineManager.PullAsync <OrderItems>(OrderItemsTable); //var result = await OfflineManager.GetAllOfflineSyncItemsAsync<Item>(ItemsTable); //var result1 = await OfflineManager.GetAllOfflineSyncItemsAsync<User>(UsersTable); //var result2 = await OfflineManager.GetAllOfflineSyncItemsAsync<Order>(OrdersTable); //var result4 = await OfflineManager.GetAllOfflineSyncItemsAsync<OrderItems>(OrderItemsTable); } else { await PopUpsHelper.DisplayMessage("Connection Error", "Please Connect your phone to the internet to sync items", "OK"); } }
public async Task SyncItems() { try { IsLoading = true; var Table = OfflineManager.GetOfflineSyncTableReference <Item>(); if (Connectivity.NetworkAccess == NetworkAccess.Internet) { await OfflineManager.PushAsync(); await OfflineManager.PullAsync <Item>(Table); await NavigationHelper.PopPageAsync(); await NavigationHelper.NavigateToPageAsync(new HomePage()); } else { await PopUpsHelper.DisplayMessage("Connection Error", "Please Connect your phone to the internet", "OK"); IsLoading = false; } } catch (Exception ex) { IsLoading = false; await PopUpsHelper.DisplayMessage("Sync Error", "Error While Syncing new products", "OK"); } }
public async Task <ObservableCollection <Item> > GetCartItemsFromAzureLocalDB() { try { IsLoading = true; AllItems = await client.GetAllOfflineSyncItemsAsync <Item>(ItemsTable); Users = await client.GetAllOfflineSyncItemsAsync <User>(UsersTable); Orders = await client.GetAllOfflineSyncItemsAsync <Order>(OrdersTable); OrdersItems = await client.GetAllOfflineSyncItemsAsync <OrderItems>(OrdersItemsTable); User User = SharedUser; Order Order = Orders.FirstOrDefault(o => (o.UserID == User.ID && (o.SubmittedOffline == false || o.SubmittedOnline == false))); List <string> ItemsIDS = OrdersItems.Where(i2 => i2.OrderID == Order.ID).Select(i => i.ItemID).ToList(); CartItems = new ObservableCollection <Item>(AllItems.Where(o => { var orderitem = OrdersItems.FirstOrDefault(oi => oi.ItemID == o.ID); if (orderitem != null) { o.Count = orderitem.ItemCount; } return(ItemsIDS.Contains(o.ID)); })); if (CartItems.Count == 0) { IsCartNotEmpty = false; } else { IsCartNotEmpty = true; } IsLoading = false; return(CartItems); } catch (Exception) { IsLoading = false; await PopUpsHelper.DisplayMessage("Connection Error", "Error While getting Data From local DB", "OK"); return(null); } }
public async Task GetAllItemsFromLocalDBAsync() { try { IsLoading = true; var Table = OfflineManager.GetOfflineSyncTableReference <Item>(); var result = await OfflineManager.GetAllOfflineSyncItemsAsync <Item>(Table); for (int i = 0; i < result?.Count; i++) { result[i].SmallDetails = result[i].Details.Length > 51 ? result[i].Details.Substring(0, 50) : result[i].Details; } Filter(result); IsLoading = false; } catch (Exception ex) { IsLoading = false; await PopUpsHelper.DisplayMessage("Sync Error", "Error While Getting all offline products", "OK"); } }
public async void SubmitCartToAzureDB() { try { if (InternetConnected) { List <OrderItems> Items = new List <OrderItems>(); for (int i = 0; i < SQLITEItems.Count; i++) { Items.Add(new OrderItems() { ItemCount = SQLITEItems[i].Count, ItemID = SQLITEItems[i].ItemID }); } Order order = new Order() { User = new Models.User() { Name = SharedUser.Name, ID = SharedUser.ID }, OrderItems = Items, }; var table = Client.GetTableReference <Order>(); await Client.InsertObjectAsync(order, table); } else { await PopUpsHelper.DisplayMessage("Connection Error", "Please Connect your phone to the internet to Submit Order items", "OK"); } } catch (Exception ex) { await PopUpsHelper.DisplayMessage("Connection Error", "Please Check Your Internet", "OK"); } }