public static void Initialize(MtgCollectionMgrContext context) { context.Database.EnsureCreated(); TcgPriceCrawler priceCrawler = new TcgPriceCrawler(); List <CardPrice> prices = priceCrawler.GetPrices(); if (context.CardModels.Any()) { InitPrices(context, prices); return; } CollectionModel model = new CollectionModel(); context.Add(model); var cards = GetCards(); foreach (CardFromJson cardList in cards) { for (int i = 0; i < cardList.Cards.Count; i++) { CardModel newCard = new CardModel(cardList.Cards[i]); context.Add(newCard); } } context.SaveChanges(); }
private static void InitPrices(MtgCollectionMgrContext context, List <CardPrice> prices) { foreach (CardPrice price in prices) { CardModel myCard = context.CardModels .FirstOrDefault(c => c.Name == price.CardName && c.SetName == price.SetName); if (myCard != null) { myCard.MedianPrice = price.MedianPrice; myCard.MarketPrice = price.MarketPrice; myCard.BuylistMarketPrice = price.BuylistMarketPrice; //context.CardModels.Update(myCard); } } context.SaveChanges(); }
public CollectionModelsController(MtgCollectionMgrContext context) { _context = context; }