示例#1
0
        public async Task TesteMetacritic()
        {
            GamesEntities        db    = new GamesEntities();
            List <game_platform> games = db.game_platform.Where(gp => gp.metacritic == null).ToList();

            foreach (game_platform g in games)
            {
                GameEntity jogo       = db.game.Find(g.id_game);
                platform   plataforma = db.platform.Find(g.id_platform);
                string     sigla;
                switch (plataforma.sigla)
                {
                case "PS1":
                    sigla = "PS";
                    break;

                case "PSVITA":
                    sigla = "VITA";
                    break;

                default:
                    sigla = plataforma.sigla;
                    break;
                }
                try {
                    var metacritic = await Metacritic.SearchFor().Games().UsingTextAsync(jogo.name);

                    var resultado = metacritic.Where(m => m.Platform == sigla).Where(m => m.Name == jogo.name).FirstOrDefault();
                    if (resultado != null)
                    {
                        g.metacritic      = resultado.Score;
                        db.Entry(g).State = EntityState.Modified;
                    }
                }
                catch (Exception ex) {
                }
            }
            db.SaveChanges();
        }
示例#2
0
        public async Task <ActionResult> PreencherDadosGameIgdbJquery(int id_igdb, int Id = 0)
        {
            IgdbService       igdb     = new IgdbService();
            DadosGameResponse response = igdb.DadosJogo(id_igdb).FirstOrDefault();
            List <DadosDeveloperPublisherResponse> devs = new List <DadosDeveloperPublisherResponse>();
            List <DadosDeveloperPublisherResponse> pubs = new List <DadosDeveloperPublisherResponse>();
            List <DadosGenreResponse> genres            = new List <DadosGenreResponse>();
            List <ReleaseDate>        lancamentos       = new List <ReleaseDate>();

            PlatformRepository pr = new PlatformRepository();

            if (response.Developers != null && response.Developers.Count > 0)
            {
                devs = igdb.DadosDeveloperPublisher(response.Developers.ToArray());
            }
            if (response.Publishers != null && response.Publishers.Count > 0)
            {
                pubs = igdb.DadosDeveloperPublisher(response.Publishers.ToArray());
            }
            if (response.Genres != null && response.Genres.Count > 0)
            {
                genres = igdb.DadosGenre(response.Genres.ToArray());
            }
            if (response.ReleaseDates != null && response.ReleaseDates.Count > 0)
            {
                lancamentos = response.ReleaseDates;
            }

            GameDataView gameDataView = GameDataView.GetGameDataView();

            gameDataView.Id        = Id;
            gameDataView.id_igdb   = id_igdb;
            gameDataView.Titulo    = response.Name;
            gameDataView.Descricao = response.Summary;

            if (response.Cover != null)
            {
                gameDataView.Imagem      = gameDataView.BigCoverUrl + response.Cover.CloudinaryId + ".jpg";
                gameDataView.CloudnaryId = response.Cover.CloudinaryId;
            }
            else
            {
                gameDataView.Imagem = "/Content/ps.png";
            }

            gameDataView.InitListas();

            foreach (DadosDeveloperPublisherResponse dev in devs)
            {
                gameDataView.ListaDeveloper.Add(new developerPublisher {
                    name    = dev.Name,
                    id_igdb = dev.Id
                });
            }

            foreach (DadosDeveloperPublisherResponse pub in pubs)
            {
                gameDataView.ListaPublisher.Add(new developerPublisher {
                    name    = pub.Name,
                    id_igdb = pub.Id
                });
            }

            foreach (DadosGenreResponse genre in genres)
            {
                gameDataView.ListaGenre.Add(new genre {
                    id_igdb = genre.Id,
                    name    = genre.Name
                });
            }

            try {
                var buscaMetacritic = await Metacritic.SearchFor().Games().UsingTextAsync(response.Name);

                foreach (ReleaseDate lancamento in lancamentos)
                {
                    platform plataforma = pr.GetPlatformByIgdb(lancamento.Platform);
                    int?     meta       = null;
                    if (plataforma != null)
                    {
                        string sigla;
                        switch (plataforma.sigla)
                        {
                        case "PS1":
                            sigla = "PS";
                            break;

                        case "PSVITA":
                            sigla = "VITA";
                            break;

                        default:
                            sigla = plataforma.sigla;
                            break;
                        }

                        var resultado = buscaMetacritic.Where(m => m.Platform == sigla).Where(m => m.Name.ToLowerInvariant() == response.Name.ToLowerInvariant()).FirstOrDefault();
                        if (resultado != null)
                        {
                            meta = resultado.Score;
                        }

                        DateTime data = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(Convert.ToDouble(Convert.ToDouble(lancamento.Date)));
                        gameDataView.Platforms.Add(new game_platform {
                            id_platform  = plataforma.id,
                            release_date = data,
                            metacritic   = meta,
                            id_region    = lancamento.Region
                        });
                    }
                }
            }
            catch (Exception ex) {
            }

            return(PartialView("FormGameView", gameDataView));
        }