Пример #1
0
        /// <summary>
        /// Execute the ipOpts to get the list of options to return to the client-
        /// side
        /// </summary>
        /// <param name="db">Database instance</param>
        /// <returns>List of options</returns>
        internal List <Dictionary <string, object> > OptionsExec(Database db)
        {
            if (_optsFn != null)
            {
                return(_optsFn());
            }

            if (_optsTable == null)
            {
                return(null);
            }

            var formatter = _optsFormat ??
                            (row => string.Join(" ", _optsLabel.Select(val => row[val] as string).ToArray()));

            var fields = new List <string>(_optsLabel)
            {
                _optsValue
            };
            var rows = db.SelectDistinct(_optsTable, fields, _optsCond)
                       .FetchAll();

            return(rows.Select(row => new Dictionary <string, object>
            {
                { "value", row[_optsValue] },
                { "label", formatter(row) }
            }).OrderBy(x => x["label"]).ToList());
        }