예제 #1
0
        public ActionResult Create(Cliente cliente)
        {
            if (!ClientesUtils.EsCedulaValida(cliente.Identificacion))
            {
                ModelState.AddModelError("Identificacion", "La cédula digitada no es valida");
            }

            if (_clientes.ValidarClienteExiste(cliente.Identificacion))
            {
                ModelState.AddModelError("Identificacion",
                                         "Existe otro cliente con la identificación especificada");
            }

            try
            {
                if (ModelState.IsValid)
                {
                    _clientes.Registrar(cliente);
                    _clientes.GuardarCambios();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View(cliente));
        }
        public List <Factura> BuscarPorNombreCliente(string nombreIdentificacion)
        {
            List <Factura> facturas;

            if (ClientesUtils.EsCedulaValida(nombreIdentificacion))
            {
                facturas = _dbContext.Facturas
                           .Where(f => f.Identificacion == nombreIdentificacion)
                           .ToList();
            }
            else
            {
                facturas = _dbContext.Facturas
                           .Where(f => f.Cliente.Nombre.Contains(nombreIdentificacion))
                           .ToList();
            }

            return(facturas);
        }
        public List <Cliente> BuscarPorNombreIdentificacion(string nombreIdentificacion)
        {
            List <Cliente> clientes;

            // Si se especifico una cédula, buscamos por identificación.
            if (ClientesUtils.EsCedulaValida(nombreIdentificacion))
            {
                clientes = _dbContext.Clientes
                           .Where(c => c.Identificacion == nombreIdentificacion)
                           .ToList();
            }
            else
            {
                // Si no se especifico una cédula, buscamos por nombre.
                clientes = _dbContext.Clientes
                           .Where(c => c.Nombre.Contains(nombreIdentificacion))
                           .ToList();
            }

            return(clientes);
        }