public async void AddCardsToCardsTable(string assistedCardId) { Thread.Sleep(100); CardsTable cardTable = new CardsTable(); if (_context.CardsTable.Where(x => x.CardId == assistedCardId).FirstOrDefault() == null) { Cardobject cardItem = await ScryfallDAL.GetApiResponse <Cardobject>("cards", assistedCardId, "https://api.scryfall.com/", ""); if (cardItem.image_uris != null) { cardTable.CardArtUrl = cardItem.image_uris.normal; } else { cardTable.CardArtUrl = "https://img4.wikia.nocookie.net/__cb20140414012548/villains/images/8/86/Dennis_Nedry.png"; } cardTable.CardId = cardItem.id; cardTable.Cmc = cardItem.cmc; cardTable.ManaCost = cardItem.mana_cost; cardTable.Name = cardItem.name; cardTable.OracleText = cardItem.oracle_text; cardTable.TypeLine = cardItem.type_line; cardTable.EdhrecRank = cardItem.edhrec_rank; if (cardItem.prices.usd == null) { cardItem.prices.usd = "0.00"; } cardTable.CardPrice = decimal.Parse(cardItem.prices.usd); if (cardItem.color_identity.Contains("B")) { cardTable.Black = "B"; } if (cardItem.color_identity.Contains("U")) { cardTable.Blue = "U"; } if (cardItem.color_identity.Contains("W")) { cardTable.White = "W"; } if (cardItem.color_identity.Contains("G")) { cardTable.Green = "G"; } if (cardItem.color_identity.Contains("R")) { cardTable.Red = "R"; } _context.CardsTable.Add(cardTable); _context.SaveChanges(); } }
public async Task <IActionResult> AddCard(CardsTable cId, DecksTable dName) { var userId = FindUserId(); string id = cId.CardId; if (_context.CardsTable.Where(x => x.CardId == id).FirstOrDefault() == null) { Cardobject cardItem = await ScryfallDAL.GetApiResponse <Cardobject>("cards", id, "https://api.scryfall.com/", "" + RemoveDuplicatesFromEndpoint(dName.DeckName)); cId.CardArtUrl = cardItem.image_uris.normal; cId.CardId = cardItem.id; cId.Cmc = cardItem.cmc; cId.ManaCost = cardItem.mana_cost; cId.Name = cardItem.name; cId.OracleText = cardItem.oracle_text; cId.TypeLine = cardItem.type_line; cId.EdhrecRank = cardItem.edhrec_rank; if (cardItem.prices.usd == null) { cardItem.prices.usd = "0.00"; } cId.CardPrice = decimal.Parse(cardItem.prices.usd); if (cardItem.color_identity.Contains("B")) { cId.Black = "B"; } if (cardItem.color_identity.Contains("U")) { cId.Blue = "U"; } if (cardItem.color_identity.Contains("W")) { cId.White = "W"; } if (cardItem.color_identity.Contains("G")) { cId.Green = "G"; } if (cardItem.color_identity.Contains("R")) { cId.Red = "R"; } _context.CardsTable.Add(cId); _context.SaveChanges(); } //if the card the user is adding exists in the decks table, return to deckview with an error //otherwise, add the card //find ID of the card in the cards table var idCollection = (from x in _context.CardsTable where id == x.CardId select x.Id).FirstOrDefault(); //find if the card exists in the decks table for this user and this deck var cardExists = (from d in _context.DecksTable where idCollection == d.CardId && FindUserId() == d.AspUserId && dName.DeckName == d.DeckName select d).FirstOrDefault(); //if the linq statement returns null, the card doesn't exist and needs to be added. if (cardExists == null || cardExists.CardId == 5633 || cardExists.CardId == 5634 || cardExists.CardId == 5635 || cardExists.CardId == 5636 || cardExists.CardId == 5637) { if (cId.ManaCost != null) { string colorId = FindColorId(cId); dName.ColorIdentity = colorId; } else { dName.ColorIdentity = "L"; } dName.CardId = idCollection; dName.Quantity = 1; if (userId != null) { dName.AspUserId = userId; } _context.DecksTable.Add(dName); _context.SaveChanges(); return(RedirectToAction("DeckList", dName)); } //else redirect to the decklist else { dName.errorMessage = "The card you've added already exists in your deck!"; return(RedirectToAction("DeckList", dName)); } }
public async Task <IActionResult> CardManaCost(string manaCost) { Cardobject cardItem = await ScryfallDAL.GetApiResponse <Cardobject>("cards", "order?cmc=", "https://api.scryfall.com/", manaCost); return(View(cardItem)); }
public async Task <IActionResult> CardColorList(string cardColor) { Cardobject cardItem = await ScryfallDAL.GetApiResponse <Cardobject>("cards", "search?order=", "https://api.scryfall.com/", cardColor); return(View(cardItem)); }