Exemplo n.º 1
0
        public SimulacaoAluguelDTO Simular(SimularAlugueisDTO Aluguel)
        {
            Carros Carro = this._carrosRepositorio.GetById(Aluguel.CarroId);

            if (Carro == null)
            {
                throw new Exception($"Carro com id: {Aluguel.CarroId} não encontrado.");
            }

            Alugueis AluguelSimulacao = new Alugueis
            {
                Carro        = Carro,
                Cliente      = null,
                DataAluguel  = DateTime.Now,
                DataCheckin  = Aluguel.DataCheckin,
                DataCheckout = Aluguel.DataCheckout,
                Origem       = Aluguel.Origem,
                PrecoNoDia   = Carro.ValorHora
            };

            return(new SimulacaoAluguelDTO
            {
                Carro = Carro,
                DateCheckin = AluguelSimulacao.DataCheckin,
                DateCheckout = AluguelSimulacao.DataCheckout,
                Horas = AluguelSimulacao.Horas,
                PrecoTotal = AluguelSimulacao.PrecoTotal
            });
        }
Exemplo n.º 2
0
        public IActionResult SimularAluguel(SimularAlugueisDTO Aluguel)
        {
            try
            {
                SimulacaoAluguelDTO Retorno = this._alugueisBLL.Simular(Aluguel);

                return(Ok(new SaidaAPI {
                    ExecutadoComSucesso = true, Data = Retorno
                }));
            }
            catch (Exception e)
            {
                return(BadRequest(new SaidaAPI {
                    ExecutadoComSucesso = false, Mensagem = e.Message
                }));
            }
        }