Exemplo n.º 1
0
        public void InsertAndUpdateMatches(IEnumerable <Match> matches)
        {
            DateTime nextDay = DateTime.Now.AddHours(24);

            List <Match> matchesInDb = _dataBase.Matches.ToList();

            foreach (var match in matches)
            {
                Match existMatch = matchesInDb.FirstOrDefault(m => m.Id == match.Id);

                if (existMatch == null && nextDay >= match.StartDate)
                {
                    var newMatch = new Match
                    {
                        Id        = match.Id,
                        Name      = match.Name,
                        StartDate = match.StartDate,
                        MatchType = match.MatchType,
                        EventId   = match.EventId
                    };

                    _dataBase.Matches.Add(newMatch);
                }
                else if ((existMatch != null && nextDay >= match.StartDate) && (existMatch.Name != match.Name || existMatch.StartDate != match.StartDate || existMatch.MatchType != match.MatchType || existMatch.EventId != match.EventId))
                {
                    existMatch.Name      = match.Name;
                    existMatch.StartDate = match.StartDate;
                    existMatch.MatchType = match.MatchType;
                    existMatch.EventId   = match.EventId;
                }

                _dataBase.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void InsertAndUpdateBets(IEnumerable <Bet> bets)
        {
            List <Bet> betsInDb = _dataBase.Bets.ToList();

            foreach (var bet in bets)
            {
                Bet   existBet    = betsInDb.FirstOrDefault(b => b.Id == bet.Id);
                Match matchForBet = _dataBase.Matches.FirstOrDefault(m => m.Id == bet.MatchId);
                if (existBet == null && matchForBet != null)
                {
                    Bet newBet = new Bet
                    {
                        Id      = bet.Id,
                        Name    = bet.Name,
                        IsLive  = bet.IsLive,
                        MatchId = bet.MatchId
                    };

                    _dataBase.Bets.Add(newBet);
                }
                else if ((existBet != null && matchForBet != null) && (existBet.Name != bet.Name || existBet.IsLive != bet.IsLive || existBet.MatchId != bet.MatchId))
                {
                    existBet.Name    = bet.Name;
                    existBet.IsLive  = bet.IsLive;
                    existBet.MatchId = bet.MatchId;
                }

                _dataBase.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public void InsertAndUpdateEvents(IEnumerable <Event> events)
        {
            List <Event> eventsInDb = _dataBase.Events.ToList();

            foreach (var ev in events)
            {
                Event existEvent = eventsInDb.FirstOrDefault(e => e.Id == ev.Id);

                if (existEvent == null)
                {
                    Event newEvent = new Event
                    {
                        Id     = ev.Id,
                        Name   = ev.Name.Split(',').Skip(1).First().Trim(),
                        IsLive = ev.IsLive,
                        GameId = ev.GameId
                    };

                    _dataBase.Events.Add(newEvent);
                }
                else if (existEvent != null && (existEvent.Name != ev.Name.Split(',').Skip(1).First().Trim() || existEvent.IsLive == ev.IsLive || existEvent.GameId != ev.GameId))
                {
                    existEvent.Name   = ev.Name.Split(',').Skip(1).First().Trim();
                    existEvent.IsLive = ev.IsLive;
                    existEvent.GameId = ev.GameId;
                }
                _dataBase.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public void InsertAndUpdateGames(IEnumerable <Game> games)
        {
            List <Game> gamesInDb         = _dataBase.Games.ToList();
            List <Game> uniqueGameRecords = games.GroupBy(x => x.Id).Select(y => y.First()).ToList();

            foreach (var game in uniqueGameRecords)
            {
                Game existGame = gamesInDb.FirstOrDefault(g => g.Id == game.Id);

                if (existGame == null)
                {
                    Game newGame = new Game {
                        Id   = game.Id,
                        Name = game.Name.Split(',').First()
                    };

                    _dataBase.Games.Add(newGame);
                }
                else if (existGame != null && existGame.Name != game.Name.Split(',').First())
                {
                    existGame.Name = game.Name.Split(',').First();
                }
                _dataBase.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public void InsertAndUpdateOdds(IEnumerable <Odd> odds)
        {
            List <Odd> oddsInDb = _dataBase.Odds.ToList();

            foreach (var odd in odds)
            {
                Odd existOdd       = oddsInDb.FirstOrDefault(o => o.Id == odd.Id);
                Bet existBetForOdd = _dataBase.Bets.FirstOrDefault(b => b.Id == odd.BetId);
                if (existOdd == null && existBetForOdd != null)
                {
                    Odd newOdd = new Odd
                    {
                        Id              = odd.Id,
                        Name            = odd.Name,
                        Value           = odd.Value,
                        SpecialBetValue = odd.SpecialBetValue,
                        BetId           = odd.BetId
                    };

                    _dataBase.Odds.Add(odd);
                }
                else if ((existOdd != null && existBetForOdd != null) && (existOdd.Name != odd.Name || existOdd.Value != odd.Value || existOdd.SpecialBetValue != odd.SpecialBetValue || existOdd.BetId != odd.BetId))
                {
                    existOdd.Name            = odd.Name;
                    existOdd.Value           = odd.Value;
                    existOdd.SpecialBetValue = odd.SpecialBetValue;
                    existOdd.BetId           = odd.BetId;
                }

                _dataBase.SaveChanges();
            }
        }