public ActionResult Save(Locacao locacao) // recebemos um cliente
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new LocacaoIndexViewModel
                {
                    Locacao    = locacao,
                    Veiculos   = _context.Veiculos.ToList(),
                    Clientes   = _context.Clientes.ToList(),
                    Vendedores = _context.Vendedores.ToList()
                };
                return(View("LocacaoForm", viewModel));
            }

            if (locacao.Id == 0)
            {
                // armazena o cliente em memória
                _context.Locacoes.Add(locacao);
            }
            else
            {
                var locacaoInDb = _context.Locacoes.Single(c => c.Id == locacao.Id);

                locacaoInDb.DataLocacao = locacao.DataLocacao;
                locacaoInDb.Veiculo     = locacao.Veiculo;
            }

            // faz a persistência
            _context.SaveChanges();
            // Voltamos para a lista de clientes
            return(RedirectToAction("Index"));
        }
        public ActionResult New()
        {
            var locacao = new LocacaoIndexViewModel
            {
                Locacao    = new Locacao(),
                Veiculos   = _context.Veiculos.ToList(),
                Clientes   = _context.Clientes.ToList(),
                Vendedores = _context.Vendedores.ToList(),
            };

            return(View("LocacaoForm", locacao));
        }
        public ActionResult Edit(int id)
        {
            var locacao = _context.Locacoes.SingleOrDefault(c => c.Id == id);

            if (locacao == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new LocacaoIndexViewModel
            {
                Locacao    = locacao,
                Veiculos   = _context.Veiculos.ToList(),
                Clientes   = _context.Clientes.ToList(),
                Vendedores = _context.Vendedores.ToList(),
            };


            return(View("LocacaoForm", viewModel));
        }