public ActionResult DeleteRule(int ruleId) { var rule = _ruleStorage.GetRuleById(ruleId, true); if (rule == null) { NotifyError(T("Admin.Rules.NotFound", ruleId)); return Json(new { Success = false }); } _ruleStorage.DeleteRule(rule); return Json(new { Success = true }); }
public ActionResult UpdateRule(int ruleId, string op, string value) { var rule = _ruleStorage.GetRuleById(ruleId, true); if (rule == null) { NotifyError(T("Admin.Rules.NotFound", ruleId)); return(Json(new { Success = false })); } // TODO? Ugly. There should be a better way. Do not store culture variant values. if (value.HasValue()) { var provider = _ruleProvider(rule.RuleSet.Scope); var descriptor = provider.RuleDescriptors.FindDescriptor(rule.RuleType); if (descriptor.RuleType == RuleType.Money) { value = value.Convert <decimal>(CultureInfo.CurrentCulture).ToString(CultureInfo.InvariantCulture); } else if (descriptor.RuleType == RuleType.Float || descriptor.RuleType == RuleType.NullableFloat) { value = value.Convert <float>(CultureInfo.CurrentCulture).ToString(CultureInfo.InvariantCulture); } else if (descriptor.RuleType == RuleType.DateTime || descriptor.RuleType == RuleType.NullableDateTime) { value = value.Convert <DateTime>(CultureInfo.CurrentCulture).ToString(CultureInfo.InvariantCulture); } } //if (value?.Contains(',') ?? false) //{ // var provider = _ruleProvider(rule.RuleSet.Scope); // var descriptor = provider.RuleDescriptors.FindDescriptor(rule.RuleType); // var floatingPointTypes = new Type[] { typeof(decimal), typeof(decimal?), typeof(float), typeof(float?), typeof(double), typeof(double?) }; // if (floatingPointTypes.Contains(descriptor.RuleType.ClrType)) // { // value = value.Replace(",", "."); // } //} rule.Operator = op; rule.Value = value; _ruleStorage.UpdateRule(rule); return(Json(new { Success = true })); }