private void OnButtonUpdateClick(object sender, EventArgs e) { if (lvSales.SelectedItems.Count != 1) { MessageBox.Show("Please select one sale.", Constant.StoreAppName); return; } Sales sale = (Sales)lvSales.SelectedItems[0].Tag; UnitOfWork unitOfWork = new UnitOfWork(new StoreAppDBEntities()); sale = unitOfWork.Sales.Get(sale.SaleId); var dialog = new FormSaleDialog(sale, unitOfWork); DialogResult result = dialog.ShowDialog(); if (result != DialogResult.OK) { return; } int entriesWritten = unitOfWork.Complete(); if (entriesWritten == 0) { MessageBox.Show("There was a problem updating the sale.", Constant.StoreAppName); return; } UpdateListView(sale, ListViewAction.Update, lvSales.SelectedItems[0].Index); }
private void OnButtonAddClick(object sender, EventArgs e) { var sale = new Sales(); var dialog = new FormSaleDialog(sale, _unitOfWork); DialogResult result = dialog.ShowDialog(); if (result != DialogResult.OK) { return; } _unitOfWork.Sales.Add(sale); int entriesWritten = _unitOfWork.Complete(); if (entriesWritten == 0) { MessageBox.Show("There was a problem adding a new sale.", Constant.StoreAppName); return; } UpdateListView(sale, ListViewAction.Add, Constant.IndexNone); }