private void submitBtn_Click(object sender, RoutedEventArgs e) { try { //dictionary to map an item to its quantity in this transaction Dictionary <Item, int> itemToQuantity = new Dictionary <Item, int>(); foreach (TillDataRow tdr in ItemDisplayDatGrd.Items) { itemToQuantity.Add(tdr.Item, tdr.Quantity); } using (var tRepo = new TransactionRepo(new InventoryContext())) { tRepo.AddNewTransaction(itemToQuantity); tRepo.Complete(); } //it worked MessageBox.Show("Transaction added"); ClearAll(); } catch (Exception) { MessageBox.Show("An error occured. Try again"); } }
public ViewTransactionsPageVM() { //assigns default values to display using (var TRepo = new TransactionRepo(new InventoryContext())) { Transactions = TRepo.AllTransactionsIncludeItemTransaction(); TRepo.Complete(); } //Default values from first transaction from db SelectionChanged(Transactions[0]); }
private void TransactionsDisplay_SelectionChanged(object sender, SelectionChangedEventArgs e) { //update dataContext w/ new transaction //datagrid display transactionID = 1 in index = 0; therefor + 1 int selectedTransactionID = TransactionsDisplay.SelectedIndex + 1; Transaction selectedTransaction; using (var TRepo = new TransactionRepo(new InventoryContext())) { selectedTransaction = TRepo.GetByID(selectedTransactionID, "ItemTransactions"); TRepo.Complete(); } dataContext.SelectionChanged(selectedTransaction); UpdateAll(); }
public static void TryAddNewTransactionUsingTRepo() { List <Item> itemsToAdd = new List <Item>(); Dictionary <Item, int> itemToInt = new Dictionary <Item, int>(); using (var iRepo = new ItemRepository(new InventoryContext())) { //first 3 items in db itemsToAdd = iRepo.GetAll().Take(5).ToList(); } //first 3 items, all w/ quantity = 1 itemsToAdd.ForEach(i => itemToInt.Add(i, 1)); using (var tRepo = new TransactionRepo(new InventoryContext())) { tRepo.AddNewTransaction(itemToInt); tRepo.Complete(); } }