Esempio n. 1
0
        public List <EntRoles> ObtenerTodos()
        {
            List <EntRoles> Lista   = new List <EntRoles>();
            EntRoles        entidad = null;

            try
            {
                AbrirConexion();
                StringBuilder CadenaSql = new StringBuilder();
                var           sql       = "SELECT id_rol, desc_rol FROM informix.roles";
                IfxCommand    cmd       = new IfxCommand(sql, Conexion);
                using (var dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        entidad          = new EntRoles();
                        entidad.id_rol   = int.Parse(dr["id_rol"].ToString());
                        entidad.desc_rol = dr["desc_rol"].ToString();
                        Lista.Add(entidad);
                    }
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                CerrarConexion();
            }
            return(Lista);
        }
Esempio n. 2
0
        public EntRoles Obtener(int id)
        {
            EntRoles entidad = null;

            try
            {
                AbrirConexion();
                StringBuilder CadenaSql = new StringBuilder();

                IfxCommand cmd = new IfxCommand(string.Empty, Conexion);
                cmd.CommandText = "SELECT id_rol, desc_rol FROM informix.roles WHERE id_rol=?";
                cmd.Parameters.Add(new IfxParameter()).Value = id;
                using (var dr = cmd.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        entidad          = new EntRoles();
                        entidad.id_rol   = int.Parse(dr["id_rol"].ToString());
                        entidad.desc_rol = dr["desc_rol"].ToString();
                    }
                }
                #region GetRolVistas
                entidad.rolVistas = new List <EntRolesVista>();
                cmd.CommandText   = "SELECT id_rol_vista, id_rol, id_vista from roles_vista where id_rol=?";
                cmd.Parameters.Clear();
                cmd.Parameters.Add(new IfxParameter()).Value = id;
                using (var dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        EntRolesVista entRolVista = new EntRolesVista();
                        entRolVista.id_rol_vista = int.Parse(dr["id_rol_vista"].ToString());
                        entRolVista.id_rol       = int.Parse(dr["id_rol"].ToString());
                        entRolVista.id_vista     = int.Parse(dr["id_vista"].ToString());
                        entRolVista.selected     = true;
                        entidad.rolVistas.Add(entRolVista);
                    }
                }
                #endregion
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                CerrarConexion();
            }
            return(entidad);
        }
Esempio n. 3
0
        public ActionResult Guardar(EntRoles entidad)
        {
            var r = false;

            try
            {
                if (entidad.id_rol > 0)
                {
                    r = control.Actualizar(entidad);
                    ctrlRolesVista.Eliminar(entidad.id_rol);
                    foreach (EntRolesVista item in entidad.rolVistas)
                    {
                        ctrlRolesVista.Insertar(new EntRolesVista
                        {
                            id_rol   = entidad.id_rol,
                            id_vista = item.id_vista
                        });
                    }
                }
                else
                {
                    r = control.Insertar(entidad);
                    int id_rol = control.ObtenerTodos().ToList().Max(p => p.id_rol);
                    foreach (EntRolesVista item in entidad.rolVistas)
                    {
                        ctrlRolesVista.Insertar(new EntRolesVista
                        {
                            id_rol   = id_rol,
                            id_vista = item.id_vista
                        });
                    }
                }

                if (!r)
                {
                    return(Json("Error al realizar la operacion", JsonRequestBehavior.AllowGet));
                }

                return(Json("Realizado", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Roles", "Create")));
            }
        }
Esempio n. 4
0
        public bool Update(EntRoles entidad)
        {
            bool respuesta = false;

            try
            {
                AbrirConexion();
                var sql = "execute procedure dml_roles (?,?,?);";
                using (var cmd = new IfxCommand(sql, Conexion))
                {
                    cmd.Connection = Conexion;
                    cmd.Parameters.Add(new IfxParameter()).Value = "UPDATE";
                    cmd.Parameters.Add(new IfxParameter()).Value = entidad.id_rol;
                    cmd.Parameters.Add(new IfxParameter()).Value = entidad.desc_rol;
                    cmd.ExecuteNonQuery();
                }
                respuesta = true;
            }

            catch (InvalidCastException ex)
            {
                ApplicationException excepcion = new ApplicationException("Se genero un error con el siguiente mensaje: " + ex.Message, ex);
                excepcion.Source = "Update Roles";
                throw excepcion;
            }
            catch (Exception ex)
            {
                ApplicationException excepcion = new ApplicationException("Se genero un error de aplicación con el siguiente mensaje: " + ex.Message, ex);
                excepcion.Source = "Update Roles";
                throw excepcion;
            }
            finally
            {
                CerrarConexion();
            }
            return(respuesta);
        }
Esempio n. 5
0
 public bool Actualizar(EntRoles Entidad)
 {
     return(PerRoles.Update(Entidad));
 }
Esempio n. 6
0
 public bool Insertar(EntRoles Entidad)
 {
     return(PerRoles.Insert(Entidad));
 }