private void Button_Click_SaveAll(object sender, RoutedEventArgs ev) { if (!_model.IsValid()) { MessageBox.Show("ОШИБКА"); return; } Purchase purchase; if (_isEditMode) { int id = _model.PurchaseID; purchase = _db.Purchases.Where(p => p.PurchaseID == id).FirstOrDefault(); purchase.Quantity = _model.Quantity; purchase.Timestamp = _model.Timestamp; purchase.TotalPrice = _model.TotalPrice; purchase.Credentials = _model.Credentials; purchase.StoreItem = _model.StoreItem; _db.TryAction(DatabaseActions.UPDATE, purchase); } else { purchase = new Purchase() { Quantity = _model.Quantity, Timestamp = DateTime.Now, TotalPrice = _model.TotalPrice, Credentials = _model.Credentials, StoreItem = _model.StoreItem }; _db.TryAction(DatabaseActions.ADD, purchase); }; _db.SaveChanges(); _w.LoadInfoFromDb(); }