예제 #1
0
        internal override ISorterFactory Build()
        {
            var sorter = new TableSorter <TRequest, TEntity, TControl>(_defaultColumn);

            _controls
            .Zip(_directions, (c, d) => new { Control = c, Direction = d })
            .ToList()
            .ForEach(z => sorter.AddControl(z.Control, z.Direction));

            foreach (var(k, v) in _columns)
            {
                v.Build(sorter, k);
            }

            if (_controls.Count == 0)
            {
                throw new BadCrudConfigurationException(
                          $"Table sorting was set for request '{typeof(TRequest)}' and entity '{typeof(TEntity)}'" +
                          ", but no controls were defined.");
            }

            if (_defaultColumn == null && _columns.Count == 0)
            {
                throw new BadCrudConfigurationException(
                          $"Table sorting was set for request '{typeof(TRequest)}' and entity '{typeof(TEntity)}'" +
                          ", but no table properties were defined.");
            }

            return(InstanceSorterFactory.From(sorter));
        }
        public TBuilder SortWith <TBaseRequest>(ISorter <TBaseRequest, TEntity> sorter)
        {
            if (!typeof(TBaseRequest).IsAssignableFrom(typeof(TRequest)))
            {
                throw new ContravarianceException(nameof(SortWith), typeof(TBaseRequest), typeof(TRequest));
            }

            Sorter = InstanceSorterFactory.From(sorter);

            return((TBuilder)this);
        }
예제 #3
0
        internal override ISorterFactory Build()
        {
            if (_operations.Count == 0)
            {
                throw new BadConfigurationException(
                          $"Basic sorting was set for request '{typeof(TRequest)}' and entity '{typeof(TEntity)}'" +
                          ", but no sort operation was defined.");
            }

            var instance = new BasicSorter <TRequest, TEntity>(_operations.Select(builder => builder.Build()).ToList());

            return(InstanceSorterFactory.From(instance));
        }
예제 #4
0
        internal override ISorterFactory Build()
        {
            var sorter = new SwitchSorter <TRequest, TEntity, TValue>(o => _getSwitchValue((TRequest)o));

            foreach (var(k, v) in _cases)
            {
                sorter.Case(k, v.Build());
            }

            if (_default != null)
            {
                sorter.Default(_default.Build());
            }

            if (_default == null && _cases.Count == 0)
            {
                throw new BadConfigurationException(
                          $"Switch sorting was set for request '{typeof(TRequest)}' and entity '{typeof(TEntity)}'" +
                          ", but no cases were defined.");
            }

            return(InstanceSorterFactory.From(sorter));
        }