Пример #1
0
        public JsonResult SaveTeamStandingGameUrl(int teamId, int clubId, string url, string teamName)
        {
            try
            {
                var service     = new ScrapperService();
                var isTeamExist = teamRepo.GetById(teamId) != null;
                var result      = service.StandingScraper(url);

                if (!isTeamExist && result.Any(t => t.Team != teamName))
                {
                    ProcessHelper.ClosePhantomJSProcess();
                    return(Json(new { Success = false, Error = "Such team not exist." }));
                }

                int standingGameId = teamRepo.SaveTeamStandingUrl(teamId, clubId, url, teamName);

                bool isSuccess = standingGameId > 0;

                if (isSuccess)
                {
                    gamesRepo.UpdateTeamStandingsFromModel(result, standingGameId, url);

                    service.Quit();
                }
                ProcessHelper.ClosePhantomJSProcess();
                return(Json(new { Success = isSuccess, Data = result }));
            }
            catch (Exception e)
            {
                return(Json(new { Sucess = false, Error = e.Message }));
            }
        }
Пример #2
0
        public JsonResult SaveGamesUrl(int teamId, string url, string teamName, int clubId)
        {
            try
            {
                var service = new ScrapperService();

                var result = service.SchedulerScraper(url);

                service.Quit();

                var isTeamExist = teamRepo.GetById(teamId) != null;


                if (!isTeamExist && result.Any(t => t.HomeTeam != teamName || t.GuestTeam != teamName))
                {
                    return(Json(new { Success = false, Error = "Such team doesn't exist" }));
                }

                var scheduleId = gamesRepo.SaveTeamGameUrl(teamId, url, clubId, teamName);

                gamesRepo.UpdateGamesSchedulesFromDto(result, clubId, scheduleId, url);

                ProcessHelper.ClosePhantomJSProcess();

                return(Json(new { Success = true, Data = result }));
            }
            catch (Exception e)
            {
                ProcessHelper.ClosePhantomJSProcess();

                return(Json(new { Success = false, Error = e.Message }));
            }
        }
Пример #3
0
        public void UpdateGamesSchedulersFromScrapper(List <string> gamesUrl)
        {
            var gameCycles = new List <SchedulerDTO>();

            var service = new ScrapperService();

            foreach (var gameUrl in gamesUrl)
            {
                var gameCycle = service.SchedulerScraper(gameUrl);
                gameCycles.AddRange(gameCycle);
            }

            var gamesToUpdate = db.TeamScheduleScrapperGames.Where(x => gamesUrl.Contains(x.GameUrl)).SelectMany(x => x.TeamScheduleScrappers).ToList();

            foreach (var game in gameCycles)
            {
                DateTime outDate;
                DateTime.TryParse(game.Time, new CultureInfo("he-IL"), DateTimeStyles.None, out outDate);
                var existedGame = gamesToUpdate.FirstOrDefault(x => x.GuestTeam == game.GuestTeam && x.HomeTeam == game.HomeTeam && x.Auditorium == game.Auditorium);
                if (existedGame != null)
                {
                    existedGame.Score = string.Format("{0}:{1}", game.HomeTeamScore, game.GuestTeamScore);
                }
                else
                {
                    var schedullerScrapperId = db.TeamScheduleScrapperGames.FirstOrDefault(x => x.GameUrl == game.Url)?.Id;
                    if (schedullerScrapperId.HasValue)
                    {
                        var newGame = new TeamScheduleScrapper
                        {
                            Auditorium = game.Auditorium,
                            GuestTeam  = game.GuestTeam,
                            HomeTeam   = game.HomeTeam,
                            SchedulerScrapperGamesId = schedullerScrapperId.Value,
                            Score     = string.Format("{0}:{1}", game.HomeTeamScore, game.GuestTeamScore),
                            StartDate = outDate,
                        };

                        db.TeamScheduleScrappers.Add(newGame);
                    }
                }
            }
            Save();
            service.Quit();
        }
Пример #4
0
        public void UpdateTeamStandingsFromScrapper(IList <string> gamesUrl)
        {
            var standings = new List <StandingDTO>();
            var service   = new ScrapperService();

            foreach (var standingUrl in gamesUrl)
            {
                var items = service.StandingScraper(standingUrl);
                standings.AddRange(items);
            }

            foreach (var standing in standings)
            {
                //var strToIntRank = Convert.ToInt32(standing.Rank.Replace(".", string.Empty));
                int outVal;
                int.TryParse(standing.Rank.Replace(".", string.Empty), out outVal);

                var dbStanding =
                    db.TeamStandings.FirstOrDefault(
                        x =>
                        x.Team == standing.Team);

                //if we find the team update it
                if (dbStanding != null)
                {
                    dbStanding.Rank           = outVal;
                    dbStanding.Games          = standing.Games.ToByte();
                    dbStanding.Wins           = standing.Win.ToByte();
                    dbStanding.Lost           = standing.Lost.ToByte();
                    dbStanding.Pts            = standing.Pts.ToByte();
                    dbStanding.Papf           = standing.PaPf;
                    dbStanding.Home           = standing.Home;
                    dbStanding.Road           = standing.Road;
                    dbStanding.ScoreHome      = standing.ScoreHome;
                    dbStanding.ScoreRoad      = standing.ScoreRoad;
                    dbStanding.Last5          = standing.Last5;
                    dbStanding.PlusMinusField = standing.PlusMinusField;
                }
                //else create new teamStanding
                else
                {
                    var standingGameId = db.TeamStandingGames.FirstOrDefault(x => x.GamesUrl == standing.Url)?.Id;

                    var newTeamStnading = new TeamStanding
                    {
                        Team                = standing.Team,
                        Rank                = outVal,
                        Games               = standing.Games.ToByte(),
                        Wins                = standing.Win.ToByte(),
                        Lost                = standing.Lost.ToByte(),
                        Pts                 = standing.Pts.ToByte(),
                        Papf                = standing.PaPf,
                        Home                = standing.Home,
                        Road                = standing.Road,
                        ScoreHome           = standing.ScoreHome,
                        ScoreRoad           = standing.ScoreRoad,
                        Last5               = standing.Last5,
                        TeamStandingGamesId = standingGameId,
                        PlusMinusField      = standing.PlusMinusField,
                    };



                    db.TeamStandings.Add(newTeamStnading);
                }
            }
            try
            {
                Save();
                service.Quit();
            }

            catch (DbEntityValidationException e)
            {
            }
            catch (Exception)
            {
                throw;
            }
        }