public async Task <CreateMatchSetResult> Handle(CreateMatchSetCommand command, CancellationToken cancel) { var set = new MatchSet { SeasonId = command.SeasonId, MatchSetNumber = _db.MatchSets.Max(ms => ms.MatchSetNumber) + 1 }; _db.MatchSets.Add(set); await _db.SaveChangesAsync(); return(new CreateMatchSetResult { MatchSet = set }); }
public async Task <CreateSeasonResult> Handle(CreateSeasonCommand message) { var result = new CreateSeasonResult(); await ValidateSeason(message, result); if (result.Errors.Count < 1) { result.NewSeason = new Season { Name = message.Name, IsCurrent = true }; _db.Seasons.Add(result.NewSeason); await _db.SaveChangesAsync(); } return(result); }
public async Task <UpdateActiveFlagResult> Handle(UpdateActiveFlagCommand command, CancellationToken cancel) { var result = new UpdateActiveFlagResult(); var golfer = await _db.Golfers.FirstOrDefaultAsync(g => g.Id == command.Id); if (golfer != null) { golfer.IsActive = command.Value; await _db.SaveChangesAsync(); result.Golfer = golfer; } else { result.Errors.Add($"Could not find golfer with an ID of {command.Id}"); } return(result); }