public static void InsertCard(CardApiDm cardApi, string setId) { using (var db = new MtgEntities()) { try { cardApi.Editions = cardApi.Editions.Where(e => e.Set_Id == setId).ToList(); var em = CardMapper.Map(cardApi); if (db.Cards.Any(c => c.CardId == em.CardId)) { foreach (var cardSet in em.CardSets.Where(s => !db.CardSets.Any(dbSet => dbSet.CardId == s.CardId && dbSet.SetId == s.SetId))) { db.CardSets.Add(cardSet); } } else { db.Cards.Add(em); } db.SaveChanges(); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Unable to save the card '{cardApi.Name}' Excpetion:"); Console.WriteLine(e); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; } } }
public static void InsertCardTag(string tag, string card) { using (var db = new MtgEntities()) { try { var emTag = db.Tags.Single(t => t.TagName == tag); var emCard = db.Cards.Single(c => c.CardName == card); var emCardTag = new CardTag { CardId = emCard.CardId, TagId = emTag.TagId }; db.CardTags.Add(emCardTag); db.SaveChanges(); } catch (Exception e) { Console.WriteLine(); Console.WriteLine($"Unable to save the tag {tag} to the card {card}."); Console.WriteLine(e); } } }
private static void DeleteCard(DeckDm deck, CardDm card) { using (var db = new MtgEntities()) { var deckCard = db.DeckCards.Single(dc => dc.DeckId == deck.Id && dc.CardId == card.Id); db.DeckCards.Remove(deckCard); db.SaveChanges(); } }
public static void InsertDeck(DeckDm deck) { var newDeck = DeckMapper.Map(deck); using (var db = new MtgEntities()) { db.Decks.Add(newDeck); db.SaveChanges(); } }
public static void Delete(string deckName) { using (var db = new MtgEntities()) { var deck = db.Decks.Single(dc => dc.DeckName == deckName); var sql = $"Delete DeckCards Where DeckId = {deck.DeckId}"; db.Database.ExecuteSqlCommand(sql); db.Decks.Remove(deck); db.SaveChanges(); } }
private static void InsertCard(string deckName, CardDm card) { var deck = GetDeck(deckName); var deckCard = new DeckCard { DeckCardsId = 0, DeckId = deck.Id, CardId = card.Id }; using (var db = new MtgEntities()) { db.DeckCards.Add(deckCard); db.SaveChanges(); } }
public static void InsertTag(string tagName) { using (var db = new MtgEntities()) { try { var em = new Tag { TagName = tagName }; db.Tags.Add(em); db.SaveChanges(); } catch (Exception e) { Console.WriteLine(); Console.WriteLine($"Unable to save the setApi '{tagName}' Excpetion:"); Console.WriteLine(e); } } }