public override async Task EnsureIsNotInUse(Game entity) { _ = entity ?? throw new ArgumentNullException(nameof(entity)); var specification = new Venue.IsInUseSpecification(entity.Id); var anyVenue = await _context.Set <Venue>().AnyAsync(specification.SatisfiedBy()); if (anyVenue) { throw new DomainException(Game.IS_IN_USE); } }
public async Task Execute(int gameId, CancellationToken cancellationToken) { var game = await _gamesRepository.Find(gameId, cancellationToken); if (game is null) { throw new DomainException(Game.NOT_FOUND); } var specification = new Venue.IsInUseSpecification(game.Id).SatisfiedBy(); var venues = await _venuesRepository.AnyAsync(specification, cancellationToken); if (venues) { throw new DomainException(Game.IS_IN_USE); } await _gamesRepository.Remove(game); }
private async Task <Unit> HandleAsync(DeleteGame request, CancellationToken cancellationToken) { var game = await _gamesRepository.Find(request.Id, cancellationToken); if (game is null) { throw new EntityNotFoundException(typeof(Game), request.Id); } var specification = new Venue.IsInUseSpecification(game.Id).SatisfiedBy(); var existsVenues = await _venuesRepository.AnyAsync(specification, cancellationToken); if (existsVenues) { throw new ApplicationException(IsInUse); } await _gamesRepository.Remove(game); await _unitOfWork.Save(default);