public ActionResult Edit(int id /* ruleSetId */) { var entity = _ruleStorage.GetRuleSetById(id, false, true); if (entity == null || entity.IsSubGroup) { return(HttpNotFound()); } var model = MiniMapper.Map <RuleSetEntity, RuleSetModel>(entity); model.ScopeName = entity.Scope.GetLocalizedEnum(Services.Localization, Services.WorkContext); var provider = _ruleProvider(entity.Scope); model.ExpressionGroup = _ruleFactory.CreateExpressionGroup(entity, provider, true); model.AvailableDescriptors = _targetGroupService.RuleDescriptors; 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(); } PrepareExpressions(model.ExpressionGroup); PrepareTemplateViewBag(entity.Id); return(View(model)); }
public ActionResult Edit(int id /* ruleSetId */) { var entity = _ruleStorage.GetRuleSetById(id, false, true); if (entity == null || entity.IsSubGroup) { return HttpNotFound(); } var model = MiniMapper.Map<RuleSetEntity, RuleSetModel>(entity); PrepareModel(model, entity); PrepareExpressions(model.ExpressionGroup); PrepareTemplateViewBag(entity.Id); return View(model); }
public ActionResult Edit(int id /* ruleSetId */) { var entity = _ruleStorage.GetRuleSetById(id, false, true); if (entity == null || entity.IsSubGroup) { return(HttpNotFound()); } var model = MiniMapper.Map <RuleSetEntity, RuleSetModel>(entity); model.ScopeName = entity.Scope.GetLocalizedEnum(Services.Localization, Services.WorkContext); var provider = _ruleProvider(entity.Scope); model.ExpressionGroup = _ruleFactory.CreateExpressionGroup(entity, provider, true); model.AvailableDescriptors = _targetGroupService.RuleDescriptors; PrepareExpressions(model.ExpressionGroup); PrepareTemplateViewBag(entity.Id); return(View(model)); }