public void Update(Aluguel aluguel)
 {
     ctx.Entry(aluguel).State = EntityState.Modified;
     ctx.SaveChanges();
 }
 public void Delete(Aluguel aluguel)
 {
     ctx.Alugueis.Remove(aluguel);
     ctx.SaveChanges();
 }
 public void Add(Aluguel aluguel)
 {
     ctx.Alugueis.Add(aluguel);
         ctx.Carros.Single(x => x.CarroID == aluguel.CarroID).Alugueis.Add(aluguel);
         ctx.SaveChanges();
 }
 public void Reservar(DateTime dataAluguel, DateTime dataDevolucao, int carroID, string userID)
 {
     try
     {
         Carro carro = carroDAO.FindById(carroID);
         if (!carro.Alugado)
         {
             carro.Alugado = true;
             Aluguel aluguel = new Aluguel()
             {
                 DataAluguel = dataAluguel,
                 DataDevolucao = dataDevolucao,
                 CarroID = carroID,
                 UserId = userID,
                 KmInicial = carro.Quilometragem
             };
             Adicionar(aluguel);
         }
         else
         {
             throw new BusinessException("Carro já se encontra alugado.");
         }
     }
     catch (NullReferenceException ex)
     {
         throw new BusinessException("Carro nao encontrado.",ex);
     }
 }
 public void Editar(Aluguel aluguel)
 {
     dao.Update(aluguel);
 }
 public void Adicionar(Aluguel aluguel)
 {
     dao.Add(aluguel);
 }