public static InventoryCard AddMagicCardToCollection(MyDbContext context, MagicCard magicCard, CardCollection collection, int insertionIndex = 0)
        {
            var inventoryCard = new InventoryCard
            {
                DisplayName      = magicCard.DisplayName,
                uuid             = magicCard.uuid,
                multiverseId_Inv = magicCard.multiverseId,
                CollectionId     = collection.Id,
                InsertionIndex   = insertionIndex,
                Virtual          = collection.Virtual
            };

            if (magicCard.isFoilOnly)
            {
                inventoryCard.Foil = true;
            }
            else
            {
                inventoryCard.Foil = false;
            }
            if (magicCard.PartB != null)
            {
                inventoryCard.PartB_uuid = magicCard.PartB.uuid;
            }
            context.Library.Add(inventoryCard);
            return(inventoryCard);
        }
        private static MagicCard UpdateCopiesOwned(MyDbContext context, FullInventoryCard card)
        {
            MagicCard magicCard    = null;
            var       allCopiesSum = context.LibraryView.Where(x => x.uuid == card.uuid && !x.Virtual).Sum(x => x.Count);

            if (allCopiesSum.HasValue && Globals.Collections.MagicCardCache.TryGetValue(card.uuid, out magicCard))
            {
                magicCard.CopiesOwned = allCopiesSum.Value;
            }

            return(magicCard);
        }
        public static void Upsert(this MyDbContext context, MagicCard card)
        {
            if (card.originalText == null)
            {
                card.originalText = "";
            }
            var existing = context.Catalog.AsNoTracking().FirstOrDefault(x => x.uuid == card.uuid);

            if (existing == null) // new card
            {
                context.Add(card);
            }
            else // update existing card
            {
                // don't overwrite existing prices
                card.tcgplayerMarketPrice = existing.tcgplayerMarketPrice;
                card.tcgplayerLowPrice    = existing.tcgplayerLowPrice;
                card.tcgplayerMidPrice    = existing.tcgplayerMidPrice;
                card.tcgplayerHighPrice   = existing.tcgplayerHighPrice;
                context.Update(card);
            }
        }