// [ValidateInput(false)]

        public ActionResult IncluirEmprestimoCliente(Emprestimo emprestimo, string[] dias)
        {
            try
            {
                IClienteProcesso processoCliente = ClienteProcesso.Instance;
                List <Cliente>   resultCliente   = processoCliente.ConsultarClientesDevedores();

                var resultCiente2 = (from cc in resultCliente
                                     where cc.id == ClasseAuxiliar.ClienteSelecionado.id
                                     select cc).SingleOrDefault();


                if (resultCiente2 != null && resultCiente2.id == ClasseAuxiliar.ClienteSelecionado.id)
                {
                    ModelState.AddModelError("valor", "O Cliente está com dividas em aberto.");
                }


                List <int>       diasUteis  = new List <int>();
                List <DayOfWeek> dayOfWeeks = new List <DayOfWeek>();
                if (dias != null)
                {
                    for (int i = 0; i < dias.Length; i++)
                    {
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Friday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Friday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Monday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Monday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Saturday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Saturday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Sunday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Sunday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Thursday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Thursday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Tuesday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Tuesday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Wednesday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Wednesday);
                        }


                        diasUteis.Add(Convert.ToInt16(dias[i]));
                    }
                }


                ViewData["DiasUteis"] = ClasseAuxiliar.CarregarCheckBoxEnum <DiasUteis>(diasUteis);

                var teste = Request;
                IEmprestimoProcesso processo = EmprestimoProcesso.Instance;
                //if (ModelState.IsValid)
                {
                    emprestimo.cliente_id = ClasseAuxiliar.ClienteSelecionado.id;
                    emprestimo.usuario_id = ClasseAuxiliar.UsuarioLogado.id;
                    emprestimo.area_id    = ClasseAuxiliar.AreaSelecionada.id;
                    //emprestimo.timeCreated = DateTime.Now;
                    //emprestimo.timeUpdated = DateTime.Now;
                    processo.Incluir(emprestimo, dayOfWeeks);
                    processo.Confirmar();
                    return(RedirectToAction("EmprestimoCliente", new { id = ClasseAuxiliar.ClienteSelecionado.id }));
                }
                //else
                //{
                //    return View(emprestimo);
                //}
            }
            catch (Exception e)
            {
                return(View(emprestimo));
            }
        }
        public ActionResult Incluir(Emprestimo emprestimo, string[] dias)
        {
            try
            {
                IClienteProcesso processoCliente = ClienteProcesso.Instance;
                List <Cliente>   resultCliente   = processoCliente.ConsultarClientesDevedores();

                var resultCiente2 = from cc in resultCliente
                                    where cc.ID == ClasseAuxiliar.ClienteSelecionado.ID
                                    select cc;


                if (resultCliente.Count > 0)
                {
                    ModelState.AddModelError("valor", "O Cliente está com dividas em aberto.");
                }

                List <int>       diasUteis  = new List <int>();
                List <DayOfWeek> dayOfWeeks = new List <DayOfWeek>();
                if (dias != null)
                {
                    for (int i = 0; i < dias.Length; i++)
                    {
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Friday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Friday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Monday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Monday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Saturday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Saturday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Sunday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Sunday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Thursday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Thursday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Tuesday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Tuesday);
                        }
                        if (Convert.ToInt16(dias[i]) == (int)DayOfWeek.Wednesday)
                        {
                            dayOfWeeks.Add(DayOfWeek.Wednesday);
                        }


                        diasUteis.Add(Convert.ToInt16(dias[i]));
                    }
                }

                ViewData["DiasUteis"] = ClasseAuxiliar.CarregarCheckBoxEnum <DiasUteis>(diasUteis);
                if (ModelState.IsValid)
                {
                    IEmprestimoProcesso processo = EmprestimoProcesso.Instance;
                    emprestimo.area_id         = ClasseAuxiliar.AreaSelecionada.ID;
                    emprestimo.usuario_id      = ClasseAuxiliar.UsuarioLogado.ID;
                    emprestimo.data_emprestimo = ClasseAuxiliar.DataSelecionada;
                    emprestimo.timeCreated     = DateTime.Now;
                    processo.Incluir(emprestimo, dayOfWeeks);
                    processo.Confirmar();
                    return(RedirectToAction("IncluirPrestacaoConta", "Movimentacao"));
                }
                else
                {
                    return(View(emprestimo));
                }
            }
            catch (Exception e)
            {
                return(View(emprestimo));
            }
        }