Ejemplo n.º 1
0
        public async Task <bool> SetGamblers(SetTournamentGamblersViewModel model)
        {
            var tournamentGamblers = await _dbContext.TournamentGamblers.Where(t => t.TournamentId == model.TournamentId).ToListAsync();

            var gamblersToActivate = tournamentGamblers.Where(g => model.GamblersIds.Contains(g.GamblerId) && !g.IsActive).ToList();

            foreach (var gambler in gamblersToActivate)
            {
                gambler.IsActive = true;

                _dbContext.Entry(gambler).State = EntityState.Modified;

                await _matchBetService.AddOrUpdateGamblerMatchBets(model.TournamentId, gambler.GamblerId);
            }

            var gamblersToDeactivate = tournamentGamblers.Where(g => !model.GamblersIds.Contains(g.GamblerId)).ToList();

            foreach (var gambler in gamblersToDeactivate)
            {
                gambler.IsActive = false;

                _dbContext.Entry(gambler).State = EntityState.Modified;
            }

            var gamblersIdsToAdd = model.GamblersIds.Except(tournamentGamblers.Select(g => g.GamblerId));

            foreach (var gamblerId in gamblersIdsToAdd)
            {
                var tournamentGambler = new TournamentGambler
                {
                    GamblerId    = gamblerId,
                    TournamentId = model.TournamentId
                };

                _dbContext.TournamentGamblers.Add(tournamentGambler);
                await _matchBetService.AddOrUpdateGamblerMatchBets(model.TournamentId, gamblerId);
            }

            await _dbContext.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> UpdateScore(UpdateMatchScoreViewModel model)
        {
            var match = await _dbContext.Matches.FirstOrDefaultAsync(m => m.Id == model.Id);

            if (match == null)
            {
                return(false);
            }

            match.TeamAScore = model.TeamAScore;
            match.TeamBScore = model.TeamBScore;

            _dbContext.Entry(match).State = EntityState.Modified;
            await _dbContext.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <MatchBet> > SaveBets(SaveMatchBetsViewModel model)
        {
            var gamblerBets = await _dbContext.MatchBets.Include(m => m.Match)
                              .Where(m => m.GamblerId == model.GamblerId && m.Match.RoundId == model.RoundId).ToListAsync();

            foreach (var bet in model.Bets)
            {
                var betToUpdate = gamblerBets.FirstOrDefault(b => b.Id == bet.Id && !b.TeamAScore.HasValue);

                if (betToUpdate == null)
                {
                    continue;
                }

                betToUpdate.TeamAScore = bet.TeamAScore;
                betToUpdate.TeamBScore = bet.TeamBScore;

                _dbContext.Entry(betToUpdate).State = EntityState.Modified;
            }

            await _dbContext.SaveChangesAsync();

            return(gamblerBets);
        }