コード例 #1
0
 public void GetToPreviousWindow()
 {
     if (OrderedProducts.Any())
     {
         MessageBox.Show("You cannot leave this window while ordered products is not empty", "Exception", MessageBoxButton.OK, MessageBoxImage.Warning);
         return;
     }
     else
     {
         var menu = new MenuView();
         menu.Show();
         CloseAction();
     }
 }
コード例 #2
0
        public void ProcessOrderedItems()
        {
            if (OrderedProducts.Any())
            {
                var sales = new List <Sale>();

                foreach (var item in OrderedProducts)
                {
                    var sale = new Sale
                    {
                        Amount          = item.Quantity * item.Price,
                        Name            = item.Name,
                        TransactionDate = DateTime.UtcNow,
                        UomType         = item.UomType,
                        Quantity        = item.Quantity
                    };

                    sales.Add(sale);
                }

                _context.Sales.AddRange(sales);

                _context.SaveChanges();

                var receiptView = new ReceiptView();
                var viewModel   = new ReceiptViewModel();
                receiptView.DataContext = viewModel;
                if (viewModel.CloseAction == null)
                {
                    viewModel.CloseAction = new Action(receiptView.Close);
                }

                ((ReceiptViewModel)receiptView.DataContext).LoadOrderedProducts(OrderedProducts.ToModelObservableCollection());
                receiptView.ShowDialog();

                OrderedProducts.Clear();
                RaisePropertyChanged("OrderedProducts");
            }
            else
            {
                MessageBox.Show("There is no item to order", "Exception", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
        }