/// <summary> /// category context menu add click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CategoryContextMenuAdd_Click(object sender, RoutedEventArgs e) { var dialog = new EditCategoryName(this); if (true != dialog.ShowDialog()) { return; } using (var table = new CategoriesTable(this._profileDatabase)) { var model = new CategoryModel() { DisplayName = dialog.DisplayName, RowOrder = this._categoryList.Count, }; model.DisplayName = dialog.DisplayName; model.RowOrder = this._categoryList.Count; model.Id = table.Insert(model); if (model.Id < 0) { AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToInsert, "category")); return; } this._categoryList.Add(model); } }
/// <summary> /// category context menu edit click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CategoryContextMenuEdit_Click(object sender, RoutedEventArgs e) { if (!((this._categoryMenu.Tag as ListViewItem)?.DataContext is CategoryModel model)) { return; } var dialog = new EditCategoryName(this, model); if (true != dialog.ShowDialog()) { return; } using (var table = new CategoriesTable(this._profileDatabase)) { model.DisplayName = dialog.DisplayName; if (0 == table.UpdateById(model)) { AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToUpdate, "category")); return; } } }