/// <summary> /// Elimina una regla de la base de datos /// </summary> /// <param name="ruleName"></param> /// <param name="applicationName"></param> /// <param name="connectionStringName"></param> /// <returns></returns> public static void DeleteRule(string ruleName, string applicationName, string connectionStringName) { aspnet_Rule waspnet_Rule = null; try { Guid wApplicationId = GetApplication(applicationName, connectionStringName); using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString)) { waspnet_Rule = dc.aspnet_Rules.First <aspnet_Rule>(s => s.name.Equals(ruleName.Trim()) && s.ApplicationId.Equals(wApplicationId)); dc.aspnet_Rules.DeleteOnSubmit(waspnet_Rule); dc.SubmitChanges(); } } catch (TechnicalException tx) { throw tx; } catch (Exception ex) { TechnicalException te = new TechnicalException(string.Format(Resource.Rule_ProblemGetingData_Error, ruleName), ex); te.ErrorId = "4003"; Fwk.Exceptions.ExceptionHelper.SetTechnicalException <FwkMembership>(te); throw te; } }
/// <summary> /// Actualiza parent category id una determinada categoria /// </summary> /// <param name="category_to_move_Id"></param> /// <param name="currentParentCategoryId"></param> /// <param name="newParentCategoryId"></param> /// <param name="applicationName"></param> /// <param name="connectionStringName"></param> public static void UpdateParentCategory(int category_to_move_Id, int currentParentCategoryId, int newParentCategoryId, string applicationName, string connectionStringName) { try { Guid wApplicationId = GetApplication(applicationName, connectionStringName); using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString)) { aspnet_RulesCategory waspnet_RulesCategory = dc.aspnet_RulesCategories.Where <aspnet_RulesCategory>(p => p.CategoryId == category_to_move_Id && p.ParentCategoryId == currentParentCategoryId && p.ApplicationId == wApplicationId).FirstOrDefault(); if (waspnet_RulesCategory != null) { waspnet_RulesCategory.ParentCategoryId = newParentCategoryId; dc.SubmitChanges(); } } } 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> /// 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; } }
/// <summary> /// Actualiza parent category id una determinada categoria /// </summary> /// <param name="category_to_move_Id"></param> /// <param name="currentParentCategoryId"></param> /// <param name="newParentCategoryId"></param> /// <param name="applicationName"></param> /// <param name="connectionStringName"></param> public static void UpdateParentCategory(int category_to_move_Id, int currentParentCategoryId, int newParentCategoryId, string applicationName, string connectionStringName) { try { Guid wApplicationId = GetApplication(applicationName, connectionStringName); using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString)) { aspnet_RulesCategory waspnet_RulesCategory = dc.aspnet_RulesCategories.Where<aspnet_RulesCategory>(p => p.CategoryId == category_to_move_Id && p.ParentCategoryId == currentParentCategoryId && p.ApplicationId == wApplicationId).FirstOrDefault(); if (waspnet_RulesCategory != null) { waspnet_RulesCategory.ParentCategoryId = newParentCategoryId; dc.SubmitChanges(); } } } 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> /// Elimina una regla de la base de datos /// </summary> /// <param name="ruleName"></param> /// <param name="applicationName"></param> /// <param name="connectionStringName"></param> /// <returns></returns> public static void DeleteRule(string ruleName, string applicationName, string connectionStringName) { aspnet_Rule waspnet_Rule = null; try { Guid wApplicationId = GetApplication(applicationName, connectionStringName); using (Fwk.Security.RuleProviderDataContext dc = new Fwk.Security.RuleProviderDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString)) { waspnet_Rule = dc.aspnet_Rules.First<aspnet_Rule>(s => s.name.Equals(ruleName.Trim()) && s.ApplicationId.Equals(wApplicationId)); dc.aspnet_Rules.DeleteOnSubmit(waspnet_Rule); dc.SubmitChanges(); } } catch (TechnicalException tx) { throw tx; } catch (Exception ex) { TechnicalException te = new TechnicalException(string.Format(Resource.Rule_ProblemGetingData_Error, ruleName), ex); te.ErrorId = "4003"; Fwk.Exceptions.ExceptionHelper.SetTechnicalException<FwkMembership>(te); throw te; } }
/// <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; } }