예제 #1
0
 public ArtistViewModel(GameArtist artist)
 {
     Artist = artist;
     SetStarProperties(artist);
     SetPromotionText(artist);
     BonusClass = IconCss.BonusClass[artist.DiscoverBonus];
 }
예제 #2
0
        private void SetStarProperties(GameArtist artist)
        {
            int index = GetIndexOfCurrentStarLevel(artist);

            CurrentStar    = StarClass[index];
            NextStar       = StarClass[index + 1];
            FameAtNextStar = artist.StarLevels[index];
        }
예제 #3
0
        private void SetPromotionText(GameArtist artist)
        {
            var text = "-";

            if (artist.Promotion > 0)
            {
                text = artist.Promotion.ToString();
            }
            PromotionText = text;
        }
예제 #4
0
        private int GetIndexOfCurrentStarLevel(GameArtist artist)
        {
            int i = 0;

            while (artist.StarLevels[i] < artist.Fame)
            {
                i++;
            }
            return(i);
        }
예제 #5
0
        private void Insert(List <Item> itemList)
        {
            foreach (Item item in itemList)
            {
                int highestVotes     = -1;
                int suggestedPlayers = 0;
                foreach (Results results in item.Poll.Where(poll => poll.Name.Contains("suggested_numplayers")).ToList().First().Results)
                {
                    foreach (Result result in results.Result)
                    {
                        if (result.Value.Contains("Best") && int.Parse(result.Numvotes) > highestVotes)
                        {
                            highestVotes     = int.Parse(result.Numvotes);
                            suggestedPlayers = int.Parse(results.Numplayers);
                        }
                    }
                }

                Games game = new Games
                {
                    Id          = int.Parse(item.Id),
                    GameName    = item.Name.First().Value,
                    MinPlayers  = int.Parse(item.Minplayers.Value),
                    MaxPlayers  = int.Parse(item.Maxplayers.Value),
                    SugPlayers  = suggestedPlayers,
                    GameDesc    = item.Description,
                    PlaytimeMin = int.Parse(item.Minplaytime.Value),
                    PlaytimeMax = int.Parse(item.Maxplaytime.Value),
                    ReviewScore = double.Parse(item.Statistics.Ratings.Average.Value),
                    NumReviews  = int.Parse(item.Statistics.Ratings.Usersrated.Value),
                    Complexity  = double.Parse(item.Statistics.Ratings.Averageweight.Value),
                    AgeMin      = int.Parse(item.Minage.Value),
                    AgeMax      = 99,
                    PictureUrl  = item.Thumbnail
                };

                foreach (Link link in item.Link)
                {
                    if (link.Type.Contains("category"))
                    {
                        Category category = new Category
                        {
                            Id        = int.Parse(link.Id),
                            Category1 = link.Value
                        };
                        GameCategory gameCategory = new GameCategory
                        {
                            GameId     = game.Id,
                            CategoryId = category.Id
                        };

                        if (!_dbContext.GameCategory.Contains(gameCategory))
                        {
                            _dbContext.Add(gameCategory);
                        }

                        if (!_dbContext.Category.Contains(category))
                        {
                            _dbContext.Add(category);
                        }
                    }
                    else if (link.Type.Contains("mechanic"))
                    {
                        Mechanic mechanic = new Mechanic
                        {
                            Id        = int.Parse(link.Id),
                            Mechanic1 = link.Value
                        };
                        GameMechanic gameMechanic = new GameMechanic
                        {
                            GameId     = game.Id,
                            MechanicId = mechanic.Id
                        };

                        if (!_dbContext.GameMechanic.Contains(gameMechanic))
                        {
                            _dbContext.Add(gameMechanic);
                        }

                        if (!_dbContext.Mechanic.Contains(mechanic))
                        {
                            _dbContext.Add(mechanic);
                        }
                    }
                    else if (link.Type.Contains("publish"))
                    {
                        Publisher publisher = new Publisher
                        {
                            Id         = int.Parse(link.Id),
                            Publisher1 = link.Value
                        };

                        GamePublisher gamePublisher = new GamePublisher
                        {
                            GameId      = game.Id,
                            PublisherId = publisher.Id
                        };
                        if (!_dbContext.GamePublisher.Contains(gamePublisher))
                        {
                            _dbContext.Add(gamePublisher);
                        }

                        if (!_dbContext.Publisher.Contains(publisher))
                        {
                            _dbContext.Add(publisher);
                        }
                    }
                    else if (link.Type.Contains("design"))
                    {
                        Designer designer = new Designer
                        {
                            Id        = int.Parse(link.Id),
                            Designer1 = link.Value
                        };
                        GameDesigner gameDesigner = new GameDesigner
                        {
                            GameId     = game.Id,
                            DesignerId = designer.Id
                        };

                        if (!_dbContext.GameDesigner.Contains(gameDesigner))
                        {
                            _dbContext.Add(gameDesigner);
                        }

                        if (!_dbContext.Designer.Contains(designer))
                        {
                            _dbContext.Add(designer);
                        }
                    }
                    else if (link.Type.Contains("artist"))
                    {
                        Artist artist = new Artist
                        {
                            Id      = int.Parse(link.Id),
                            Artist1 = link.Value
                        };
                        GameArtist gameArtist = new GameArtist
                        {
                            GameId   = game.Id,
                            ArtistId = artist.Id
                        };
                        if (!_dbContext.GameArtist.Contains(gameArtist))
                        {
                            _dbContext.Add(gameArtist);
                        }
                        if (!_dbContext.Artist.Contains(artist))
                        {
                            _dbContext.Add(artist);
                        }
                    }
                }
                if (!_dbContext.Games.Contains(game))
                {
                    _dbContext.Add(game);
                }
                _dbContext.SaveChanges();
            }
        }