Пример #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();
                }
            }
        }
Пример #2
0
        private async Task ReLoadPendingOrders()
        {
            this.Orders.ItemsSource     = null;
            this.Message.Visibility     = Visibility.Visible;
            this.OrdersPanel.Visibility = Visibility.Collapsed;

            Message.Text = "Fetching pending orders...";

            try
            {
                var orders = await UnicornStoreService.GetPendingOrders();

                if (orders.Any())
                {
                    this.Orders.ItemsSource     = orders;
                    this.Message.Visibility     = Visibility.Collapsed;
                    this.OrdersPanel.Visibility = Visibility.Visible;
                }
                else
                {
                    Message.Text = "There are currently no pending orders.";
                }
            }
            catch (HttpRequestException)
            {
                Message.Text = "Could not connect. Try again when you have a network connection.";
            }
        }
Пример #3
0
        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();
            }
        }
Пример #4
0
        private async void AssignOrders_Click(object sender, RoutedEventArgs e)
        {
            var selectedOrders = Orders.SelectedItems.Cast <Order>().ToList();

            // Assign selected orders to current user
            var selectedIds = selectedOrders.Select(o => o.OrderId);

            try
            {
                await UnicornStoreService.PackingOrders(selectedIds);

                // Take a local copy of the orders
                using (var db = new OrdersContext())
                {
                    foreach (var order in selectedOrders)
                    {
                        db.Orders.Add(order);
                        db.OrderLines.AddRange(order.Lines);
                    }

                    db.SaveChanges();
                }

                // Refresh the page with pending orders
                await ReLoadPendingOrders();

                // Inform user of success
                var dialog = new MessageDialog("Orders successfully assigned.");
                await dialog.ShowAsync();
            }
            catch (HttpRequestException)
            {
                var dialog = new MessageDialog("Could not connect. Try again when you have a network connection.");
                await dialog.ShowAsync();
            }
        }