public IActionResult QuizResult(QuizViewModel result)
        {
            List <int> colorInteger             = new List <int>();
            Dictionary <string, int> colorScore = new Dictionary <string, int>();
            List <string>            colors     = new List <string>();
            QuizResultViewModel      quizResult = new QuizResultViewModel();

            string[] desserializeResult = result.ColorScore.Split('|');
            foreach (string color in desserializeResult)
            {
                colorScore.Add(color.Substring(0, 1), int.Parse(color.Substring(1)));
            }

            var sortedDict = from entry in colorScore orderby entry.Value descending select entry;


            quizResult.PrimaryColor = colorScore.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;



            quizResult.SecondaryColor = sortedDict.Skip(1).Aggregate((x, y) => x.Value > y.Value ? x : y).Key;

            if (quizResult.PrimaryColor == quizResult.SecondaryColor)
            {
                quizResult.PrimaryColor = sortedDict.OrderByDescending(i => i.Value).FirstOrDefault().Key;
            }

            quizResult.ColorScore = colorScore;
            AspNetUsers user = _context.AspNetUsers.Find(FindUserId());

            user.Playertype            = quizResult.PrimaryColor + quizResult.SecondaryColor;
            _context.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.Update(user);
            _context.SaveChanges();

            return(View(quizResult));
        }
        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 void AddCardsToDecksTable(string CardId)
        {
            DecksTable lastEntry = _context.DecksTable.OrderByDescending(i => i.Id).FirstOrDefault();
            DecksTable deckTable = new DecksTable();

            var userId       = FindUserId();
            var idCollection = (from x in _context.CardsTable where CardId == x.CardId select x.Id).FirstOrDefault();

            deckTable.CardId    = idCollection;
            deckTable.AspUserId = userId;
            deckTable.DeckName  = lastEntry.DeckName;
            //deckTable.Quantity = quantity;

            _context.DecksTable.Add(deckTable);
            _context.SaveChanges();
        }
Exemple #4
0
        public async Task <IActionResult> CardList(string cardName, DecksTable dName)
        {
            CardsTable            cardTable = new CardsTable();
            ScryfallDAL           dl        = new ScryfallDAL();
            List <CardsTable>     cardList  = new List <CardsTable>();
            CombinedDeckViewModel combo     = new CombinedDeckViewModel();

            var cardId = _context.CardsTable.Where(x => x.Name.Contains(cardName)).FirstOrDefault();

            if (cardId == null)
            {
                CardSearchObject cardItem = await dl.GetListOfCards($"{cardName}+{ RemoveDuplicatesFromEndpoint(dName.DeckName)}");

                if (cardItem.data != null)
                {
                    for (int i = 0; i < cardItem.data.Length; i++)
                    {
                        if (cardItem.data[i].image_uris == null)
                        {
                            cardTable.CardArtUrl = "https://img4.wikia.nocookie.net/__cb20140414012548/villains/images/8/86/Dennis_Nedry.png";
                        }
                        else
                        {
                            cardTable.CardArtUrl = cardItem.data[i].image_uris.normal;
                        }
                        cardTable.CardId     = cardItem.data[i].id;
                        cardTable.Cmc        = cardItem.data[i].cmc;
                        cardTable.ManaCost   = cardItem.data[i].mana_cost;
                        cardTable.Name       = cardItem.data[i].name;
                        cardTable.OracleText = cardItem.data[i].oracle_text;
                        cardTable.TypeLine   = cardItem.data[i].type_line;
                        cardTable.EdhrecRank = cardItem.data[i].edhrec_rank;
                        if (cardItem.data[i].prices == null)
                        {
                            cardItem.data[i].prices.usd      = "0.00";
                            cardItem.data[i].prices.eur      = "0.00";
                            cardItem.data[i].prices.usd_foil = "0.00";
                            cardItem.data[i].prices.tix      = "0.00";
                        }
                        else if (cardItem.data[i].prices.usd == null)
                        {
                            cardItem.data[i].prices.usd = "0.00";
                        }
                        cardTable.CardPrice = decimal.Parse(cardItem.data[i].prices.usd);

                        if (cardItem.data[i].color_identity.Contains("B"))
                        {
                            cardTable.Black = "B";
                        }
                        if (cardItem.data[i].color_identity.Contains("U"))
                        {
                            cardTable.Blue = "U";
                        }
                        if (cardItem.data[i].color_identity.Contains("W"))
                        {
                            cardTable.White = "W";
                        }
                        if (cardItem.data[i].color_identity.Contains("G"))
                        {
                            cardTable.Green = "G";
                        }
                        if (cardItem.data[i].color_identity.Contains("R"))
                        {
                            cardTable.Red = "R";
                        }

                        cardTable.Id = 0;

                        _context.CardsTable.Add(cardTable);
                        _context.SaveChanges();
                    }
                }
                else
                {
                    dName.errorMessage = "Unable to find the requested card";
                    return(RedirectToAction("DeckList", dName));
                }
            }

            //now that the card exists in the card table
            //we need to get the card from the cards table and save
            //first to the cardList then to the combo


            List <DecksTable> deckList = new List <DecksTable>();

            combo.Search     = cardList;
            combo.deckObject = deckList;

            cardList = (from c in _context.CardsTable where c.Name.Contains(cardName) select c).ToList();

            deckList.Add(dName);

            for (int i = 0; i < cardList.Count; i++)
            {
                combo.Search.Add(cardList[i]);
            }

            combo.deckObject = deckList;

            return(View(combo));
        }
Exemple #5
0
        public IActionResult UpdateLandCount(int numberOfPlains, int numberOfIslands, int numberOfSwamps, int numberOfMountains, int numberOfForests, int numberOfWastes, string DeckName)
        {
            //this action will update the database with the selected quantity of lands
            List <DecksTable> landData   = (from d in _context.DecksTable where d.AspUserId == FindUserId() && d.DeckName == DeckName && d.ColorIdentity == "L" select d).ToList();
            DecksTable        landsToAdd = new DecksTable();
            DecksTable        deck       = new DecksTable();

            List <int> landCounts = new List <int> {
                numberOfForests, numberOfIslands, numberOfMountains, numberOfPlains, numberOfSwamps, numberOfWastes
            };

            List <DecksTable> deckname       = new List <DecksTable>();
            List <CardsTable> landPrimaryKey = (from c in _context.CardsTable where c.TypeLine.Contains("Basic Land") select c).ToList();

            //Lands are pulled from the API in alphabetical order, therefore the CardsTable list will always pull from the table in alphabetical order
            //By setting up the land add in this manner the add will be immune to database resets.
            for (int i = 0; i < landCounts.Count; i++)
            {
                if (landCounts[i] != 0)
                {
                    for (int j = 0; j < landCounts[i]; j++)
                    {
                        landsToAdd.DeckName      = DeckName;
                        landsToAdd.Quantity      = 1;
                        landsToAdd.ColorIdentity = "L";
                        landsToAdd.CardId        = landPrimaryKey[i].Id;
                        landsToAdd.AspUserId     = FindUserId();

                        _context.DecksTable.Add(landsToAdd);
                        _context.SaveChanges();
                        landsToAdd.Id = 0;
                    }
                }
            }
            ;

            deckname.Add(landsToAdd);
            deck.DeckName = DeckName;

            return(RedirectToAction("DeckList", deck));
        }
Exemple #6
0
        public override Task OnConnected()
        {
            using (var context = new MagicDbContext())
            {
                var userId = Context.User.Identity.GetUserId();
                var foundUser = context.Users.Find(userId);

                var connection = new UserConnection
                {
                    Id = Context.ConnectionId,
                    UserId = userId
                };
                context.Connections.Add(connection);
                context.SaveChanges();

                SubscribeChatRoom(DefaultRoomId);
                if (foundUser.Connections.Count == 1)
                {
                    // If this is the user's only connection broadcast a chat info.
                    UserStatusUpdate(userId, UserStatus.Online, DefaultRoomId);
                }

                UpdateChatRoomUsers(DefaultRoomId);
                foreach (var chatRoom in GetChatRoomsWithUser(userId))
                {
                    UpdateChatRoomUsers(chatRoom.Id);
                }
                
                SubscribeActiveChatRooms(Context.ConnectionId, userId);
                // TODO: What when: user disconnects, other user has private chat tab open, user connects again - chat tab is unsubscribed, typing message does not notify receiving user?
                // Solution: use message notifications for that - partially implemented.
            }

            System.Diagnostics.Debug.WriteLine("Connected: " + Context.ConnectionId);
            return base.OnConnected();
        }
Exemple #7
0
        public void UnsubscribeChatRoom(string roomId)
        {
            using (var context = new MagicDbContext())
            {
                var userId = Context.User.Identity.GetUserId();

                var userConnections = context.ChatRoomConnections.Where(c => c.ChatRoomId == roomId && c.UserId == userId);
                var userConnectionIds = userConnections.Select(c => c.ConnectionId).ToList();
                Clients.Clients(userConnectionIds).closeChatRoom(roomId);

                context.ChatRoomConnections.RemoveRange(userConnections);
                context.SaveChanges();

                Task.WhenAll(userConnectionIds.Select(connectionId => Groups.Remove(connectionId, roomId)).ToArray());
            }
        }