private void ReplaceActionRule(IValidationRuleConfiguredByUser actionRuleUserConfigured) { bool MatchControllerAndAction(IValidationRuleInternal rule) => rule.Action.DeclaringType.FullName == actionRuleUserConfigured.Action.DeclaringType.FullName && rule.Action.ToString() == actionRuleUserConfigured.Action.ToString(); MergeRules(actionRuleUserConfigured, MatchControllerAndAction); }
/// <summary> /// Replaces the default validation rules with the ones from users configured rules /// (and in the case of action rules also replaces rules configured on controller level) /// (sets the Attribute required from configuration in the rules that will finally be validated) /// </summary> /// <param name="validationRuleConfiguredByUser"></param> /// <param name="matchActionAndOrController"></param> private void MergeRules(IValidationRuleConfiguredByUser validationRuleConfiguredByUser, Func <IValidationRuleInternal, bool> matchActionAndOrController) { var rulesToReplace = AuthorizationValidationRules.Where(matchActionAndOrController).ToList(); var newRules = rulesToReplace.Select(oldRule => new ValidationRuleActionInternal( oldRule.Action, validationRuleConfiguredByUser.AttributeRequired )); rulesToReplace.ForEach(rule => AuthorizationValidationRules.Remove(rule)); AuthorizationValidationRules.AddRange(newRules); }
/// <summary> /// Replaces all default actions rules for the controller /// </summary> /// <param name="controllerRuleConfiguredByUser"></param> private void ReplaceActionRulesForController(IValidationRuleConfiguredByUser controllerRuleConfiguredByUser) { bool MatchControllerName(IValidationRuleInternal rule) => rule.ControllerName == controllerRuleConfiguredByUser.ControllerName; MergeRules(controllerRuleConfiguredByUser, MatchControllerName); }