Beispiel #1
0
        // POST api/values
        public object Post(RulesExecuteModel model)
        {
            // MoreApplicationFactory.GetCompiler(model.EffectiveDate);
            try
            {
                var inputs = JsonHelper.FromJson(model.Data);
                var rulesEngine = new RulesEngine();
                var assemblyEffectiveDate = MoreApplicationFactory.GetAssemblyEffectiveDate(model.EffectiveDate);
                var factory = rulesEngine.GetFactory(
                    MoreApplicationFactory.GetAssemblyName(assemblyEffectiveDate),
                    MoreApplicationFactory.GetLookupRepository(assemblyEffectiveDate)
                    );
                if (factory == null)
                {
                    return
                        "Either the assembly was not found.  Or it was compiled incorrectly. Recompile and try again.";
                }
                var ruleBook = factory.GetRuleBook(model.RuleBook);

                if (ruleBook == null)
                {
                    return "Rule book not found.";
                }
                var result = ruleBook.Execute(inputs);
                if (result.Errors.Any())
                {
                    var error = result.Errors.First();
                    return string.Format("{0} - {1}", error.Message, error.RuleDescription);
                }
                if (model.Items != null && model.Items.Length > 0 && model.Items.First() != "null")
                {
                    return model.Items.ToDictionary(item => item, result.Find);
                }
                return JsonHelper.GetJsonTrace(result.Results);
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
Beispiel #2
0
 // GET api/values/5
 public string Get(RulesExecuteModel model)
 {
     return "value";
 }