Esempio n. 1
0
        private async void Sync_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new OrdersContext())
            {
                var orders = db.Orders.Where(o => o.IsShipped && !o.IsShippingSynced).ToList();

                if (orders.Any())
                {
                    try
                    {
                        foreach (var order in orders)
                        {
                            await UnicornStoreService.ShippedOrder(order.OrderId);

                            order.IsShippingSynced = true;
                            db.SaveChanges();
                        }

                        var dialog = new MessageDialog("All shipped orders now recorded in central database.");
                        await dialog.ShowAsync();
                    }
                    catch (HttpRequestException)
                    {
                        var dialog = new MessageDialog("Could not connect. Try again when you have a network connection.");
                        await dialog.ShowAsync();
                    }
                }
                else
                {
                    var dialog = new MessageDialog("There weren't any shipped orers not already recorded in central database.");
                    await dialog.ShowAsync();
                }
            }
        }
        private async void Shipped_Click(object sender, RoutedEventArgs e)
        {
            if (await ConfirmShipping())
            {
                CurrentOrder.IsShipped = true;
                db.SaveChanges();

                try
                {
                    await UnicornStoreService.ShippedOrder(CurrentOrder.OrderId);

                    CurrentOrder.IsShippingSynced = true;
                    db.SaveChanges();
                }
                catch (HttpRequestException)
                {
                    var dialog = new MessageDialog("Could not mark as shipped in central database. Use the 'Sync' button when you are back online.");
                    await dialog.ShowAsync();
                }

                ReLoadAssignedOrders();
            }
        }