public ActionResult CardDetails(string cardName, string setCode) { var requestEngine = new ScryfallRequestEngine(); var card = requestEngine.FirstCardFromSearch(cardName, setCode); return(card != null?View("CardDetails", card) : View("~/Views/Shared/CardNotFound.cshtml", null, cardName)); }
public ActionResult ViewCollection(int id) { var collection = ApplicationUserEngine.GetCollection(id, out var error); var scryfallRequestEngine = new ScryfallRequestEngine(); var tcgPlayerRequestEngine = new TcgPlayerRequestEngine(); var displayName = ApplicationUserEngine.GetApplicationUser(collection.ApplicationUserId).DisplayName; var ownerDisplayName = $"{displayName}#{collection.ApplicationUserId}"; if (User.Identity.IsAuthenticated) { var email = ((ClaimsIdentity)User.Identity).Claims.First(i => i.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value; var user = ApplicationUserEngine.GetApplicationUser(email); ViewBag.IsOwner = user.Collections.Any(i => i.CollectionId == collection.CollectionId); } else { ViewBag.IsOwner = false; } // TODO: Up the view count and add it to an audit log for tracking so the system can't be cheated // TODO: create an audit log, lol if (!string.IsNullOrEmpty(error)) { TempData["AlertMsg"] = "<br /><div class=\"alert alert-danger alert-dismissible\">" + "<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>" + $"<strong>{error}</div>"; return(View("Error")); } var prices = new List <double>(); var pricingRequest = tcgPlayerRequestEngine.CardListPriceRequest(collection); // Get card data and prices foreach (var collectionCard in collection.Cards) { var price = pricingRequest.FirstOrDefault(i => i.ProductId == tcgPlayerRequestEngine.ProductIdRequest(collectionCard.Name, collectionCard.SetName) && i.SubTypeName == (collectionCard.Foil ? "Foil" : "Normal")); //var price = tcgPlayerRequestEngine.CardPriceRequest(scryfallList[index]?.Name, scryfallList[index]?.SetName)?.First(i => // collectionCard.Foil ? i.SubTypeName == "Foil" : i.SubTypeName == "Normal"); prices.Add(price?.MidPrice ?? 0); } var model = new ViewCollectionModel { Collection = collection, ScryfallList = scryfallRequestEngine.GetCardList(collection), Prices = prices, OwnerDisplayName = ownerDisplayName, OwnerId = collection.ApplicationUserId }; return(View("Collection", model)); }
public static bool VerifyCardList(List <CollectionCard> list, out List <CollectionCard> verifiedList, out string error) { var requestEngine = new ScryfallRequestEngine(); error = ""; var errorLine = 0; verifiedList = new List <CollectionCard>(); foreach (var card in list) { errorLine++; if (requestEngine.GetCard(card.Name, card.SetCode) == null) { error = $"Error processing the Card named {card.Name}" + (!string.IsNullOrEmpty(card.SetCode) ? $" with Set Code {card.SetCode}." : "."); error += $" (Line {errorLine})"; return(false); } card.Name = requestEngine.GetCard(card.Name, card.SetCode).Name; } if (list.Count(i => i.Commander) > 1) { var commanders = list.Where(i => i.Commander).ToList(); foreach (var commander in commanders) { var card = requestEngine.GetCard(commander.Name, commander.SetCode); if (!card.TypeLine.Contains("Legendary") && !card.TypeLine.Contains("Creature") || !card.OracleText.Contains("can be your commander")) { error = "Your Commander has to be a Legendary Creature or a card with \"can be your commander\" in its rules text."; return(false); } } if (!commanders.All(i => i.Name.Contains("Kenrith"))) { foreach (var commander in commanders) { var card = requestEngine.GetCard(commander.Name); if (!card.OracleText.Contains("Partner") && !card.OracleText.Contains("Partner with")) { error = "You can't have more than one commander in your list."; return(false); } } } } verifiedList = list; return(true); }
public ActionResult Results(string cardName) { cardName = cardName.Trim(); if (cardName.Length <= 2) { return(RedirectToAction("Index", "Home")); } var requestEngine = new ScryfallRequestEngine(); var results = requestEngine.CardSearchRequest(cardName); if (results.TotalCards == 1) { return(RedirectToAction("CardDetails", "Search", new { cardName = results.Data[0].Name })); } return(View("Results", new SearchResultsViewMovel { NameSearch = cardName, Results = results })); }
public static void Init() { cache = new MemoryCache("main_cache"); scryfallRequestEngine = new ScryfallRequestEngine(); }
public ActionResult Spoilers(string setCode, int?sortId) { var scryfallRequestEngine = new ScryfallRequestEngine(); if (string.IsNullOrEmpty(setCode)) { setCode = scryfallRequestEngine.LatestSet().Code; } List <Card> cards; if (sortId != null) { // TODO: We don't really need a new request every time they change sort order... switch (sortId) { // default sort order, by collector number default: cards = scryfallRequestEngine.CardSetListRequest(setCode).Data .OrderBy(i => Convert.ToInt32(i.CollectorNumber.GetNumber())) .ToList(); break; // sort by rarity then by collector number case 1: cards = scryfallRequestEngine.CardSetListRequest(setCode).Data .OrderBy(i => Array.IndexOf(SpoilersViewModel.RarityOrder, i.Rarity)) .ThenBy(i => Convert.ToInt32(i.CollectorNumber.GetNumber())) .ToList(); break; // sort by name; no need to sort by collector number in this case case 2: cards = scryfallRequestEngine.CardSetListRequest(setCode).Data .OrderBy(i => i.Name.Replace("\"", string.Empty)) .ToList(); break; // sort by cmc then by collector number case 3: cards = scryfallRequestEngine.CardSetListRequest(setCode).Data .OrderBy(i => i.Cmc) .ThenBy(i => Convert.ToInt32(i.CollectorNumber.GetNumber())) .ToList(); break; } } else { cards = scryfallRequestEngine.CardSetListRequest(setCode).Data .OrderBy(i => Convert.ToInt32(i.CollectorNumber.GetNumber())) .ToList(); } var model = new SpoilersViewModel { Set = scryfallRequestEngine.SetRequest(setCode), Sets = scryfallRequestEngine.SetsRequest(), Cards = cards }; return(View(model)); }