private void OnButtonUpdateClick(object sender, EventArgs e) { if (lvProducts.SelectedItems.Count != 1) { MessageBox.Show("Please select one product.", Constant.StoreAppName); return; } Products product = (Products)lvProducts.SelectedItems[0].Tag; var dialog = new FormProductDialog(product, _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 product.", Constant.StoreAppName); return; } UpdateListView(product, ListViewAction.Update, lvProducts.SelectedItems[0].Index); }
private void OnButtonAddClick(object sender, EventArgs e) { var product = new Products(); var dialog = new FormProductDialog(product, _unitOfWork); DialogResult result = dialog.ShowDialog(); if (result != DialogResult.OK) { return; } _unitOfWork.Products.Add(product); int entriesWritten = _unitOfWork.Complete(); if (entriesWritten == 0) { MessageBox.Show("There was a problem adding a new product.", Constant.StoreAppName); return; } UpdateListView(product, ListViewAction.Add, Constant.IndexNone); }