private void DeleteMenuButton_Click(object sender, RoutedEventArgs e) { Accepted selectedItem = (Accepted)AcceptedDataGrid.SelectedItem; if (selectedItem == null) { MessageBox.Show("Line not selected"); return; } try { if (_db.Storage.FirstOrDefault(o => o.NameItem == selectedItem.NameItem) != null) { Accepted acceptedObj = _db.Accepted.FirstOrDefault(o => o.NameItem == selectedItem.NameItem); Models.Storage storageObj = _db.Storage.FirstOrDefault(o => o.NameItem == selectedItem.NameItem); if (acceptedObj == null || storageObj == null) { throw new ArgumentNullException(); } _db.Accepted.Remove(acceptedObj); _db.Storage.Remove(storageObj); Refresh(); } else { MessageBox.Show("Already sold. Unable to delete"); } } catch (Exception) { MessageBox.Show("Error"); } }
private void SaleMenuButton_Click(object sender, RoutedEventArgs e) { Models.Storage selectedItem = (Models.Storage)StorageDataGrid.SelectedItem; if (selectedItem == null) { MessageBox.Show("Line not selected"); return; } try { Models.Storage storageObj = _db.Storage.FirstOrDefault(o => o.NameItem == selectedItem.NameItem); if (storageObj == null) { throw new ArgumentNullException(); } _db.SoldOut.Add(new Models.SoldOut { NameItem = storageObj.NameItem, Count = storageObj.Count, Price = storageObj.Price, DateCreate = DateTime.Now }); _db.Storage.Remove(storageObj); Refresh(); } catch (Exception) { MessageBox.Show("Error"); } }