public IActionResult SimularReserva(SimulacaoReservaModel simulacaoReserva)
        {
            base.PreencherViewBagUsuarioLogado();

            if (simulacaoReserva != null)
            {
                AluguelDTO aluguelDTO = new AluguelDTO()
                {
                    Veiculo = new VeiculoDTO()
                    {
                        IdVeiculo = simulacaoReserva.IdVeiculo
                    },
                    TotalDeHoras        = simulacaoReserva.TotalHorasAluguel,
                    DataPrevistaAluguel = simulacaoReserva.DataPrevista
                };

                var aluguel = _reservaBLL.SimularAluguel(aluguelDTO);
                aluguel.Veiculo.Placa = simulacaoReserva.Placa;

                return(View("ResumoReserva", new AluguelModel(aluguel)));
            }
            else
            {
                return(View("Index", "Home"));
            }
        }
예제 #2
0
        public Aluguel Alugar(AluguelDTO aluguel)
        {
            if (aluguel.DataEmprestimo > aluguel.DataDevolucao)
            {
                throw new Exception("A data de empréstimo deve ser anterior à data de entrega.");
            }

            DateTime inicio  = aluguel.DataEmprestimo.GetValueOrDefault();
            DateTime entrega = aluguel.DataDevolucao.GetValueOrDefault();

            IList <Veiculo> veiculosDisponiveis = veiculoRepositorio.ListarDisponiveis(inicio, entrega);

            Veiculo veiculo = veiculosDisponiveis.FirstOrDefault(x => x.Id == aluguel.Veiculo.Id);

            if (veiculo == null)
            {
                throw new Exception("Veículo indisponível durante o período selecionado.");
            }

            Aluguel novoAluguel = new Aluguel();

            novoAluguel.Clientes = new List <Cliente>();

            novoAluguel.DataEmprestimo          = inicio;
            novoAluguel.DataDevolucaoContratada = entrega;
            novoAluguel.DataDevolucao           = null;
            novoAluguel.Veiculo = veiculo;
            novoAluguel.Clientes.Add(clienteRepositorio.buscarPorCpf(aluguel.Cpf));

            return(repositorio.Inserir(novoAluguel));
        }
        public ActionResult EfetuarAluguel()
        {
            try
            {
                Aluguel aluguel = null;

                if (Session["Aluguel"] != null)
                {
                    aluguel = (Aluguel)Session["Aluguel"];
                }
                else
                {
                    Carrinho carrinho = CarrinhoRepository.GetInstance().Get(UsuarioLogado.Usuario);

                    PrecoPrazoEntrega precoPrazo = CalculoPrecoPrazoRepository.GetInstance().CalcularPrecoPrazo(UsuarioLogado.Usuario.Cep.ToString("00000000"));
                    AluguelDTO        aluguelDTO = FactoryAluguel.Criar(carrinho, precoPrazo);

                    aluguel = aluguelDTO.Aluguel;
                }

                AluguelRepository.Instancia.ConfirmarAluguel(aluguel);

                return(View(aluguel));
            }
            catch (Exception ex)
            {
                return(Json(new { Mensagem = ex.Message }));
            }
        }
        public ActionResult Index()
        {
            Carrinho carrinho = CarrinhoRepository.GetInstance().Get(UsuarioLogado.Usuario);

            PrecoPrazoEntrega precoPrazo = CalculoPrecoPrazoRepository.GetInstance().CalcularPrecoPrazo(UsuarioLogado.Usuario.Cep.ToString("00000000"));
            AluguelDTO        aluguel    = FactoryAluguel.Criar(carrinho, precoPrazo);

            Session["Aluguel"] = aluguel.Aluguel;

            return(View(aluguel));
        }
        public IActionResult ConcluirReserva(AluguelModel aluguel)
        {
            var aluguelcookie            = RecuperarReservaCookie();
            var aluguelParaProcessamento = aluguelcookie != null && !aluguelcookie.IdVeiculo.Equals(0) ? aluguelcookie : aluguel;

            if (!VerificarUsuarioLogado())
            {
                SalvarReservaCookie(aluguelParaProcessamento);
                return(RedirectToAction("Login", "CadastroUsuario", new UsuarioModel()
                {
                    PreReserva = true
                }));
            }
            var clienteLogado = ObterClienteLogado();

            if (clienteLogado?.IdCliente == 0 && aluguel.IdCliente.Equals(0))
            {
                SalvarReservaCookie(aluguelParaProcessamento);
                return(RedirectToAction("Index", "CadastroCliente", new ClienteModel()
                {
                    PreReserva = true
                }));
            }

            aluguelParaProcessamento.IdCliente = clienteLogado.IdCliente;
            if (aluguelParaProcessamento != null)
            {
                AluguelDTO aluguelDTO = new AluguelDTO()
                {
                    Veiculo = new VeiculoDTO()
                    {
                        IdVeiculo = aluguelParaProcessamento.IdVeiculo, Placa = aluguelParaProcessamento.Placa
                    },
                    Cliente = new ClienteDTO()
                    {
                        IdCliente = aluguelParaProcessamento.IdCliente
                    },
                    TotalDeHoras        = aluguelParaProcessamento.TotalDeHoras,
                    DataPrevistaAluguel = aluguelParaProcessamento.DataPrevistaAluguel,
                    ValorHora           = aluguelParaProcessamento.ValorHora,
                    ValorFinal          = aluguelParaProcessamento.ValorFinalAluguel
                };

                _reservaBLL.EfetuarAluguel(aluguelDTO, ObterJWToken());
                RemoverReservaCookie();
            }
            else
            {
                return(View("Index", "Home"));
            }
            base.PreencherViewBagUsuarioLogado();
            return(View("ReservaConcluida"));
        }
예제 #6
0
 public AluguelModel(AluguelDTO aluguel)
 {
     if (aluguel != null)
     {
         IdAluguel           = aluguel.IdAluguel;
         Placa               = aluguel.Veiculo?.Placa;
         IdVeiculo           = aluguel.Veiculo != null ? aluguel.Veiculo.IdVeiculo : 0;
         IdCliente           = aluguel.Cliente != null? aluguel.Cliente.IdCliente : 0;
         Categoria           = aluguel.Categoria;
         DataPrevistaAluguel = aluguel.DataPrevistaAluguel;
         ValorHora           = aluguel.ValorHora;
         TotalDeHoras        = aluguel.TotalDeHoras;
         ValorFinalAluguel   = aluguel.ValorFinal;
     }
 }
        public AluguelDTO EfetuarAluguel(AluguelDTO aluguel, string jwToken)
        {
            AluguelDTO retorno = Post <AluguelDTO>($"{_rotaAluguel}/", jwToken, aluguel);

            return(retorno);
        }
        public AluguelDTO SimularAluguel(AluguelDTO aluguel)
        {
            AluguelDTO retorno = Post <AluguelDTO>($"{_rotaAluguel}/simulacao", null, aluguel);

            return(retorno);
        }
 public AluguelDTO EfetuarAluguel(AluguelDTO aluguel, string jwToken)
 {
     return(_reservaRepository.EfetuarAluguel(aluguel, jwToken));
 }
예제 #10
0
 public AluguelDTO SimularAluguel(AluguelDTO aluguel)
 {
     return(_reservaRepository.SimularAluguel(aluguel));
 }
예제 #11
0
 public void Alugar([FromBody] AluguelDTO aluguel)
 {
     _business.Alugar(aluguel);
 }