/// <summary>
 /// Overloaded constructor to evaluate the score of the game based on user preference.
 /// </summary>
 /// <param name="g">The game to calulate the user's preference for at</param>
 /// <param name="db">The database context</param>
 /// <param name="user">The current user</param>
 public GameDTO(Game g, WgsipContext db, ClaimsPrincipal user)
 {
     GameName      = g.GameName;
     DatePublished = g.DatePublished;
     Genre         = g.Genre.GenreName;
     Publisher     = g.Publisher.PublisherName;
     EsrbRating    = g.EsrbRating;
     Platforms     = g.Platforms;
     Score         = getScoreFromFormula(g, db, user);
 }
        /// <summary>
        /// Get the score for the game based on our formula for scoring games based on
        /// what the user likes.
        /// </summary>
        /// <param name="game">The game to calulate the user's preference for at</param>
        /// <param name="db">The database context</param>
        /// <param name="user">The current user</param>
        /// <returns>The score calulated by the formula</returns>
        public int getScoreFromFormula(Game game, WgsipContext db, ClaimsPrincipal user)
        {
            int tagsWeight      = 0;
            int genreWeight     = 0;
            int publisherWeight = 0;


            //get gameid
            int gameId = game.GameId;
            //get publisherid
            int publisherId = game.Publisher.PublisherId;
            //get genreid
            int genreId = game.Genre.GenreId;

            try
            {
                PublisherWeights pW = db.PublisherWeights.Include(pw => pw.User)
                                      .Include(pw => pw.Publisher)
                                      .First(pw => pw.Publisher.PublisherId == publisherId &&
                                             pw.User.AccountEmail.ToLower().Equals(user.Identity.Name.ToLower())
                                             );
                publisherWeight += pW.Weight;
            }
            catch (Exception)
            {
                publisherWeight = 0;
            }


            try
            {
                GenreWeights gW = db.GenreWeights.Include(pw => pw.User)
                                  .Include(gw => gw.Genre)
                                  .First(gw => gw.Genre.GenreId == genreId &&
                                         gw.User.AccountEmail.ToLower().Equals(user.Identity.Name.ToLower())
                                         ) ?? null;
                genreWeight += gW.Weight;
            }
            catch (Exception)
            {
                genreWeight = 0;
            }

            // create list of tags assosiated with this game
            List <GameTag> tagsForGame = db.GameTags.Include(g => g.Game).Include(g => g.Tag)
                                         .Where(g => g.Game.GameId == gameId).ToList();

            foreach (GameTag tag in tagsForGame)
            {
                //get the tagid
                int tagid = tag.Tag.TagId;

                //adjust weight for each tag
                try
                {
                    tagsWeight += db.TagWeights.Include(pg => pg.User).Include(pg => pg.Tag)
                                  .First(pg =>
                                         pg.Tag.TagId == tagid &&
                                         pg.User.AccountEmail.ToLower().Equals(user.Identity.Name.ToLower())
                                         ).Weight;
                }
                catch (Exception)
                {
                    continue;
                }
            }

            return(tagsWeight + genreWeight + publisherWeight);
        }