/// <summary> /// Saves the current order to the database. /// </summary> public async Task SaveOrder() { Order result = null; try { var db = new ContosoModels.ContosoDataSource(); result = await db.Orders.PostAsync(_order); } catch (Exception ex) { throw new OrderSavingException("Unable to save. There might have been a problem " + "connecting to the database. Please try again.", ex); } if (result != null) { await Utilities.CallOnUiThreadAsync(() => HasChanges = false); } else { await Utilities.CallOnUiThreadAsync(() => new OrderSavingException( "Unable to save. There might have been a problem " + "connecting to the database. Please try again.")); } }
/// <summary> /// Retrieves orders from the data source. /// </summary> public async void LoadOrders() { await Utilities.CallOnUiThreadAsync(() => { IsLoading = true; Orders.Clear(); masterOrdersList.Clear(); }); var db = new ContosoModels.ContosoDataSource(); var orders = await db.Orders.GetAsync(); await Utilities.CallOnUiThreadAsync(() => { if (orders != null) { foreach (Order o in orders) { Orders.Add(o); masterOrdersList.Add(o); } } IsLoading = false; }); }
/// <summary> /// Loads the specified customer and sets the /// SelectedCustomer property. /// </summary> /// <param name="customerId">The customer to load.</param> private async void loadCustomer(Guid customerId) { var db = new ContosoModels.ContosoDataSource(); var customer = await db.Customers.GetAsync(customerId); await Utilities.CallOnUiThreadAsync(() => { SelectedCustomer = customer; }); }
/// <summary> /// Deletes the specified order from the database. /// </summary> /// <param name="orderToDelete">The order to delete.</param> public async Task DeleteOrder(Order orderToDelete) { var db = new ContosoModels.ContosoDataSource(); var response = await db.Orders.DeleteAsync(orderToDelete.Id); if (!response.IsSuccessStatusCode) { Orders.Remove(orderToDelete); SelectedOrder = null; } else { throw new OrderDeletionException(response.ReasonPhrase); } }
/// <summary> /// Queries the database and updates the list of new product suggestions. /// </summary> /// <param name="queryText">The query to submit.</param> public async void UpdateProductSuggestions(string queryText) { ProductSuggestions.Clear(); if (!string.IsNullOrEmpty(queryText)) { var dataSource = new ContosoModels.ContosoDataSource(); var suggestions = await dataSource.Products.GetAsync(queryText); foreach (Product p in suggestions) { ProductSuggestions.Add(p); } } }
/// <summary> /// Submits a query to the data source. /// </summary> /// <param name="query"></param> public async void QueryOrders(string query) { IsLoading = true; Orders.Clear(); if (!string.IsNullOrEmpty(query)) { var dataSource = new ContosoModels.ContosoDataSource(); var results = await dataSource.Orders.GetAsync(query); await Utilities.CallOnUiThreadAsync(() => { foreach (Order o in results) { Orders.Add(o); } IsLoading = false; }); } }