示例#1
0
 /// <summary>
 /// Deletes a category on delete keypress
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void categoryDatagrid_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Delete)
     {
         try
         {
             Category         category         = (Category)categoryDatagrid.SelectedItem;
             var              selectedRow      = categoryDatagrid.SelectedIndex;
             MessageBoxResult messageboxResult = MessageBox.Show($"Are you sure you want to delete: {category.name}?", "Are you sure?", MessageBoxButton.YesNo);
             if (messageboxResult == MessageBoxResult.Yes)
             {
                 categoryList.RemoveAt(selectedRow);
                 categoryClient.DeleteCategory(category.id);
             }
             else
             {
                 RefreshDataGrid();
             }
         }
         catch (InvalidCastException invalidCast)
         {
             MessageBox.Show(invalidCast.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             throw;
         }
     }
 }
 public ActionResult Delete(int?id)
 {
     categoryObj.DeleteCategory(id);
     return(RedirectToAction("Index"));
 }