Exemplo n.º 1
0
        public Vacacion retornarObjetoVacacion(String identificacion)
        {
            //abrir conexion
            ConexionBD conexion = new ConexionBD();

            conexion.abrirConexion();
            Vacacion v        = new Vacacion();
            string   consulta = "SELECT * FROM VACACION WHERE IDENTIFICACION =" + identificacion;

            try
            {
                SqlCommand    comando = new SqlCommand(consulta, conexion.conn); //crea el comando, pero aun no ejecuta
                SqlDataReader lector  = comando.ExecuteReader();                 //lee los datos provenientes de la consulta y los guarda en lector
                while (lector.Read())
                {
                    v = new Vacacion(lector.GetValue(0).ToString(), Convert.ToDateTime(lector.GetValue(1)), Convert.ToDateTime(lector.GetValue(2)));
                }
                conexion.cerrarConexion();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error al ejecutar la consulta");
            }
            return(v);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,EmpleadoId,Desde,Hasta,AnioCorrespondiente,Completa,Comentarios")] Vacacion vacacion)
        {
            if (id != vacacion.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vacacion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VacacionExists(vacacion.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmpleadoId"] = new SelectList(_context.Empleados, "Id", "Apellido", vacacion.EmpleadoId);
            return(View(vacacion));
        }
Exemplo n.º 3
0
        public void Inicializado()
        {
            empleadoDA = new EmpleadoDA();
            vacacionDA = new VacacionDA();
            empleado   = new Empleado();
            vacacion   = new Vacacion();


            tablaEmpleados            = empleadoDA.ListarEmpleadosActivos();
            cmbEmpleado.DataSource    = tablaEmpleados;
            cmbEmpleado.DisplayMember = "Nombres_apellidos";
            cmbEmpleado.ValueMember   = "IdEmpleado";

            cmbEmpleado.SelectedIndex = -1;


            dtpFechaInicio.Value = DateTime.Now;
            dtpFechaFin.MinDate  = DateTime.Now;
            //cmbEmpleado.SelectedIndex = 0;

            //int i = cmbEmpleado.SelectedIndex;

            //int idEmpleado = Convert.ToInt32(tablaEmpleados.Rows[i]["idEmpleado"].ToString());
            //txtNroDocumento.Text = tablaEmpleados.Rows[i]["nroDocumento"].ToString();
            //txtFechaIngreso.Text = tablaEmpleados.Rows[i]["fechaIngreso"].ToString();
            //txtSaldo.Text = tablaEmpleados.Rows[i]["saldo"].ToString();
        }
Exemplo n.º 4
0
        //
        // GET: /Vacaciones/Edit/5

        public ActionResult Edit(int id)
        {
            Vacacion vacacion = db.Vacaciones.Find(id);

            ViewBag.IdPersonalInterno = new SelectList(db.PersonalesInternos, "IdPersonalInterno", "ApellidoMaterno", vacacion.IdPersonalInterno);
            return(View(vacacion));
        }
Exemplo n.º 5
0
        public ActionResult Create(Vacacion vacacion)
        {
            List <Actividad> actividades = db.Actividades.Where(a => a.IdPersonalInterno == vacacion.IdPersonalInterno).OrderByDescending(a => a.FechaFin).ToList();

            if (DateTime.Compare(vacacion.FechaInicio, actividades[0].FechaFin) <= 0)
            {
                string error = "La fecha mínima de salida es: " + actividades[0].FechaFin.AddDays(1).ToShortDateString();
                ModelState.AddModelError("FechaInicio", error);
            }
            if (vacacion.Periodo > 20)
            {
                string error = "El periodo máximo de vacaciones es 20 días";
                ModelState.AddModelError("Periodo", error);
            }
            if (vacacion.Periodo <= 5)
            {
                string error = "El periodo mínimo de vacaciones es 5 días";
                ModelState.AddModelError("Periodo", error);
            }
            if (ModelState.IsValid)
            {
                vacacion.FechaFin = vacacion.FechaInicio.AddDays(vacacion.Periodo);
                vacacion.Estado   = "Aprobado";
                vacacion.Anho     = vacacion.FechaFin.Year;

                db.Vacaciones.Add(vacacion);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdPersonalInterno = new SelectList(db.PersonalesInternos, "IdPersonalInterno", "ApellidoMaterno", vacacion.IdPersonalInterno);
            return(View(vacacion));
        }
Exemplo n.º 6
0
        public ActionResult Create(Vacacion vacacion)
        {
            List<Actividad> actividades = db.Actividades.Where(a => a.IdPersonalInterno == vacacion.IdPersonalInterno).OrderByDescending(a=>a.FechaFin).ToList();
            if (DateTime.Compare(vacacion.FechaInicio,actividades[0].FechaFin)<=0)
            {
                string error = "La fecha mínima de salida es: " + actividades[0].FechaFin.AddDays(1).ToShortDateString();
                ModelState.AddModelError("FechaInicio", error);
            }
            if (vacacion.Periodo > 20)
            {
                string error = "El periodo máximo de vacaciones es 20 días";
                ModelState.AddModelError("Periodo", error);
            }
            if (vacacion.Periodo <= 5)
            {
                string error = "El periodo mínimo de vacaciones es 5 días";
                ModelState.AddModelError("Periodo", error);
            }
            if (ModelState.IsValid)
            {
                vacacion.FechaFin = vacacion.FechaInicio.AddDays(vacacion.Periodo);
                vacacion.Estado = "Aprobado";
                vacacion.Anho = vacacion.FechaFin.Year;

                db.Vacaciones.Add(vacacion);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.IdPersonalInterno = new SelectList(db.PersonalesInternos, "IdPersonalInterno", "ApellidoMaterno", vacacion.IdPersonalInterno);
            return View(vacacion);
        }
Exemplo n.º 7
0
        private List <int> validar_cambios(Vacacion vacacion)
        {
            List <Int32> lista = new List <Int32>();

            if (!(vacacion.Fecha_Salida == this.vacacion.Fecha_Salida))
            {
                lista.Add(0);
            }
            if (!(vacacion.Fecha_Regreso == this.vacacion.Fecha_Regreso))
            {
                lista.Add(1);
            }
            if (!(vacacion.Numero_Dias == this.vacacion.Numero_Dias))
            {
                lista.Add(2);
            }
            if (!(vacacion.Salario == this.vacacion.Salario))
            {
                lista.Add(3);
            }
            if (vacacion.Estado != this.vacacion.Estado)
            {
                lista.Add(4);
            }
            return(lista);
        }
Exemplo n.º 8
0
        public int InsertarVacacion(Vacacion vacacion, string usuario)
        {
            parametrosEntrada    = new MySqlParameter[10];
            parametrosEntrada[0] = new MySqlParameter("@_idEmpleado", MySqlDbType.Int32);
            parametrosEntrada[1] = new MySqlParameter("@_mes", MySqlDbType.Int32);
            parametrosEntrada[2] = new MySqlParameter("@_ano", MySqlDbType.Int32);
            parametrosEntrada[3] = new MySqlParameter("@_cantDias", MySqlDbType.Int32);
            parametrosEntrada[4] = new MySqlParameter("@_fechaInicio", MySqlDbType.Date);
            parametrosEntrada[5] = new MySqlParameter("@_fechaFin", MySqlDbType.Date);
            parametrosEntrada[6] = new MySqlParameter("@_observacion", MySqlDbType.VarChar, 3000);
            parametrosEntrada[7] = new MySqlParameter("@_estado", MySqlDbType.Int32);
            parametrosEntrada[8] = new MySqlParameter("@_usuario_ins", MySqlDbType.VarChar, 100);
            parametrosEntrada[9] = new MySqlParameter("@_idVacacion", MySqlDbType.Int32);

            parametrosEntrada[0].Value = vacacion.IdEmpleado;
            parametrosEntrada[1].Value = vacacion.Mes;
            parametrosEntrada[2].Value = vacacion.Ano;
            parametrosEntrada[3].Value = vacacion.Dias;
            parametrosEntrada[4].Value = vacacion.FechaInicio;
            parametrosEntrada[5].Value = vacacion.FechaFin;
            parametrosEntrada[6].Value = vacacion.Observacion;
            parametrosEntrada[7].Value = 1;
            parametrosEntrada[8].Value = usuario;

            string[] datosSalida = new string[1];

            objManager.EjecutarProcedureConDatosDevueltos(parametrosEntrada, "insert_vacacion",
                                                          9, 10, out datosSalida, 1);

            if (datosSalida != null)
            {
                vacacion.IdVacacion = Convert.ToInt32(datosSalida[0]);
            }
            return(vacacion.IdVacacion);
        }
Exemplo n.º 9
0
        public void CargarData()
        {
            try
            {
                vacacionDA    = new VacacionDA();
                vacacion      = new Vacacion();
                tablaEmpleado = vacacionDA.ListarVacaciones();


                dgvVacaciones.DataSource = tablaEmpleado;
                vista.OptionsBehavior.AutoPopulateColumns = false;
                vista.OptionsSelection.MultiSelect        = true;
                dgvVacaciones.Refresh();

                usuario  = vacacionDA.ObtenerPerfil(this.idUsuario);
                idPerfil = int.Parse(usuario.Rows[0]["perfil"].ToString());
                if (idPerfil == idPerfilAnular)
                {
                    this.Anular.Visible = true;
                }
                else
                {
                    this.Anular.Visible = false;
                    //this.FechaUltimaFactura.Width = 140;
                    //this.FechaCorteAlquiler.Width = 140;
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message); OMITIMOS EL MENSAJE
            }
        }
Exemplo n.º 10
0
 //
 // GET: /Vacaciones/Create
 public ActionResult Create()
 {
     ViewBag.IdPersonalInterno = new SelectList(db.PersonalesInternos, "IdPersonalInterno", "ApellidoPaterno");
     Vacacion vacacion = new Vacacion();
     vacacion.FechaInicio = DateTime.Today;
     return View(vacacion);
 }
Exemplo n.º 11
0
        public Boolean eliminar_sys()
        {
            if (existen_registros())
            {
                Int32  id     = Int32.Parse(dg_vacaciones.CurrentRow.Cells["Id"].Value.ToString());
                String nombre = dg_vacaciones.CurrentRow.Cells["Nombre"].Value.ToString() + " " + dg_vacaciones.CurrentRow.Cells["Apellidos"].Value.ToString();

                DialogResult dialogResult = MessageBox.Show("¿Desea establecer como inactiva la vacación del colaborador " + nombre + " ?", "Inactivo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    Vacacion vacacion = new Vacacion();
                    vacacion.Id     = id;
                    vacacion.Estado = false;
                    if (vacacion.eliminar())
                    {
                        MessageBox.Show("Vacación inactiva", "Excelente!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return(true);
                    }
                    else
                    {
                        MessageBox.Show("Ocurrió un error", "Ups!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }
                return(false);
            }
            return(false);
        }
Exemplo n.º 12
0
        //
        // GET: /Vacaciones/Create

        public ActionResult Create()
        {
            ViewBag.IdPersonalInterno = new SelectList(db.PersonalesInternos, "IdPersonalInterno", "ApellidoPaterno");
            Vacacion vacacion = new Vacacion();

            vacacion.FechaInicio = DateTime.Today;
            return(View(vacacion));
        }
Exemplo n.º 13
0
 private void btnCancelar_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Estas seguro que deseas cancelar el proceso", "◄ AVISO | LEASEIN ►", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
     {
         estadoComponentes(TipoVista.Limpiar);
         vacacion = new Vacacion();
     }
 }
Exemplo n.º 14
0
        public ActionResult DeleteConfirmed(int id)
        {
            Vacacion vacacion = db.Vacacions.Find(id);

            db.Vacacions.Remove(vacacion);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 15
0
 public Vacaciones_Agregar(Vacacion vacacion)
 {
     InitializeComponent();
     this.vacacion       = vacacion;
     colaborador         = new Colaborador();
     lista_colaboradores = colaborador.obtener_lista_activos();
     setear_datos();
     rb_activo.Checked = true;
 }
Exemplo n.º 16
0
        public static Vacacion GetVacacionById(int pk)
        {
            List <Vacacion> listadeVacaciones = new List <Vacacion>();

            OnTime.DAL.VacacionesDSTableAdapters.VacacionesTableAdapter objDataSet = new OnTime.DAL.VacacionesDSTableAdapters.VacacionesTableAdapter();
            VacacionesDS.VacacionesDataTable dtVacacion = objDataSet.GetVacacionByID(pk);
            Vacacion objVacacion = rowToDto(dtVacacion[0]);

            return(objVacacion);
        }
Exemplo n.º 17
0
        public ActionResult Edit(Vacacion vacacion)
        {
            if (ModelState.IsValid)
            {
                objsBs.Update(vacacion);
                return(RedirectToAction("Index", "Vacacion", new { area = "Admin" }));
            }

            return(View());
        }
Exemplo n.º 18
0
        public ActionResult Create(Vacacion vacacion)
        {
            HttpCookie authCookie            = Request.Cookies[FormsAuthentication.FormsCookieName];
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
            string name = ticket.Name;

            vacacion.fkAutorizacion = Convert.ToInt32(name);
            VacacionBLL.InsertObjetoVacacion(vacacion);
            return(RedirectToAction("Index", "Vacaciones"));
        }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "Id_Vacacion,Id_Empleado,Inicio_Vacaciones,Fin_Vacaciones,Año,Comentario")] Vacacion vacacion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vacacion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id_Empleado = new SelectList(db.Empleados, "Id_Empleado", "Nombre_Empleado", vacacion.Id_Empleado);
     return(View(vacacion));
 }
Exemplo n.º 20
0
 public Vacaciones_Agregar()
 {
     InitializeComponent();
     vacacion    = new Vacacion();
     colaborador = new Colaborador();
     llenar_cb_colaboradores();
     lb_cantidad_dias.Text = "0";
     rb_activo.Checked     = true;
     editar = false;
     //setear_fechas_Y_salario();
 }
Exemplo n.º 21
0
        public static Vacacion rowToDto(VacacionesDS.VacacionesRow row)
        {
            Vacacion objVacacion = new Vacacion();

            objVacacion.pkVacacion      = row.pkVacacion;
            objVacacion.dateFechaInicio = row.dateFechaInicio;
            objVacacion.dateFechaFin    = row.dateFechaFin;
            objVacacion.fkEmpleado      = row.fkEmpleado;
            objVacacion.fkAutorizacion  = row.fkAutorizacion;

            return(objVacacion);
        }
        public async Task <IActionResult> Create([Bind("Id,EmpleadoId,Desde,Hasta,AnioCorrespondiente,Completa,Comentarios")] Vacacion vacacion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vacacion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmpleadoId"] = new SelectList(_context.Empleados, "Id", "Apellido", vacacion.EmpleadoId);
            return(View(vacacion));
        }
Exemplo n.º 23
0
        public void actualizarVacacion(Vacacion v)
        {
            ConexionBD conexion = new ConexionBD();
            SqlCommand comm     = new SqlCommand();

            comm.Connection  = conexion.abrirConexion();
            comm.CommandText = "sp_ActualizarVacacion";
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.AddWithValue("@IDENTIFICACION", v.IdentificacionPersonalV);
            comm.Parameters.AddWithValue("@FECHA_INICIO", v.FechaInicioVacaciones);
            comm.Parameters.AddWithValue("@FECHA_FIN", v.FechaFinVacaciones);
            comm.ExecuteNonQuery();
        }
Exemplo n.º 24
0
        public Vacacion validarPeriodoVacaciones(Vacacion vacacionPropuesta, EFDbContext db)
        {
            List<Actividad> actividades = db.Actividades.Where(a => a.IdPersonalInterno == vacacionPropuesta.IdPersonalInterno).OrderByDescending(a=>a.FechaFin).ToList();
            if (DateTime.Compare(vacacionPropuesta.FechaInicio, actividades[0].FechaFin) > 0)
            {
                return vacacionPropuesta;
            }
            else
            {

            }
            return null;
        }
Exemplo n.º 25
0
        public Vacacion obtener()
        {
            Vacacion vacacion = new Vacacion();
            Int32    id       = Int32.Parse(dg_vacaciones.CurrentRow.Cells["Id"].Value.ToString());

            foreach (Vacacion x in lista)
            {
                if (x.Id == id)
                {
                    vacacion = x;
                }
            }
            return(vacacion);
        }
Exemplo n.º 26
0
        public static List <Vacacion> SelectAll()
        {
            List <Vacacion> listadeVacaciones = new List <Vacacion>();

            OnTime.DAL.VacacionesDSTableAdapters.VacacionesTableAdapter objDataSet = new OnTime.DAL.VacacionesDSTableAdapters.VacacionesTableAdapter();
            VacacionesDS.VacacionesDataTable dtVacacion = objDataSet.GetAllVacaciones();

            foreach (VacacionesDS.VacacionesRow row in dtVacacion)
            {
                Vacacion objVacacion = rowToDto(row);
                listadeVacaciones.Add(objVacacion);
            }
            return(listadeVacaciones);
        }
Exemplo n.º 27
0
        // GET: Vacaciones/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Vacacion vacacion = db.Vacacions.Find(id);

            if (vacacion == null)
            {
                return(HttpNotFound());
            }
            return(View(vacacion));
        }
Exemplo n.º 28
0
        public static List <Vacacion> GetVacacionesByIdEmpleaso(int empleado)
        {
            List <Vacacion> listadeVacaciones = new List <Vacacion>();

            OnTime.DAL.VacacionesDSTableAdapters.VacacionesTableAdapter objDataSet = new OnTime.DAL.VacacionesDSTableAdapters.VacacionesTableAdapter();
            VacacionesDS.VacacionesDataTable dtVacacion = objDataSet.GetVacacionByIdEmpleado(empleado);

            foreach (VacacionesDS.VacacionesRow row in dtVacacion)
            {
                Vacacion objVacacion = rowToDto(row);
                listadeVacaciones.Add(objVacacion);
            }
            return(listadeVacaciones);
        }
Exemplo n.º 29
0
        // GET: Vacaciones/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Vacacion vacacion = db.Vacacions.Find(id);

            if (vacacion == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Id_Empleado = new SelectList(db.Empleados, "Id_Empleado", "Nombre_Empleado", vacacion.Id_Empleado);
            return(View(vacacion));
        }
Exemplo n.º 30
0
 //Muestra mensaje de confirmnacion si la vacacion fue agregado con exito ó mensaje de error en el caso contrario.
 public Boolean agregar_sys()
 {
     vacacion = obtener_datos();
     if (vacacion.agregar())
     {
         buscar_colaborador(Convert.ToInt32(cb_colaborador.SelectedValue));
         colaborador.reducir_vacaciones(Convert.ToInt32(lb_cantidad_dias.Text) + colaborador.Vacaciones);
         MessageBox.Show("La vacación fue agregada con éxito", "Excelente!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(true);
     }
     else
     {
         MessageBox.Show("Ocurrió un error", "Ups!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }
Exemplo n.º 31
0
        private void cmbEmpleado_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = cmbEmpleado.SelectedIndex;

            if (i >= 0) //Esto verifica que se ha seleccionado algún item del comboBox
            {
                vacacion = new Vacacion();
                int idEmpleado = Convert.ToInt32(tablaEmpleados.Rows[i]["IdEmpleado"].ToString());
                txtNroDocumento.Text = tablaEmpleados.Rows[i]["nroDocumento"].ToString();
                DateTime aux = Convert.ToDateTime(tablaEmpleados.Rows[i]["fechaIngreso"].ToString());
                txtFechaIngreso.Text = aux.ToString("dd/MM/yyyy");
                txtSaldo.Text        = tablaEmpleados.Rows[i]["saldo"].ToString();
                vacacion.IdEmpleado  = idEmpleado;
            }
            else
            {
                txtNroDocumento.Text = "";
                txtFechaIngreso.Text = "";
                txtSaldo.Text        = "";
            }
        }
Exemplo n.º 32
0
        //verifica 30 dias por ley
        public int insertarVacacion(Vacacion v)
        {
            ConexionBD conexion = new ConexionBD();
            SqlCommand comm     = new SqlCommand();

            comm.Connection  = conexion.abrirConexion();
            comm.CommandText = "sp_InsertarVacacion";
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.AddWithValue("@IDENTIFICACION", v.IdentificacionPersonalV);
            comm.Parameters.AddWithValue("@FECHA_INICIO", v.FechaInicioVacaciones);
            comm.Parameters.AddWithValue("@FECHA_FIN", v.FechaFinVacaciones);
            //obtener parametro de retorno
            comm.Parameters.Add("@VERIFICACION", System.Data.SqlDbType.Int).Direction = System.Data.ParameterDirection.Output;
            comm.ExecuteNonQuery();
            int retornoProcedure = Convert.ToInt32(comm.Parameters["@VERIFICACION"].Value);

            Console.WriteLine(retornoProcedure);
            if (retornoProcedure != 1)
            {
                MessageBox.Show("Ha sobrepasado el límite de 30 días de vacaciones para el año actual");
            }
            return(retornoProcedure);
        }
Exemplo n.º 33
0
        //verifica que no pueda ingresar en el intervalo de otra vacacion
        public int verificarFechaParaVacacion(Vacacion v)
        {
            ConexionBD conexion = new ConexionBD();
            SqlCommand comm     = new SqlCommand();

            comm.Connection  = conexion.abrirConexion();
            comm.CommandText = "sp_consultarFechaInicioVacacion";
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.AddWithValue("@FECHA_INICIO", v.FechaInicioVacaciones);
            comm.Parameters.AddWithValue("@FECHA_FIN", v.FechaFinVacaciones);
            comm.Parameters.AddWithValue("@IDENTIFICACION", v.IdentificacionPersonalV);
            //obtener parametro de retorno
            comm.Parameters.Add("@VERIFICACION", System.Data.SqlDbType.Int).Direction = System.Data.ParameterDirection.Output;
            comm.ExecuteNonQuery();
            int retornoProcedure = Convert.ToInt32(comm.Parameters["@VERIFICACION"].Value);

            Console.WriteLine(retornoProcedure);
            if (retornoProcedure != 0)
            {
                MessageBox.Show("No puede guardar una nueva vacación dentro del periodo de otra vacación");
            }
            return(retornoProcedure);
        }
Exemplo n.º 34
0
 public ActionResult Edit(Vacacion vacacion)
 {
     if (vacacion.Periodo > 20)
     {
         string error = "El periodo máximo de vacaciones es 20 días";
         ModelState.AddModelError("Periodo", error);
     }
     if (vacacion.Periodo <= 5)
     {
         string error = "El periodo mínimo de vacaciones es 5 días";
         ModelState.AddModelError("Periodo", error);
     }
     if (ModelState.IsValid)
     {
         vacacion.FechaFin = vacacion.FechaInicio.AddDays(vacacion.Periodo);
         vacacion.Estado = "Aprobado";
         vacacion.Anho = vacacion.FechaFin.Year;
         db.Entry(vacacion).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.IdPersonalInterno = new SelectList(db.PersonalesInternos, "IdPersonalInterno", "ApellidoMaterno", vacacion.IdPersonalInterno);
     return View(vacacion);
 }