Esempio n. 1
0
        /// <summary>
        /// Gets the complete list of customers from the database.
        /// </summary>
        private async void GetCustomerList()
        {
            IsLoading = true;

            var db        = new ContosoDataSource();
            var customers = await db.Customers.GetAsync();

            await Utilities.CallOnUiThreadAsync(() =>
            {
                if (customers != null)
                {
                    ErrorText = null;
                    Customers.Clear();
                    foreach (var c in customers)
                    {
                        Customers.Add(new CustomerViewModel(c));
                    }
                }
                else
                {
                    // There was a problem retreiving customers. Let the user know.
                    ErrorText = "Couldn't retrieve customers. Check your connection and " +
                                "click Refresh to try again.";
                }

                IsLoading = false;
            });
        }
        /// <summary>
        /// Returns the order with the specified ID.
        /// </summary>
        /// <param name="orderId">The ID of the order to retrieve.</param>
        /// <returns>The order, if it exists; otherwise, null. </returns>
        private static async Task <Order> getOrder(Guid orderId)
        {
            var db    = new ContosoDataSource();
            var order = await db.Orders.GetAsync(orderId);

            return(order);
        }
        private async void GetOrdersList()
        {
            IsLoading = true;

            var db     = new ContosoDataSource();
            var orders = await db.Orders.GetAsync(Model);

            await Utilities.CallOnUiThreadAsync(() =>
            {
                if (orders != null)
                {
                    foreach (Order o in orders)
                    {
                        Orders.Add(o);
                    }
                }
                else
                {
                    // There was a problem retreiving customers. Let the user know.
                    ErrorText = "Couldn't retrieve orders.";
                }

                IsLoading = false;
            });
        }
        /// <summary>
        /// Loads the customer with the specified ID.
        /// </summary>
        /// <param name="customerId">The ID of the customer to load.</param>
        private async void loadCustomer(Guid customerId)
        {
            var db       = new ContosoDataSource();
            var customer = await db.Customers.GetAsync(customerId);

            await Utilities.CallOnUiThreadAsync(() =>
            {
                Customer = customer;
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the customer with the specified ID.
        /// </summary>
        /// <param name="customerId">The ID of the customer to load.</param>
        private async void LoadCustomer(Guid customerId)
        {
            var db       = new ContosoDataSource();
            var customer = await db.Customers.GetAsync(customerId);

            await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
            {
                Customer = customer;
            });
        }
Esempio n. 6
0
 /// <summary>
 /// Queries the database for a current list of customers.
 /// </summary>
 private void OnSync()
 {
     Task.Run(async() =>
     {
         IsLoading = true;
         var db    = new ContosoDataSource();
         foreach (var modifiedCustomer in Customers
                  .Where(x => x.IsModified).Select(x => x.Model))
         {
             await db.Customers.PostAsync(modifiedCustomer);
         }
         await GetCustomerListAsync();
         IsLoading = false;
     });
 }
 /// <summary>
 /// Queries the database for a customer result matching the search text entered.
 /// </summary>
 private async void CustomerSearchBox_TextChanged(AutoSuggestBox sender,
                                                  AutoSuggestBoxTextChangedEventArgs args)
 {
     // We only want to get results when it was a user typing,
     // otherwise we assume the value got filled in by TextMemberPath
     // or the handler for SuggestionChosen
     if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
     {
         // If no search query is entered, refresh the complete list.
         if (string.IsNullOrEmpty(sender.Text))
         {
             sender.ItemsSource = null;
         }
         else
         {
             ContosoDataSource data = new ContosoDataSource();
             sender.ItemsSource = await data.Customers.GetAsync(sender.Text);
         }
     }
 }
        private async void OnSave()
        {
            if (CanSave == true)
            {
                Model.FirstName = _firstNameOriginal = FirstName;
                Model.LastName  = _lastNameOriginal = LastName;
                Model.Company   = _companyOriginal = Company;
                Model.Email     = _emailOriginal = Email;
                Model.Phone     = _phoneOriginal = Phone;
                Model.Address   = _addressOriginal = Address;

                var db = new ContosoDataSource();
                await db.Customers.PostAsync(Model);

                HasChanges = true;
                if (IsNewCustomer == true)
                {
                    IsNewCustomer = false;
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the complete list of customers from the database.
        /// </summary>
        public async Task GetCustomerListAsync()
        {
            await Utilities.CallOnUiThreadAsync(() => IsLoading = true);

            var db        = new ContosoDataSource();
            var customers = await db.Customers.GetAsync();

            if (customers == null)
            {
                return;
            }
            await Utilities.CallOnUiThreadAsync(() =>
            {
                Customers.Clear();
                foreach (var c in customers)
                {
                    Customers.Add(new CustomerViewModel(c)
                    {
                        Validate = true
                    });
                }
                IsLoading = false;
            });
        }