public async void AddCardsToDecksTable(string assistedCardId, int quantity) { Thread.Sleep(400); // DecksTable lastEntry = (from x in _context.DecksTable where assistedCardId == x.CardId select x.Id).FirstOrDefault(); AssistedDeckViewModel assistedDeck = new AssistedDeckViewModel(); var deckStatus = HttpContext.Session.GetString("AssistedDeck") ?? "EmptySession"; if (deckStatus != "EmptySession") { assistedDeck = System.Text.Json.JsonSerializer.Deserialize <AssistedDeckViewModel>(deckStatus); } for (int i = 0; i < quantity; i++) { DecksTable deckTable = new DecksTable(); var userId = FindUserId(); var idCollection = (from x in _context.CardsTable where assistedCardId == x.CardId select x.Id).FirstOrDefault(); deckTable.CardId = idCollection; deckTable.AspUserId = userId; deckTable.DeckName = assistedDeck.DeckName; deckTable.Quantity = 1; if (quantity > 1) { deckTable.ColorIdentity = "L"; } _context.DecksTable.Add(deckTable); _context.SaveChanges(); } ; }
public async Task <IActionResult> AdvanceCreatureManaCurve() { ScryfallDAL dl = new ScryfallDAL(); string identity = FindPlayerType(); AssistedDeckViewModel assistedDeck = OpenSession(); string assistedDeckJSON = ""; assistedDeck.CurvePosition++; //Checks if all points on the mana curve have been filled out. Once they have, creatures portion of deck //being true should now be true, so f converted t at position 5, and information is returned to index. this will //update the button status from red to green and indicate that this portion is taken care of. if (assistedDeck.CurvePosition >= assistedDeck.CurveData.Count()) { assistedDeck.DeckStatus = assistedDeck.DeckStatus.Substring(0, 4) + "t"; assistedDeckJSON = System.Text.Json.JsonSerializer.Serialize(assistedDeck); HttpContext.Session.SetString("AssistedDeck", assistedDeckJSON); return(View("Index", assistedDeck)); } ; assistedDeck.ErrorMessage = $"You need to select exactly {assistedDeck.CurveData[assistedDeck.CurvePosition]} creatures of this mana level."; assistedDeck.CardSearch = await dl.GetSearch($"id:{identity.ToLower()}+t:\"Creature\"+cmc={assistedDeck.CurvePosition+2}{RemoveDuplicatesFromEndpoint(assistedDeck.DeckName)}", FindPlayerBudget()); assistedDeck.Creatures = assistedDeck.CurveData[assistedDeck.CurvePosition]; assistedDeckJSON = System.Text.Json.JsonSerializer.Serialize(assistedDeck); HttpContext.Session.SetString("AssistedDeck", assistedDeckJSON); return(View("FindCreatures", assistedDeck)); }
public async Task <IActionResult> AddCreaturesIfValid() { var SelectedCard = new List <string>(); using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { var x = await reader.ReadToEndAsync(); SelectedCard = JsonConvert.DeserializeObject <List <string> >(x); } AssistedDeckViewModel assistedDeck = OpenSession(); int creatureCount = assistedDeck.CurveData[assistedDeck.CurvePosition]; if (SelectedCard.Count() != creatureCount) { return(Json(false)); } else { foreach (string card in SelectedCard) { await Task.Run(() => AddCardsToCardsTable(card)); await Task.Run(() => AddCardsToDecksTable(card, 1)); } return(Json(true)); } }
public async Task <IActionResult> StartCreatures() { //This List displays how many creatures should be chosen at each mana value along a mana curve. List <int> cardCurveData = new List <int>() { 5, 8, 7, 5, 4, 2 }; //Opens session, stores card curve data, then re-serializes as assistedDeckJSON. This assisted deck is then passed to the view AssistedDeckViewModel assistedDeck = OpenSession(); assistedDeck.CurveData = cardCurveData; assistedDeck.ErrorMessage = $"You need to select exactly {assistedDeck.CurveData[assistedDeck.CurvePosition]} creatures of this mana level."; //Reserialize the session, so that the information can be saved. string assistedDeckJSON = System.Text.Json.JsonSerializer.Serialize(assistedDeck); HttpContext.Session.SetString("AssistedDeck", assistedDeckJSON); //Taps into the DAL inorder to connect to scryfall endpoints for returning creatures that cost 2 mana ScryfallDAL dl = new ScryfallDAL(); string identity = FindPlayerType(); assistedDeck.CardSearch = await dl.GetSearch($"id:{identity.ToLower()}+t:\"Creature\"+cmc={assistedDeck.CurvePosition+2}{RemoveDuplicatesFromEndpoint(assistedDeck.DeckName)}", FindPlayerBudget()); return(View("FindCreatures", assistedDeck)); }
//This method validates the card amount, then adds them to the deck/cards table before returning to //index. public async Task <IActionResult> ValidateSelectedCards(int menu) { AssistedDeckViewModel assistedDeck = OpenSession(); var ids = new List <string>(); using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { var x = await reader.ReadToEndAsync(); ids = JsonConvert.DeserializeObject <List <string> >(x); } if (menu == 0) { if (ids.Count() != 10) { return(Json(false)); } assistedDeck.DeckStatus = "t" + assistedDeck.DeckStatus.Substring(1); } else if (menu == 1) { if (ids.Count() != 10) { return(Json(false)); } assistedDeck.DeckStatus = assistedDeck.DeckStatus.Substring(0, 1) + "t" + assistedDeck.DeckStatus.Substring(2); } else if (menu == 2) { if (ids.Count() != 5) { return(Json(false)); } assistedDeck.DeckStatus = assistedDeck.DeckStatus.Substring(0, 2) + "t" + assistedDeck.DeckStatus.Substring(3); } else if (menu == 3) { if (ids.Count() != 5) { return(Json(false)); } assistedDeck.DeckStatus = assistedDeck.DeckStatus.Substring(0, 3) + "t" + assistedDeck.DeckStatus.Substring(4); } foreach (string card in ids) { await Task.Run(() => AddCardsToCardsTable(card)); await Task.Run(() => AddCardsToDecksTable(card, 1)); } string assistedDeckJSON = System.Text.Json.JsonSerializer.Serialize(assistedDeck); HttpContext.Session.SetString("AssistedDeck", assistedDeckJSON); return(Json(true)); }
public AssistedDeckViewModel OpenSession() { AssistedDeckViewModel assistedDeck = new AssistedDeckViewModel(); var deckStatus = HttpContext.Session.GetString("AssistedDeck") ?? "EmptySession"; if (deckStatus != "EmptySession") { assistedDeck = System.Text.Json.JsonSerializer.Deserialize <AssistedDeckViewModel>(deckStatus); } return(assistedDeck); }
public async Task <IActionResult> FindDraw(AssistedDeckViewModel assistedDeck) { AssistedDeckViewModel session = OpenSession(); string identity = FindPlayerType(); ScryfallDAL dl = new ScryfallDAL(); assistedDeck.CardSearch = await dl.GetSearch($"id:{identity.ToLower()}+o:draw{RemoveDuplicatesFromEndpoint(session.DeckName)}", FindPlayerBudget()); assistedDeck.ErrorMessage = "You need to select exactly 10 card draw sources."; return(View(assistedDeck)); }
public async Task <IActionResult> FindSingleRemoval(AssistedDeckViewModel assistedDeck) { AssistedDeckViewModel session = OpenSession(); ScryfallDAL dl = new ScryfallDAL(); string identity = FindPlayerType(); assistedDeck.CardSearch = await dl.GetSearch($"id:{identity.ToLower()}+o:\"destroy\"+t:\"instant\"ort:\"sorcery\"{RemoveDuplicatesFromEndpoint(session.DeckName)}", FindPlayerBudget()); assistedDeck.ErrorMessage = "You need to select exactly 5 single target removal."; return(View(assistedDeck)); }
public async Task <IActionResult> FindRamp(AssistedDeckViewModel assistedDeck) { AssistedDeckViewModel session = OpenSession(); string identity = FindPlayerType(); ScryfallDAL dl = new ScryfallDAL(); assistedDeck.CardSearch = await dl.GetSearch($"id:{identity.ToLower()}+produces<={FindPlayerType()}c+-t:\"Land\"{RemoveDuplicatesFromEndpoint(session.DeckName)}", FindPlayerBudget()); assistedDeck.ErrorMessage = "You need to select exactly 10 sources of ramp."; //ramp goes to draw from the view return(View(assistedDeck)); }
public async void CreateDeckName(int commanderId, string colorId) { Thread.Sleep(100); AssistedDeckViewModel assistedDeck = new AssistedDeckViewModel(); var deckStatus = HttpContext.Session.GetString("AssistedDeck") ?? "EmptySession"; if (deckStatus != "EmptySession") { assistedDeck = System.Text.Json.JsonSerializer.Deserialize <AssistedDeckViewModel>(deckStatus); } string assistedDeckName = ""; DecksTable deckTable = new DecksTable(); string userName = FindUserId(); int deckNumber = (from n in _context.DecksTable where n.AspUserId == userName select n.DeckName).Count(); assistedDeckName = ($"assistedDeck_{deckNumber + 1}"); assistedDeck.DeckName = assistedDeckName; assistedDeck.DeckStatus = "fffff"; assistedDeck.Creatures = 5; string assistedDeckJSON = System.Text.Json.JsonSerializer.Serialize(assistedDeck); HttpContext.Session.SetString("AssistedDeck", assistedDeckJSON); deckTable.DeckName = assistedDeckName; deckTable.CardId = commanderId; deckTable.AspUserId = userName; deckTable.Quantity = 1; deckTable.ColorIdentity = colorId; _context.DecksTable.Add(deckTable); _context.SaveChanges(); }
public async Task <IActionResult> SaveChanges() { var ids = new List <string>(); using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { var x = await reader.ReadToEndAsync(); ids = JsonConvert.DeserializeObject <List <string> >(x); } AssistedDeckViewModel assistedDeck = new AssistedDeckViewModel(); var deckStatus = HttpContext.Session.GetString("AssistedDeck") ?? "EmptySession"; if (deckStatus != "EmptySession") { assistedDeck = System.Text.Json.JsonSerializer.Deserialize <AssistedDeckViewModel>(deckStatus); } return(Json(false)); }
public async Task <IActionResult> UpdateBudget(string budget) { decimal budgetParse = 0; try { budgetParse = decimal.Parse(budget); } catch { return(View("Budget", "Please enter a valid dollar amount.")); } AspNetUsers user = _context.AspNetUsers.Find(FindUserId()); user.Budget = decimal.Parse(budget); _context.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(user); _context.SaveChanges(); AssistedDeckViewModel assistedDeck = OpenSession(); return(View("Index", assistedDeck)); }
public IActionResult DeckList() { AssistedDeckViewModel assistedDeck = new AssistedDeckViewModel(); var deckStatus = HttpContext.Session.GetString("AssistedDeck") ?? "EmptySession"; if (deckStatus != "EmptySession") { assistedDeck = System.Text.Json.JsonSerializer.Deserialize <AssistedDeckViewModel>(deckStatus); } CardsTable cd = new CardsTable(); string id = FindUserId(); List <DecksTable> deckList = (from d in _context.DecksTable where d.AspUserId == id && d.DeckName == assistedDeck.DeckName select d).ToList(); List <CardsTable> cardlist = new List <CardsTable>(); CombinedDeckViewModel combo = new CombinedDeckViewModel(); for (int i = 0; i < deckList.Count; i++) { cardlist.Add(_context.CardsTable.Find(deckList[i].CardId)); } float cmc = 0; decimal?cost = 0; foreach (CardsTable card in cardlist) { cmc += card.Cmc; cost += card.CardPrice; if (card.TypeLine.Contains("Creature")) { combo.creatureCount += 1; } if (card.TypeLine.Contains("Instant")) { combo.instantCount += 1; } if (card.TypeLine.Contains("Sorcery")) { combo.sorceryCount += 1; } if (card.TypeLine.Contains("Artifact") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Enchantment")) { combo.artifactCount += 1; } if (card.TypeLine.Contains("Enchantment") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Artifact")) { combo.enchantmentCount += 1; } if (card.TypeLine.Contains("Land") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Artifact") && !card.TypeLine.Contains("Enchantment")) { combo.landCount += 1; } } combo.DeckCost = cost?.ToString("C2"); combo.Search = cardlist; combo.deckObject = deckList; return(View(combo)); }
public IActionResult Index() { AssistedDeckViewModel assistedDeck = OpenSession(); return(View(assistedDeck)); }