private void AddButtonClick(object sender, RoutedEventArgs e) { var selectedItem = goodsComboBox.SelectedValue as ListBoxItem; AddGoodsWindow addGoodsWindow = new AddGoodsWindow(); if (selectedItem != null) addGoodsWindow = new AddGoodsWindow(selectedItem.Id); addGoodsWindow.ShowDialog(); if (string.IsNullOrWhiteSpace(addGoodsWindow.Value)) return; using (var db = new Model.BudgetModel()) { var goodsItem = new GoodsItem(); goodsItem.Name = addGoodsWindow.Value; goodsItem.Category = db.Categories.Find(addGoodsWindow.Category.Id); goodsItem.UnitOfMeasure = db.UnitOfMeasures.Find(addGoodsWindow.UnitOfMeasure.Id); db.Goods.Add(goodsItem); db.SaveChanges(); } UpdateListBox(); }
private void RenameMenuItemClick(object sender, RoutedEventArgs e) { var selectedItem = goodsLstBox.SelectedValue as ListBoxItem; var selectedCategory = goodsComboBox.SelectedValue as ListBoxItem; if (selectedItem == null) return; using (var db = new Model.BudgetModel()) { var goodsItem = db.Goods.Find(selectedItem.Id); AddGoodsWindow addGoodsItem = new AddGoodsWindow( goodsItem.Category.Id, goodsItem.UnitOfMeasure.Id, goodsItem.Name ); addGoodsItem.ShowDialog(); if (addGoodsItem.Category == null || addGoodsItem.UnitOfMeasure == null || string.IsNullOrWhiteSpace(addGoodsItem.Value)) return; goodsItem.Name = addGoodsItem.Value; goodsItem.Category = db.Categories.Find(addGoodsItem.Category.Id); goodsItem.UnitOfMeasure = db.UnitOfMeasures.Find(addGoodsItem.UnitOfMeasure.Id); db.SaveChanges(); UpdateListBox(); } }