//
        // GET: /TeleEntrega/Index
        public ActionResult Index()
        {
            Parametro teleEntrega = null;

            try
            {
                ParametroService teleEntregaService = new ParametroService();
                teleEntrega = teleEntregaService.Find();
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View(teleEntrega);
        }
        public ActionResult Index(Parametro teleEntrega)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ParametroService teleEntregaService = new ParametroService();
                    teleEntregaService.Update(teleEntrega);

                    TempData["message"] = "Parâmetros alterados com sucesso";

                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return View(teleEntrega);
        }
        public ActionResult Index(Fechamento fechamento)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Carrega os pedidos em aberto
                    PedidoService pedidoService = new PedidoService();
                    fechamento.Pedidos = pedidoService.ListPedidosAbertos(true);

                    // Carrega os parãmetros
                    ParametroService parametroService = new ParametroService();
                    fechamento.Parametro = parametroService.Find();

                    // Fecha o pedido
                    FechamentoService fechamentoService = new FechamentoService();
                    fechamentoService.FechaPedido(fechamento);

                    // Envia os emails
                    fechamentoService.EnviaEmailContato(fechamento);
                    fechamentoService.EnviaEmailUsuarios(fechamento);

                    TempData["message"] = "Pedido finalizado com sucesso - Valor total R$ " + String.Format("{0:0.00}", fechamento.Pedidos.Sum(p => p.Valor));

                    return RedirectToAction("Index", "Home");
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            fechamento = InicializaTela(fechamento);

            return View();
        }