Пример #1
0
        public async Task <bool> Handle(CreateTournament command,
                                        CancellationToken cancellationToken = default(CancellationToken))
        {
            var tournament = new Tournament(command.Title, command.StartDate, command.EndDate);
            await _context.Tournaments.AddAsync(tournament, cancellationToken);

            return(await _context.SaveChangesAsync(cancellationToken) > 0);
        }
Пример #2
0
        public async Task <bool> Handle(CreateExpert command,
                                        CancellationToken cancellationToken = default(CancellationToken))
        {
            var expert = new Expert(command.Nickname);
            await _context.Experts.AddAsync(expert, cancellationToken);

            return(await _context.SaveChangesAsync(cancellationToken) > 0);
        }
Пример #3
0
        public async Task <bool> Handle(UpdateTourInfo command,
                                        CancellationToken cancellationToken = default(CancellationToken))
        {
            var tour = await _context.Tours.FindAsync(command.Id);

            tour.UpdateInfo(command.Number, command.StartDate, command.EndDate);
            return(await _context.SaveChangesAsync(cancellationToken) > 0);
        }
Пример #4
0
        public async Task <bool> Handle(DeleteTour command,
                                        CancellationToken cancellationToken = default(CancellationToken))
        {
            var tour = await _context.Tours.FindAsync(command.Id);

            _context.Remove(tour);

            return(await _context.SaveChangesAsync(cancellationToken) > 0);
        }
Пример #5
0
        public async Task <bool> Handle(RollbackHeadToHeadTour request,
                                        CancellationToken cancellationToken = default(CancellationToken))
        {
            var headToHeadTourId = request.HeadToHeadTourId;
            var headToHeadTour   = await _context.HeadToHeadTours.FetchWithMatches(FetchMode.ForModify).WithIdAsync(headToHeadTourId, cancellationToken);

            headToHeadTour.Rollback();
            return(await _context.SaveChangesAsync(cancellationToken) >= 0);
        }
        public async Task <bool> Handle(AddExpertTourPredictions request,
                                        CancellationToken cancellationToken = default(CancellationToken))
        {
            var expertId = request.ExpertId;
            var tourId   = request.TourId;
            var incomingPredictionsInfo = request.Predictions.ToList();

            var tour = await _context
                       .Tours
                       .FetchWitMatchesAndPredictions(FetchMode.ForModify)
                       .WithIdAsync(tourId, cancellationToken);

            //if (tour.IsClosed) throw new InvalidOperationException("The tour is closed");

            var matches = tour.Matches;

            var expertPredictions = matches
                                    .SelectMany(m => m.Predictions)
                                    .Where(p => p.ExpertId == expertId)
                                    .ToList();

            foreach (var incomingPredictionInfo in incomingPredictionsInfo)
            {
                var expertPrediction = expertPredictions.SingleOrDefault(p => p.MatchId == incomingPredictionInfo.MatchId);

                if (expertPrediction == null)
                {
                    var score = FootballScoreProcessor.CreateScoreExpr(incomingPredictionInfo.HomeGoals,
                                                                       incomingPredictionInfo.AwayGoals);
                    var prediction = new Prediction(expertId, incomingPredictionInfo.MatchId, score);
                    _context.Add(prediction);
                }
                else
                {
                    expertPrediction.SetScore(incomingPredictionInfo.HomeGoals, incomingPredictionInfo.AwayGoals);
                }
            }

            return(await _context.SaveChangesAsync(cancellationToken) >= 0);
        }