public static void CollectionViewFormCardsUpdated(object sender, CardsUpdatedEventArgs e)
 {
     if (e.CollectionViewForm != null)
     {
         CardManager.UpdateCards(e);
     }
 }
        public static void UpdateCards(CardsUpdatedEventArgs e)
        {
            var setItems = new Dictionary <string, OLVSetItem>();

            using (MyDbContext context = new MyDbContext())
            {
                try
                {
                    UpdateCardsInDB(context, e.Items);
                    var inventoryCardsToRemove  = new List <FullInventoryCard>();
                    var magicCardsCopiesUpdated = new List <MagicCard>();
                    foreach (FullInventoryCard card in e.Items)
                    {
                        if (!setItems.TryGetValue(card.Edition, out OLVSetItem setItem)) // get updated set item
                        {
                            if ((setItem = Globals.Forms.DBViewForm.SetItems.FirstOrDefault(x => x.Name == card.Edition)) != null)
                            {
                                setItems.Add(card.Edition, setItem);
                            }
                        }

                        var magicCard = UpdateCopiesOwned(context, card);
                        if (magicCard != null)
                        {
                            magicCardsCopiesUpdated.Add(magicCard);
                        }
                        if (card.Count < 1)
                        {
                            inventoryCardsToRemove.Add(card);
                        }
                    }
                    if (inventoryCardsToRemove.Count > 0)
                    {
                        e.CollectionViewForm.RemoveFullInventoryCards(inventoryCardsToRemove);
                    }
                    else
                    {
                        e.CollectionViewForm.UpdateTotals();
                    }
                    Globals.Forms.DBViewForm.cardListView.RefreshObjects(magicCardsCopiesUpdated);
                    Globals.Forms.DBViewForm.setListView.RefreshObjects(setItems.Values.ToArray());
                }
                catch (Exception ex)
                {
                    DebugOutput.WriteLine(ex.ToString());
                    foreach (var item in e.Items)
                    {
                        if (item is FullInventoryCard card)
                        {
                            context.Entry(card).Reload();
                        }
                    }

                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    e.CollectionViewForm.cardListView.Refresh();
                }
            }
        }