Exemplo n.º 1
0
        public string Borrar(roles_proyecto entidad)
        {
            try
            {
                if (ExistRolenUso(entidad))
                {
                    return("Este Rol esta siendo utilizado en un proyecto, por lo que NO PODRA SER ELIMINADO.");
                }
                else
                {
                    Model          context = new Model();
                    roles_proyecto rol     = context.roles_proyecto
                                             .First(i => i.id_rol == entidad.id_rol);
                    rol.usuario_borrado     = entidad.usuario_borrado;
                    rol.comentarios_borrado = entidad.comentarios_borrado;
                    rol.fecha_borrado       = DateTime.Now;
                    context.SaveChanges();
                    return("");
                }
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                return(fullErrorMessage.ToString());
            }
        }
Exemplo n.º 2
0
        public string Editar(roles_proyecto entidad)
        {
            try
            {
                Model          context = new Model();
                roles_proyecto rol     = context.roles_proyecto
                                         .First(i => i.id_rol == entidad.id_rol);
                rol.rol                 = entidad.rol;
                rol.nivel               = entidad.nivel;
                rol.responsabilidades   = entidad.responsabilidades;
                rol.fecha_borrado       = null;
                rol.usuario_borrado     = null;
                rol.comentarios_borrado = null;
                rol.usuario_edicion     = entidad.usuario_edicion;
                context.SaveChanges();
                return("");
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                return(fullErrorMessage.ToString());
            }
        }
 private void CargarRoles()
 {
     try
     {
         roles_proyecto entidad  = new roles_proyecto();
         RolesCOM       roles    = new RolesCOM();
         DataTable      dt_roles = roles.Get(entidad);
         grid_roles.DataSource = dt_roles;
         grid_roles.DataBind();
     }
     catch (Exception ex)
     {
         Toast.Error(ex.Message, this);
     }
 }
Exemplo n.º 4
0
        public DataTable Get(proyectos_involucrados entidad)
        {
            DataTable dt = new DataTable();

            try
            {
                Model context = new Model();
                var   query   = context.proyectos_involucrados
                                .Where(s => s.id_pinvolucrado == entidad.id_pinvolucrado & s.usuario_borrado == null)
                                .Select(u => new
                {
                    u.id_pinvolucrado,
                    u.id_proyecto,
                    u.celular,
                    u.id_rol,
                    u.nombre,
                    u.no_empleado,
                    u.telefono,
                    u.correo,
                    u.usuario,
                    u.fecha_registro,
                    u.usuario_edicion,
                    u.fecha_edicion,
                    u.usuario_borrado,
                    u.fecha_borrado,
                    u.comentarios_borrado
                });
                dt = To.DataTable(query.ToList());
                dt.Columns.Add("rol");
                foreach (DataRow row in dt.Rows)
                {
                    roles_proyecto entidadrol = new roles_proyecto();
                    entidadrol.id_rol = Convert.ToInt32(row["id_rol"]);
                    RolesCOM  roles    = new RolesCOM();
                    DataTable dt_roles = roles.Get(entidadrol);
                    if (dt_roles.Rows.Count > 0)
                    {
                        row["rol"] = dt_roles.Rows[0]["rol"].ToString();
                    }
                }
                return(dt);
            }
            catch (Exception ex)
            {
                return(dt);
            }
        }
 protected void lnkcommand_Click(object sender, EventArgs e)
 {
     try
     {
         LinkButton     lnk     = sender as LinkButton;
         string         command = lnk.CommandName;
         int            id_rol  = Convert.ToInt32(lnk.CommandArgument);
         roles_proyecto entidad = new roles_proyecto();
         entidad.id_rol = Convert.ToInt32(id_rol);
         entidad.comentarios_borrado = hdfmotivos.Value.Trim();
         entidad.usuario_borrado     = Session["usuario"] as string;
         RolesCOM roles = new RolesCOM();
         rtxtnivel.ReadOnly = false;
         if (command == "Editar")
         {
             DataTable dt_rol = roles.Get(entidad);
             txtid_rol.Text             = id_rol.ToString().Trim();
             rtxtnivel.Text             = dt_rol.Rows[0]["nivel"].ToString().Trim();
             rtxtresponsabilidades.Text = dt_rol.Rows[0]["responsabilidades"].ToString().Trim();
             rtxtrol.Text       = dt_rol.Rows[0]["rol"].ToString().Trim();
             rtxtnivel.ReadOnly = Convert.ToBoolean(dt_rol.Rows[0]["en_uso"]);
             ModalShow("#myModalEmpleados");
         }
         else
         {
             string vmensaje = roles.Borrar(entidad);
             if (vmensaje == "")
             {
                 System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(),
                                                                   "ModalClose();", true);
                 System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(),
                                                                   "AlertGO('Rol Eliminado Correctamente', 'catalogo_roles.aspx');", true);
             }
             else
             {
                 Toast.Error(vmensaje, this);
             }
         }
     }
     catch (Exception ex)
     {
         Toast.Error(ex.Message, this);
     }
 }
Exemplo n.º 6
0
        public Boolean Exist(roles_proyecto entidad)
        {
            DataTable dt = new DataTable();

            try
            {
                Model context = new Model();
                var   query   = context.roles_proyecto
                                .Where(s => s.rol.Trim().ToUpper() == entidad.rol.Trim().ToUpper() && s.usuario_borrado == null)
                                .Select(u => new
                {
                    u.id_rol
                });
                dt = To.DataTable(query.ToList());
                return(dt.Rows.Count > 0);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        public Boolean ExistRolenUso(roles_proyecto entidad)
        {
            DataTable dt = new DataTable();

            try
            {
                Model context = new Model();
                var   query   = context.proyectos_involucrados
                                .Where(s => s.id_rol == entidad.id_rol && s.usuario_borrado == null)
                                .Select(u => new
                {
                    u.id_rol
                });
                dt = To.DataTable(query.ToList());
                return(dt.Rows.Count > 0);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Obtiene los roles
        /// </summary>
        /// <param name="entidad"></param>
        /// <returns></returns>
        public DataTable Get(roles_proyecto entidad)
        {
            DataTable dt = new DataTable();

            try
            {
                Model context = new Model();
                var   query   = context.roles_proyecto
                                .Where(s => s.id_rol == (entidad.id_rol == 0 ? s.id_rol : entidad.id_rol) && s.usuario_borrado == null)
                                .Select(u => new
                {
                    u.id_rol,
                    u.rol,
                    u.nivel,
                    u.usuario,
                    u.responsabilidades,
                    u.fecha_registro,
                    u.usuario_borrado,
                    u.fecha_borrado,
                    u.usuario_edicion,
                    u.fecha_edicion
                })
                                .OrderBy(s => s.rol);
                dt = To.DataTable(query.ToList());
                dt.Columns.Add("en_uso");
                foreach (DataRow row in dt.Rows)
                {
                    roles_proyecto entidad_rol = new roles_proyecto();
                    entidad_rol.id_rol = Convert.ToInt32(row["id_rol"]);
                    row["en_uso"]      = ExistRolenUso(entidad_rol);
                }
                return(dt);
            }
            catch (Exception ex)
            {
                return(dt);
            }
        }
Exemplo n.º 9
0
        public string Agregar(roles_proyecto entidad)
        {
            try
            {
                if (Exist(entidad))
                {
                    return("Ya existe un rol con el nombre: " + entidad.rol);
                }
                else
                {
                    roles_proyecto rol = new roles_proyecto
                    {
                        rol = entidad.rol,
                        responsabilidades = entidad.responsabilidades,
                        nivel             = entidad.nivel,
                        fecha_registro    = DateTime.Now,
                        usuario           = entidad.usuario
                    };
                    Model context = new Model();
                    context.roles_proyecto.Add(rol);
                    context.SaveChanges();
                    return("");
                }
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                return(fullErrorMessage.ToString());
            }
        }
        private String EditarRol()
        {
            try
            {
                string vmensaje = "";
                if (rtxtrol.Text == "")
                {
                    vmensaje = "Escriba el Nombre del Rol";
                }
                else if (rtxtresponsabilidades.Text == "")
                {
                    vmensaje = "Escriba las Responsabilidades";
                }
                else if (Convert.ToInt32(rtxtnivel.Text == "" ? "0" : rtxtnivel.Text) == 0)
                {
                    vmensaje = "Indique un nivel mayor a 0(cero)";
                }
                else
                {
                    roles_proyecto entidad = new roles_proyecto();
                    entidad.id_rol            = Convert.ToInt32(txtid_rol.Text);
                    entidad.rol               = rtxtrol.Text.Trim();
                    entidad.responsabilidades = rtxtresponsabilidades.Text.Trim();
                    entidad.nivel             = Convert.ToByte(rtxtnivel.Text.Trim());
                    entidad.usuario_edicion   = Session["usuario"] as string;
                    RolesCOM roles = new RolesCOM();
                    vmensaje = roles.Editar(entidad);
                }


                return(vmensaje);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }