Example #1
0
        public DomainTableModel GetTableByIdByEffectiveDate(string id, DateTime effectiveDate)
        {
            RatingEngineTableRepository.ChangeEffectiveDate(effectiveDate);
            var table = RatingEngineTableRepository.GetLookupTable(id);

            //TODO: put in adapter
            var domainTable = new DomainTableModel
            {
                Name = table.Name,
                Group = table.Properties.Schema,
                TableType = table.Properties.TableType,
                EffectiveDate = DateTime.Parse(table.Properties.EffectiveDate),
                Columns = table.KeysAndColumns.Select(c => new DomainTableColumnModel
                {
                    Name = c.Name,
                    MatchType = c.LookupType.ToString(),
                    IsKey = c.IsKey
                }).ToArray(),
                Rows = table.Rows.Select(r => r.KeyValues.Select(k => new { Name = k.Name, Value = k.LowValue })
                                                         .Union(r.ColumnValues.Select(c => new { Name = c.Key, Value = c.Value.ToString() }))
                                 .ToDictionary(k => k.Name, k => k.Value)).ToList()
            };

            return domainTable;
        }
Example #2
0
        public DomainTableModel GetTableById(string id)
        {
            var table = RatingEngineTableRepository.GetLookupTable(id);

            //TODO: put in adapter
            var domainTable = new DomainTableModel
            {
                Name = table.Name,
                Group = table.Properties.Schema,
                TableType = table.Properties.TableType,
                EffectiveDate = DateTime.Parse(table.Properties.EffectiveDate),
                Columns = table.KeysAndColumns.Select(c => new DomainTableColumnModel
                {
                    Name = c.Name,
                    MatchType = c.LookupType.ToString(),
                    IsKey = c.IsKey
                }).ToArray(),
                Rows = table.Rows.Select(r => r.ColumnValues.ToDictionary(d => d.Key, d => d.Value.ToString())).ToList()
            };

            return domainTable;
        }
Example #3
0
        //TODO: add more flexibility
        private static DomainTableModel ApplyFilter(DomainTableModel model, dynamic filter)
        {
            //filter rows
            foreach (var rowFilter in filter.rows)
            {
                var column = (string)rowFilter.col.ToString();
                var operation = (string)rowFilter.op.ToString();
                var val = (string)rowFilter.val.ToString();

                var outVal = 0.0;
                var isNumeric = double.TryParse(val, out outVal);

                if (operation.Equals("eq"))
                    model.Rows = model.Rows.Where(r => r[column] == val).ToList();
                else if (operation.Equals("lt") && isNumeric)
                    model.Rows = model.Rows.Where(r => double.Parse(r[column]) < outVal).ToList();
                else if (operation.Equals("lte") && isNumeric)
                    model.Rows = model.Rows.Where(r => double.Parse(r[column]) < outVal).ToList();
                else if (operation.Equals("gt") && isNumeric)
                    model.Rows = model.Rows.Where(r => double.Parse(r[column]) < outVal).ToList();
                else if (operation.Equals("gte") && isNumeric)
                    model.Rows = model.Rows.Where(r => double.Parse(r[column]) < outVal).ToList();
                else if (operation.Equals("neq"))
                    model.Rows = model.Rows.Where(r => r[column] != val).ToList();
                else if (operation.Equals("in"))
                    model.Rows = model.Rows.Where(r => val.Split('|').ToList().Contains(r[column])).ToList();
            }

            //filter columns
            var columns = new List<string>();
            foreach (var column in filter.columns)
            {
                columns.Add(column.ToString());
            }

            model.Columns = model.Columns.Where(c => columns.Contains(c.Name)).ToArray();

            model.Rows = model.Rows.Select(r => r.Where(i => columns.Contains(i.Key)).ToDictionary(d => d.Key, d => d.Value)).ToList();

            return model;
        }
Example #4
0
        public DomainTableModel GetTableByNameByGroupByEffectiveDate(DomainTableRequestModel model)
        {
            var table = RatingEngineTableRepository.GetLookupTable(model.Name, model.Group, model.EffectiveDate);

            //TODO: put in adapter
            var domainTable = new DomainTableModel
            {
                Name = table.Name,
                Group = table.Properties.Schema,
                TableType = table.Properties.TableType,
                EffectiveDate = DateTime.Parse(table.Properties.EffectiveDate),
                Columns = table.KeysAndColumns.Select(c => new DomainTableColumnModel
                {
                    Name = c.Name,
                    MatchType = c.LookupType.ToString(),
                    IsKey = c.IsKey
                }).ToArray(),
                Rows = table.Rows.Select(r => r.KeyValues.Select(k => new { Name = k.Name, Value = k.LowValue })
                                                         .Union(r.ColumnValues.Select(c => new { Name = c.Key, Value = c.Value.ToString() }))
                                 .ToDictionary(k => k.Name, k => k.Value)).ToList()
            };

            if(model.Filter != null)
                domainTable = ApplyFilter(domainTable, model.Filter);

            return domainTable;
        }