BL.Security.getCentrosPermitidos C# (CSharp) Method

getCentrosPermitidos() public method

public getCentrosPermitidos ( string username ) : List
username string
return List
        public List<string> getCentrosPermitidos(string username)
        {
            //TODO: hacer que esta funcion devuelva los centros permitidos para editar por el username
            try
            {
                List<string> centros = new List<string>();

                /*var allcentros = from c in entidad.centros
                                 select c.lugar;

                centros = allcentros.ToList();
                return centros;*/

                var query = (from u in entidad.usuarios
                          where u.username == username
                          select u).First();

                foreach (role rol in query.roles)
                {
                    if(!centros.Contains(rol.centro1.lugar))
                        centros.Add(rol.centro1.lugar);
                }

                return centros;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString() + "  --Security.cs / getCentrosPermitidos()");
            }
        }

Usage Example

 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         SetFocus(searchBtn);
         if (!IsPostBack)
         {
             Security sec = new Security();
             centrosPermitidos.DataSource = sec.getCentrosPermitidos(Session["nombre_usuario"].ToString());
             centrosPermitidos.DataBind();
         }
     }
     catch (Exception ex)
     {
         Session["Error_Msg"] = ex.Message;
         Response.Redirect("~/Error.aspx", true);
     }
 }
All Usage Examples Of BL.Security::getCentrosPermitidos