Пример #1
0
        public IActionResult Save([FromBody] EmpleadoViewModel empViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var emp = MapperHelper <EmpleadoViewModel, Empleado> .ObjectTo(empViewModel);

                    emp.Estado = 1;
                    var ValidarEmpleado = _serv.getEmpleadoByNombre(emp.Nombres, emp.Apellidos);
                    if (ValidarEmpleado == null)
                    {
                        _serv.Save(emp, empViewModel.IdSucursal);
                    }
                    else
                    {
                        return(BadRequest("Empleado existente"));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(BadRequest());
            }

            return(Ok(true));
        }
Пример #2
0
        private void btnEmpleadoGuardar_Click(object sender, EventArgs e)
        {
            bool validaCedula(string pCedula)
            {
                int    vnTotal  = 0;
                string vcCedula = pCedula.Replace("-", "");
                int    pLongCed = vcCedula.Trim().Length;

                int[] digitoMult = new int[11] {
                    1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1
                };

                if (pLongCed < 11 || pLongCed > 11)
                {
                    return(false);
                }

                for (int vDig = 1; vDig <= pLongCed; vDig++)
                {
                    int vCalculo = Int32.Parse(vcCedula.Substring(vDig - 1, 1)) * digitoMult[vDig - 1];
                    if (vCalculo < 10)
                    {
                        vnTotal += vCalculo;
                    }
                    else
                    {
                        vnTotal += Int32.Parse(vCalculo.ToString().Substring(0, 1)) + Int32.Parse(vCalculo.ToString().Substring(1, 1));
                    }
                }

                if (vnTotal % 10 == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (txtEmpleadoNombre.Text == "" || txtEmpleadoApellido.Text == "" || txtEmpleadoCedula.Text == "" ||
                txtEmpleadoComision.Text == "" || txtEmpleadoUsuario.Text == "" || txtEmpleadoPass.Text == "")
            {
                MessageBox.Show("Llene los campos faltantes.",
                                "Datos necesarios vacios",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else if (validaCedula(txtEmpleadoCedula.Text) == false)
            {
                MessageBox.Show("Corrija su num de Cedula",
                                "Cedula Mal",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                DateTime today        = DateTime.Today;
                var      fechaIngreso = lblEmpleadoIngreso.Text;

                // Estado de disponibilidad
                bool estado;
                if (ckbEmpleadoEstado.Checked)
                {
                    estado = true;
                }
                else
                {
                    estado = false;
                }


                var empleado = new Data.Entidades.Empleado
                {
                    Id                = lblEmpleadoId.Text == "Empleado ID" ? 0 : Convert.ToInt32(lblEmpleadoId.Text),
                    Nombre            = txtEmpleadoNombre.Text,
                    Apellido          = txtEmpleadoApellido.Text,
                    Cedula            = txtEmpleadoCedula.Text,
                    PorcientoComision = Convert.ToDecimal(txtEmpleadoComision.Text),
                    Usuario           = txtEmpleadoUsuario.Text,
                    Pass              = txtEmpleadoPass.Text,
                    Cargo             = chkClienteAdmin.Checked,
                    FechaIngreso      = today.Date,
                    TandaLaborId      = Convert.ToInt32(cbEmpleadoTanda.SelectedValue),
                    Activo            = estado
                };

                _empleadoService.Save(empleado);
                MessageBox.Show("El empleado a sido agregado satisfactoriamente",
                                "Empeado agregado",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            if (lblEmpleadoId.Text == "Empleado ID")
            {
                txtEmpleadoNombre.Text        = "";
                txtEmpleadoApellido.Text      = "";
                txtEmpleadoCedula.Text        = "";
                txtEmpleadoUsuario.Text       = "";
                txtEmpleadoPass.Text          = "";
                txtEmpleadoComision.Text      = "";
                chkClienteAdmin.Checked       = false;
                cbEmpleadoTanda.SelectedIndex = 0;
                ckbEmpleadoEstado.Checked     = true;
            }
            else
            {
                Dispose();
                var empleadoLista = new EmpleadoLista();
                empleadoLista.Show();
            }
        }