/// <summary>
        /// Elimina todas las filas de RuleInCategory y las agrega nuevamente.-
        /// Las que agrega son las que se mofificaron desde el front end u otro origen.-
        /// </summary>
        /// <param name="pFwkCategory"></param>
        /// <param name="applicationName">Nombre de la aplicacion. Coincide con CompanyId en la arquitectura</param>
        /// <param name="connectionStringName">Nombre de cadena de coneccion del archivo de configuracion.-</param>
        static void CreateRuleInCategory(FwkCategory pFwkCategory, string applicationName, string connectionStringName)
        {
            Guid id = GetApplication(applicationName, connectionStringName);

            try
            {
                StringBuilder str = new StringBuilder(FwkMembershipScripts.RulesInCategory_d);

                foreach (FwkAuthorizationRule rule in pFwkCategory.FwkRulesInCategoryList)
                {
                    str.Append(FwkMembershipScripts.RuleInCategory_i);
                    str.Replace("[RuleId]", rule.Id.ToString());
                }
                str.Replace("[CategoryId]", pFwkCategory.CategoryId.ToString());
                str.Replace("[ApplicationId]", id.ToString());

                using (SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString))
                    using (SqlCommand cmd = new SqlCommand(str.ToString(), cnn))
                    {
                        cmd.CommandType = CommandType.Text;

                        cmd.ExecuteNonQuery();
                    }
            }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(Fwk.Security.Properties.Resource.MembershipSecurityGenericError, ex);
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4000";
                throw te;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pFwkCategory"></param>
        /// <param name="connectionStringName">Nombre de cadena de coneccion del archivo de configuracion.-</param>
        /// <param name="applicationName">Nombre de la aplicacion. Coincide con CompanyId en la arquitectura</param>
        public static void CreateCategory(FwkCategory pFwkCategory, string applicationName, string connectionStringName)
        {
            try
            {
                Guid wApplicationId = GetApplication(applicationName, connectionStringName);


                StringBuilder str = new StringBuilder(FwkMembershipScripts.Category_i);


                str.Replace("[ApplicationId]", wApplicationId.ToString());
                if (pFwkCategory.ParentId == null)
                {
                    pFwkCategory.ParentId = 0;
                }
                str.Replace("[ParentCategoryId]", pFwkCategory.ParentId.ToString());
                str.Replace("[CategoryName]", pFwkCategory.Name.ToLower());


                using (SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString))
                    using (SqlCommand cmd = new SqlCommand(str.ToString(), cnn))
                    {
                        cmd.CommandType = CommandType.Text;

                        pFwkCategory.CategoryId = Convert.ToInt32(cmd.ExecuteScalar());
                    }



                if (pFwkCategory.FwkRulesInCategoryList != null)
                {
                    if (pFwkCategory.FwkRulesInCategoryList.Count != 0)
                    {
                        CreateRuleInCategory(pFwkCategory, applicationName.ToLower(), connectionStringName);
                    }
                }
            }
            catch (TechnicalException tx)
            { throw tx; }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(Fwk.Security.Properties.Resource.MembershipSecurityGenericError, ex);
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4000";
                throw te;
            }
        }
        /// <summary>
        /// Obtiene las Categorias de una determinada aplicacion. Recibe el Nombre de cadena de coneccion del archivo de configuracion.-
        /// </summary>
        /// <param name="applicationName">Nombre de la aplicacion. Coincide con CompanyId en la arquitectura</param>
        /// <param name="connectionStringName">Nombre de cadena de coneccion del archivo de configuracion.-</param>
        /// <returns></returns>
        public static FwkCategoryList GetAllCategories(string applicationName, string connectionStringName)
        {
            FwkCategory     wCategory;
            FwkCategoryList wCategoryList = null;

            try
            {
                Guid wApplicationId = GetApplication(applicationName, connectionStringName);
                using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString))
                {
                    var rulesinCat = from s in dc.aspnet_RulesCategories where s.ApplicationId == wApplicationId select s;

                    wCategoryList = new FwkCategoryList();
                    foreach (aspnet_RulesCategory aspnet_cat in rulesinCat.ToList <aspnet_RulesCategory>())
                    {
                        wCategory            = new FwkCategory();
                        wCategory.CategoryId = aspnet_cat.CategoryId;
                        if (aspnet_cat.ParentCategoryId != null)
                        {
                            wCategory.ParentId = aspnet_cat.ParentCategoryId;
                        }
                        wCategory.Name = aspnet_cat.Name;
                        wCategoryList.Add(wCategory);
                    }
                }

                foreach (FwkCategory category in wCategoryList)
                {
                    category.FwkRulesInCategoryList = GetFwkRules_By_Category(category.CategoryId, connectionStringName);
                }


                return(wCategoryList);
            }
            catch (TechnicalException tx)
            { throw tx; }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(Fwk.Security.Properties.Resource.MembershipSecurityGenericError, ex);
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4000";
                throw te;
            }
        }
        /// <summary>
        /// Obtiene las subcategorias de una categoria.-
        /// </summary>
        /// <param name="pCategoryId"></param>
        /// <param name="applicationName">Nombre de la aplicacion de membership</param>
        /// <param name="connectionStringName">Nombre de cadena de coneccion</param>
        /// <returns></returns>
        static List <FwkCategory> GetSubCategoriesByCategoryId(int pCategoryId, string applicationName, string connectionStringName)
        {
            IEnumerable <FwkCategory> wCategories = null;
            FwkCategory wFwkCategory = new FwkCategory();

            try
            {
                Guid wApplicationId = GetApplication(applicationName, connectionStringName);
                using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString))
                {
                    wCategories = from s in dc.aspnet_RulesCategories
                                  where (s.ParentCategoryId == pCategoryId &&
                                         s.ApplicationId == wApplicationId)
                                  select new FwkCategory {
                        CategoryId = s.CategoryId, ParentId = s.ParentCategoryId, Name = s.Name
                    };

                    //var wRulesCategories = from s in dc.aspnet_RulesCategories
                    //                       where (s.ParentCategoryId == pCategoryId
                    //                       && s.ApplicationId == wApplicationId)
                    //                       select s;

                    //foreach(aspnet_RulesCategory rule in wRulesCategories.ToList<aspnet_RulesCategory>())
                    //{
                    //    wFwkCategory = new FwkCategory ();
                    //    wFwkCategory.CategoryId = pCategoryId;
                    //    wFwkCategory.Name = rule.Name;
                    //    wFwkCategory.ParentId = rule.ParentCategoryId;

                    //wCategories.Add(wFwkCategory);
                    //}
                    return(wCategories.ToList <FwkCategory>());
                }
            }
            catch (TechnicalException tx)
            { throw tx; }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(Fwk.Security.Properties.Resource.MembershipSecurityGenericError, ex);
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4000";
                throw te;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pFwkCategory"></param>
        /// <param name="providerName">Nombre del proveedor de membership</param>
        public static void CreateCategory(FwkCategory pFwkCategory, string providerName)
        {
            SqlMembershipProvider wProvider = GetSqlMembershipProvider(providerName);

            CreateCategory(pFwkCategory, wProvider.ApplicationName, GetProvider_ConnectionStringName(wProvider.Name));
        }