Ejemplo n.º 1
0
    protected void EntityDataSourceItems_Updating(object sender, EntityDataSourceChangingEventArgs e)
    {
        Entidades.Plantilla ItemPlantilla = (Entidades.Plantilla)e.Entity;

        long id = Convert.ToInt64(ViewState["IdRol"]);

        IEnumerable <KeyValuePair <string, object> > entityKeyValues =
            new KeyValuePair <string, object>[] {
            new KeyValuePair <string, object>("IdSegRol", id)
        };

        System.Data.EntityKey key  = new System.Data.EntityKey("EntidadesConosud.SegRol", entityKeyValues);
        Entidades.SegRol      _rol = (Entidades.SegRol)e.Context.GetObjectByKey(key);
        ItemPlantilla.RolesPlanilla.Load();

        if (ItemPlantilla.RolesPlanilla.Count == 0)
        {
            Entidades.RolesPlanilla rolP = new Entidades.RolesPlanilla();
            rolP.Plantilla = ItemPlantilla;
            rolP.SegRol    = _rol;
            e.Context.AddObject("EntidadesConosud.RolesPlanilla", rolP);
        }
        else
        {
            ItemPlantilla.RolesPlanilla.First().SegRol = _rol;
        }

        e.Context.SaveChanges();
    }
    protected void gvRoles_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
        {
            Entidades.SegRol rol = (Entidades.SegRol)e.Item.DataItem;

            int exist = (from M in (Session["RolesAsignados"] as List <Entidades.SegUsuarioRol>)
                         where M.SegRol.IdSegRol == rol.IdSegRol
                         select M).Count();

            if (exist > 0)
            {
                (e.Item.FindControl("chkSeleccion") as CheckBox).Checked = true;
            }
        }
    }
Ejemplo n.º 3
0
    protected void btnAsignar_Click(object sender, EventArgs e)
    {
        Entidades.EntidadesConosud dcAux = new Entidades.EntidadesConosud();

        long idRol = long.Parse(Request.QueryString["IdRol"].ToString());

        Entidades.SegRol CurrentRol = (from M in dcAux.SegRol
                                       where M.IdSegRol == idRol
                                       select M).First <Entidades.SegRol>();

        List <Entidades.SegRolMenu> MenuEliminar = (from M in dcAux.SegRolMenu
                                                    where M.SegRol.IdSegRol == idRol
                                                    select M).ToList <Entidades.SegRolMenu>();

        foreach (Entidades.SegRolMenu item in MenuEliminar)
        {
            dcAux.DeleteObject(item);
        }
        dcAux.SaveChanges();



        foreach (GridDataItem item in gvSubContratistas.Items)
        {
            if ((item.FindControl("chkSeleccion") as CheckBox).Checked)
            {
                long idMenu = long.Parse(gvSubContratistas.Items[item.DataSetIndex].GetDataKeyValue("IdSegMenu").ToString());
                Entidades.SegMenu CurrentMenu = (from M in dcAux.SegMenu
                                                 where M.IdSegMenu == idMenu
                                                 select M).First <Entidades.SegMenu>();


                Entidades.SegRolMenu segMenu = new Entidades.SegRolMenu();
                segMenu.SegMenu      = CurrentMenu;
                segMenu.SegRol       = CurrentRol;
                segMenu.Creacion     = (item.FindControl("chkCreacion") as CheckBox).Checked;
                segMenu.Modificacion = (item.FindControl("chkModificacion") as CheckBox).Checked;
                segMenu.Lectura      = (item.FindControl("chkLectura") as CheckBox).Checked;


                dcAux.AddObject("EntidadesConosud.SegRolMenu", segMenu);
            }
        }

        dcAux.SaveChanges();
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "ocultar", "CloseWindows();", true);
    }
    protected void btnAsignar_Click(object sender, EventArgs e)
    {
        Entidades.EntidadesConosud dcAux = new Entidades.EntidadesConosud();

        long idUsuario = long.Parse(Request.QueryString["IdUsuario"].ToString());

        Entidades.SegUsuario CurrentUsuario = (from M in dcAux.SegUsuario
                                               where M.IdSegUsuario == idUsuario
                                               select M).First <Entidades.SegUsuario>();


        List <Entidades.SegUsuarioRol> rolesEliminar = (from M in dcAux.SegUsuarioRol
                                                        where M.SegUsuario.IdSegUsuario == idUsuario
                                                        select M).ToList <Entidades.SegUsuarioRol>();

        foreach (Entidades.SegUsuarioRol item in rolesEliminar)
        {
            dcAux.DeleteObject(item);
        }
        dcAux.SaveChanges();



        foreach (GridDataItem item in gvRoles.Items)
        {
            if ((item.FindControl("chkSeleccion") as CheckBox).Checked)
            {
                long idRol = long.Parse(gvRoles.Items[item.DataSetIndex].GetDataKeyValue("IdSegRol").ToString());

                Entidades.SegRol CurrentRol = (from M in dcAux.SegRol
                                               where M.IdSegRol == idRol
                                               select M).First <Entidades.SegRol>();


                Entidades.SegUsuarioRol segRol = new Entidades.SegUsuarioRol();
                segRol.SegRol     = CurrentRol;
                segRol.SegUsuario = CurrentUsuario;


                dcAux.AddObject("EntidadesConosud.SegUsuarioRol", segRol);
            }
        }

        dcAux.SaveChanges();
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "ocultar", "CloseWindows();", true);
    }