public static string GetAmbitoIdByName(string ambitoName)
        {
            string    path = System.Web.Hosting.HostingEnvironment.MapPath(FilePaths.AmbitiXML);
            XDocument root = AmbitiUtility.GetXmlDocument(path);

            string ambitoId = null;

            if (root != null)
            {
                ambitoId = (from f in root.Elements("ambiti").Elements("ambito").Elements("node")
                            where f.Value.Equals(ambitoName)
                            select f)
                           .Select(f => f.Parent.Attribute("id").Value).SingleOrDefault();
            }
            return(ambitoId);
        }
        public static string GetAmbitoRoleById(int ambitoId, List <string> roles)
        {
            string    path = System.Web.Hosting.HostingEnvironment.MapPath(FilePaths.RolesXML);
            XDocument root = AmbitiUtility.GetXmlDocument(path);

            string role = null;

            if (root != null)
            {
                role = root.Elements("ambiti").Elements("role")
                       .Where(r => r.Attributes("id").Any(x => roles.Contains(x.Value)))
                       .Where(r => r.Attribute("ambito").Value.Equals(ambitoId.ToString()))
                       .OrderByDescending(p => p.Attribute("priority").Value)
                       .Select(r => r.Value).FirstOrDefault();
            }

            return(role);
        }
        public static List <Ambiti> AssignAmbitoRoles(List <AmbitoRoles> AmbitoRoles)
        {
            List <Ambiti> AmbitoList = new List <Ambiti>();

            List <string> ambitiId = new List <string>();

            ambitiId = (from f in AmbitoRoles
                        select f.AmbitoId).ToList();

            AmbitoList = AmbitiUtility.GetAmbitoById(ambitiId);

            foreach (var ambito in AmbitoList)
            {
                string role = AmbitoRoles.Where(r => r.AmbitoId.Equals(ambito.Id)).Select(x => x.Role).SingleOrDefault().ToString();

                ambito.role = role;
            }

            return(AmbitoList);
        }