Exemplo n.º 1
0
    public async Task AddTeamAsync(AddTeam cmd)
    {
        // Check if the team already exists
        var teamGrain = GrainFactory.GetGrain <ITeamGrain>(cmd.TeamId);
        var exists    = await teamGrain.TeamExistAsync();

        if (!exists)
        {
            await PublishErrorAsync(new ErrorHasOccurred((int)Results.TeamDoesNotExist, nameof(AddTeam), cmd.TraceId, cmd.InvokerUserId));
        }

        // Check other preconditions
        var result = ResultsUtil.Eval(
            State.TournamentExists(),
            State.TeamIsNotAdded(cmd.TeamId),
            State.LessThanEightTeams());

        var task = result switch
        {
            Results.Unit => PersistPublishAsync(new TeamAdded(cmd.TeamId, cmd.TournamentId, cmd.TraceId, cmd.InvokerUserId)),
            Results x => PublishErrorAsync(new ErrorHasOccurred((int)x, x.ToString(), cmd.TraceId, cmd.InvokerUserId))
        };

        await task;
    }
Exemplo n.º 2
0
    public async Task SetMatchResultAsync(SetMatchResult cmd)
    {
        var result = ResultsUtil.Eval(
            State.TournamentExists(),
            State.TournamentStarted(),
            State.MatchIsNotDraw(cmd.Match.MatchResult),
            State.MatchExistsAndIsNotPlayed(cmd.Match));

        var task = result switch
        {
            Results.Unit => PersistPublishAsync(new MatchResultSet(cmd.TournamentId, cmd.Match, cmd.TraceId, cmd.InvokerUserId)),
            Results x => PublishErrorAsync(new ErrorHasOccurred((int)x, x.ToString(), cmd.TraceId, cmd.InvokerUserId))
        };

        await task;
    }
}
Exemplo n.º 3
0
    public async Task StartAsync(StartTournament cmd)
    {
        var result = ResultsUtil.Eval(
            State.TournamentExists(),
            State.TournamentDidNotStart(),
            State.EightTeamsToStartTournament());

        // Randomize seed
        var seed = DateTime.Now.Millisecond;

        var task = result switch
        {
            Results.Unit => PersistPublishAsync(new TournamentStarted(cmd.TournamentId, State.Teams, seed, cmd.TraceId, cmd.InvokerUserId)),
            Results x => PublishErrorAsync(new ErrorHasOccurred((int)x, x.ToString(), cmd.TraceId, cmd.InvokerUserId))
        };

        await task;
    }