コード例 #1
0
        /// <summary>
        /// Crea una regla
        /// </summary>
        /// <param name="rule"></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>
        public static void CreateRule(FwkAuthorizationRule rule, string applicationName, string connectionStringName)
        {
            //Verificar si ya existe
            if (FwkMembership.ExistRule(rule.Name, applicationName, connectionStringName))
            {
                TechnicalException te = new TechnicalException(string.Format(Resource.Rule_ExistError, rule.Name));
                te.ErrorId = "4004";
                throw te;
            }

            try
            {
                Guid wApplicationId = GetApplication(applicationName, connectionStringName);


                StringBuilder str = new StringBuilder(FwkMembershipScripts.Rule_i);
                str.Replace("[ApplicationId]", wApplicationId.ToString());
                str.Replace("[rulename]", rule.Name.Trim());
                str.Replace("[expression]", rule.Expression);

                if (!String.IsNullOrEmpty(rule.Description))
                {
                    str.Replace("[description]", rule.Description.Trim());
                }
                else
                {
                    str.Replace("[description]", string.Empty);
                }
                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 (TechnicalException tx)
            { throw tx; }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(string.Format(Resource.Rule_Crate_Error, rule.Name), ex);
                te.ErrorId = "4005";
                Fwk.Exceptions.ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                throw te;
            }
        }
コード例 #2
0
        /// <summary>
        /// UpdateRule
        /// </summary>
        /// <param name="rule"></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>
        private static void UpdateRule(FwkAuthorizationRule rule, string newRuleName, string applicationName, string connectionStringName)
        {
            //Verificar si existe
            if (!FwkMembership.ExistRule(rule.Name.Trim(), applicationName, connectionStringName))
            {
                TechnicalException te = new TechnicalException(string.Format(Resource.Rule_NotExist, rule.Name));
                te.ErrorId = "4004";
                throw te;
            }


            try
            {
                Guid wApplicationId = GetApplication(applicationName, connectionStringName);


                using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString))
                {
                    var ruleToUpdate = dc.aspnet_Rules.Where(p => p.Id.Equals(rule.Id)).FirstOrDefault();

                    if (!string.IsNullOrEmpty(newRuleName))
                    {
                        ruleToUpdate.name = newRuleName;
                    }

                    ruleToUpdate.expression  = rule.Expression;
                    ruleToUpdate.Description = rule.Description;

                    dc.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                TechnicalException te = new TechnicalException(Fwk.Security.Properties.Resource.MembershipSecurityGenericError, ex);
                ExceptionHelper.SetTechnicalException <FwkMembership>(te);
                te.ErrorId = "4000";
                throw te;
            }
        }