public SuppliersListViewModel() { if (DesignerProperties.GetIsInDesignMode( new System.Windows.DependencyObject())) return; try { var suppliers = db.Suppliers.Include(s => s.Suburb); Suppliers = new ObservableCollection<Supplier>(suppliers.ToList()); } catch (Exception ex) { logger.Error(ex.Message.ToString()); } try { var suburbs = db.Suburbs.ToList(); Suburbs = new ObservableCollection<Suburb>(suburbs); } catch (Exception ex) { logger.Error(ex.Message.ToString()); } _newSupplier = new Supplier(); _searchResults = new ObservableCollection<Supplier>(); DeleteSupplierCommand = new RelayCommand<Supplier>(onDeleteSupplier); UpdateSupplierCommand = new RelayCommand<Supplier>(onUpdateSupplier); AddSupplierCommand = new RelayCommand<Supplier>(onAddSupplier); FindSuppliersCommand = new RelayCommand<string>(onFindSuppliers); }
public void onDeleteSupplier(Supplier sup) { if (sup != null) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure you wish to delete this supplier?", "Confirm Delete", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { int supplierid = sup.supplierID; Supplier supToRemove = (Supplier)Suppliers.Single(s => s.supplierID == supplierid); db.Suppliers.Remove(supToRemove); db.SaveChanges(); Suppliers = UpdateSuppliersCollection(Suppliers); } } }
public void onUpdateSupplier(Supplier sup) { var supplier = sup; if (supplier != null) { db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); Suppliers = UpdateSuppliersCollection(Suppliers); MessageBoxResult msgBox = MessageBox.Show("Changes Saved", "Success"); } }
public void onAddSupplier(Supplier sup) { var newSupplier = sup; if (newSupplier != null) { db.Suppliers.Add(newSupplier); db.SaveChanges(); Suppliers = UpdateSuppliersCollection(Suppliers); MessageBoxResult msgBox = MessageBox.Show("Supplier Added", "Success"); } }