Пример #1
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 }));
            }
        }
Пример #2
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();
        }