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 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(); } }