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();
                }
            }
        }
Esempio n. 2
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();
            }
            
        }