public void DeleteRuleSet(RuleSetEntity ruleSet) { Guard.NotNull(ruleSet, nameof(ruleSet)); _rsRuleSets.Delete(ruleSet); InvalidateRuleSet(ruleSet.Id); }
public ActionResult AddGroup(int ruleSetId, RuleScope scope) { var provider = _ruleProvider(scope); var group = new RuleSetEntity { IsActive = true, IsSubGroup = true, Scope = scope }; _ruleStorage.InsertRuleSet(group); var groupRefRule = new RuleEntity { RuleSetId = ruleSetId, RuleType = "Group", Operator = RuleOperator.IsEqualTo, Value = group.Id.ToString() }; _ruleStorage.InsertRule(groupRefRule); var expression = provider.VisitRuleSet(group); expression.RefRuleId = groupRefRule.Id; return(PartialView("_RuleSet", expression)); }
public override IRuleExpressionGroup VisitRuleSet(RuleSetEntity ruleSet) { var group = new SearchFilterExpressionGroup { Id = ruleSet.Id, LogicalOperator = ruleSet.LogicalOperator, IsSubGroup = ruleSet.IsSubGroup, Value = ruleSet.Id, RawValue = ruleSet.Id.ToString(), Provider = this }; return(group); }
public override IRuleExpressionGroup VisitRuleSet(RuleSetEntity ruleSet) { var group = new FilterExpressionGroup(typeof(Customer)) { Id = ruleSet.Id, LogicalOperator = ruleSet.LogicalOperator, IsSubGroup = ruleSet.IsSubGroup, Value = ruleSet.Id, RawValue = ruleSet.Id.ToString(), Provider = this // INFO: filter group does NOT access any descriptor }; return(group); }
public override IRuleExpressionGroup VisitRuleSet(RuleSetEntity ruleSet) { var group = new RuleExpressionGroup { Id = ruleSet.Id, LogicalOperator = ruleSet.LogicalOperator, IsSubGroup = ruleSet.IsSubGroup, Value = ruleSet.Id, RawValue = ruleSet.Id.ToString(), Provider = this, Descriptor = new CartRuleDescriptor { RuleType = RuleType.Boolean, ProcessorType = typeof(CompositeRule) } }; return(group); }
public virtual IRuleExpressionGroup CreateExpressionGroup(RuleSetEntity ruleSet, IRuleVisitor visitor) { if (ruleSet.Scope != visitor.Scope) { // TODO: ErrHandling (ruleSet is for a different scope) return(null); } var group = visitor.VisitRuleSet(ruleSet); var expressions = ruleSet.Rules .Select(x => CreateExpression(x, visitor)) .Where(x => x != null) .ToArray(); group.AddExpressions(expressions); return(group); }
public virtual IRuleExpressionGroup CreateExpressionGroup(RuleSetEntity ruleSet, IRuleVisitor visitor, bool includeHidden = false) { if (ruleSet.Scope != visitor.Scope) { throw new SmartException($"Differing rule scope {ruleSet.Scope}. Expected {visitor.Scope}."); } if (!includeHidden && !ruleSet.IsActive) { return(null); } var group = visitor.VisitRuleSet(ruleSet); var expressions = ruleSet.Rules .Select(x => CreateExpression(x, visitor)) .Where(x => x != null) .ToArray(); group.AddExpressions(expressions); return(group); }
public void InsertRuleSet(RuleSetEntity ruleSet) { Guard.NotNull(ruleSet, nameof(ruleSet)); _rsRuleSets.Insert(ruleSet); }
public abstract IRuleExpressionGroup VisitRuleSet(RuleSetEntity rule);
private void PrepareModel(RuleSetModel model, RuleSetEntity entity, RuleScope?scope = null) { var scopes = (entity?.Scope ?? scope ?? RuleScope.Cart).ToSelectList(); model.Scopes = scopes .Select(x => { var item = new ExtendedSelectListItem { Value = x.Value, Text = x.Text, Selected = x.Selected }; var ruleScope = (RuleScope)x.Value.ToInt(); item.CustomProperties["Description"] = ruleScope.GetLocalizedEnum(Services.Localization, Services.WorkContext, true); return(item); }) .ToList(); if ((entity?.Id ?? 0) != 0) { var provider = _ruleProvider(entity.Scope); model.ScopeName = entity.Scope.GetLocalizedEnum(Services.Localization, Services.WorkContext); model.ExpressionGroup = _ruleFactory.CreateExpressionGroup(entity, provider, true); model.AssignedToDiscounts = entity.Discounts .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.Name.NullEmpty() ?? x.Id.ToString() }) .ToList(); model.AssignedToShippingMethods = entity.ShippingMethods .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.GetLocalized(y => y.Name) }) .ToList(); var paymentMethods = entity.PaymentMethods; if (paymentMethods.Any()) { var paymentProviders = _paymentService.Value.LoadAllPaymentMethods().ToDictionarySafe(x => x.Metadata.SystemName); model.AssignedToPaymentMethods = paymentMethods .Select(x => { string friendlyName = null; if (paymentProviders.TryGetValue(x.PaymentMethodSystemName, out var paymentProvider)) { friendlyName = _pluginMediator.Value.GetLocalizedFriendlyName(paymentProvider.Metadata); } return(new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = friendlyName.NullEmpty() ?? x.PaymentMethodSystemName, SystemName = x.PaymentMethodSystemName }); }) .ToList(); } model.AssignedToCustomerRoles = entity.CustomerRoles .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.Name }) .ToList(); model.AssignedToCategories = entity.Categories .Select(x => new RuleSetModel.AssignedToEntityModel { Id = x.Id, Name = x.GetLocalized(y => y.Name) }) .ToList(); } }