コード例 #1
0
        public static void MoveFullInventoryCardsToCollection(ArrayList fullInventoryCards, CollectionViewForm sourceCVForm, CardCollection collection)
        {
            var cardsList = new List <FullInventoryCard>();

            try
            {
                using (var context = new MyDbContext())
                {
                    foreach (FullInventoryCard fullInventoryCard in fullInventoryCards)
                    {
                        fullInventoryCard.CollectionId = collection.Id;
                        if (fullInventoryCard.Virtual != collection.Virtual)
                        {
                            fullInventoryCard.TimeAdded = DateTime.Now;
                        }
                        fullInventoryCard.Virtual = collection.Virtual;
                        context.Update(fullInventoryCard.InventoryCard);
                        cardsList.Add(fullInventoryCard);
                    }
                    context.SaveChanges();
                }
                sourceCVForm.RemoveFullInventoryCards(cardsList);
                Globals.Forms.OpenCollectionForms.FirstOrDefault(x => x.Collection.Id == collection.Id)?.AddFullInventoryCards(cardsList);
            }
            catch (Exception ex)
            {
                DebugOutput.WriteLine(ex.ToString());
                MessageBox.Show("Could not move cards to collection.");
            }
        }