public async Task Alugar(Locacao locacao) { if (locacao.ClienteId == Guid.Empty) { throw new Exception("Cliente não pode ser nulo"); } if (locacao.FilmeId == Guid.Empty) { throw new Exception("Filme não pode ser nulo"); } var filme = await _filmeRepository.ObterPorId(locacao.FilmeId); if (filme == null) { throw new Exception("Filme não encontrado"); } var cliente = await _clienteRepository.ObterPorId(locacao.ClienteId); if (cliente == null) { throw new Exception("Cliente não encontrado"); } if (_locacaoRepository.VerificarSeClienteJaLocouFilme(locacao.ClienteId, locacao.FilmeId).Result.Any()) { throw new Exception("O Filme já foi locado anteriormente"); } if (filme.QuantidadeDisponivel == 0) { throw new Exception("O Filme esta indisponivel"); } locacao.Inicio = DateTime.Now; await _locacaoRepository.Adicionar(locacao); filme.QuantidadeDisponivel--; await _filmeRepository.Atualizar(filme); }