public PurchaseOrdersListViewModel()
        {
            if (DesignerProperties.GetIsInDesignMode(
                new System.Windows.DependencyObject())) return;

            try
            {
                var purchaseOrders = db.PurchaseOrders.Include(p => p.Supplier);
                PurchaseOrders = new ObservableCollection<PurchaseOrder>(purchaseOrders.ToList());
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message.ToString());
            }
            try
            {
                var suppliers = db.Suppliers.ToList();
                Suppliers = new ObservableCollection<Supplier>(suppliers);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message.ToString());
            }
            try
            {
                var rawMaterials = db.RawMaterials.ToList();
                RawMaterials = new ObservableCollection<RawMaterial>(rawMaterials);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message.ToString());
            }

            _newPurchaseOrder = new PurchaseOrder();
            _newPurchaseOrderLine = new PurchaseOrderLine();
            _newPurchaseOrder.PurchaseOrderLines = new ObservableCollection<PurchaseOrderLine>();
            _purchaseOrderLines = new ObservableCollection<PurchaseOrderLine>();
            _searchResults = new ObservableCollection<PurchaseOrder>();

            DeletePurchaseOrderCommand = new RelayCommand<PurchaseOrder>(onDeletePurchaseOrder);
            UpdatePurchaseOrderCommand = new RelayCommand<PurchaseOrder>(onUpdatePurchaseOrder);
            AddPurchaseOrderCommand = new RelayCommand<PurchaseOrder>(onAddPurchaseOrder);
            AddPurchaseOrderLineCommand = new RelayCommand<PurchaseOrderLine>(onAddPurchaseOrderLine);
            UpdatePurchaseOrderLineCommand = new RelayCommand<PurchaseOrderLine>(onUpdatePurchaseOrderLine);
            SelectPurchaseOrderCommand = new RelayCommand<PurchaseOrder>(onSelectPurchaseOrder);
            FindPurchaseOrdersCommand = new RelayCommand<string>(onFindPurchaseOrders);

            DeletePurchaseOrderLineCommand = new RelayCommand<PurchaseOrderLine>(onDeletePurchaseOrderLine);
            DeleteNewPurchaseOrderLineCommand = new RelayCommand<PurchaseOrderLine>(onDeleteNewPurchaseOrderLine);
        }
        public void onDeletePurchaseOrderLine(PurchaseOrderLine line)
        {
            if (line != null)
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure you wish to delete this item?", "Confirm Delete", System.Windows.MessageBoxButton.YesNo);

                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int purchaseOrderLineid = line.purchaseOrderLinesID;
                    PurchaseOrderLine lineToRemove = (PurchaseOrderLine)PurchaseOrderLines.Single(p => p.purchaseOrderLinesID == purchaseOrderLineid);

                    db.PurchaseOrderLines.Remove(lineToRemove);
                    db.SaveChanges();
                    PurchaseOrders = UpdatePurchaseOrdersCollection(PurchaseOrders);
                }
            }
        }
 public void onUpdatePurchaseOrderLine(PurchaseOrderLine line)
 {
     var newPurchaseOrderLine = line;
      if (newPurchaseOrderLine != null)
      NewPurchaseOrder.PurchaseOrderLines.Add(newPurchaseOrderLine);
 }
        public void onAddPurchaseOrderLine(PurchaseOrderLine line)
        {
            var  newLine = line;

            if (newLine != null)
            {
                NewPurchaseOrderLine = newLine;
            }
            NewPurchaseOrder.PurchaseOrderLines.Add(NewPurchaseOrderLine);
        }