コード例 #1
0
        public IModulesSettings Initialize(IComboRequestJson requestJson, IModulesSettings modulesSettings)
        {
            Guard.Requires(requestJson, "requestJson").IsNotNull();
            Guard.Requires(modulesSettings, "modulesSettings").IsNotNull();

            modulesSettings.Filters = new FiltersFactory().Create(requestJson.Filters);

            return(modulesSettings);
        }
コード例 #2
0
ファイル: PaginationModule.cs プロジェクト: ssnenov/ComboRox
        public IModulesSettings Initialize(IComboRequestJson requestJson, IModulesSettings modulesSettings)
        {
            if (requestJson.Pagination == null)
            {
                return(modulesSettings);
            }

            modulesSettings.Pagination = requestJson.Pagination;

            return(modulesSettings);
        }
コード例 #3
0
ファイル: Initialize_Should.cs プロジェクト: ssnenov/ComboRox
        public void ReturnsNull_WhenPassingNullSortingObjec()
        {
            // Arrange
            var sortingModule   = new SortingModule();
            var requestJson     = new ComboRequestJson();
            var modulesSettings = new ModulesSettings();

            // Act
            IModulesSettings result = sortingModule.Initialize(requestJson, modulesSettings);

            // Assert
            Assert.IsNull(result.Sorting);
        }
コード例 #4
0
        public void ReturnModulesSettingsObj_WhenPassingCorrectParameters()
        {
            // Arrange
            var modulesManager   = new Core.ModulesManager();
            var comboRequestJson = new ComboRequestJson {
                Filters = new List <FilterObject>()
            };

            // Act
            IModulesSettings result = modulesManager.GetModulesSettings(comboRequestJson, null);

            // Assert
            Assert.IsNotNull(result);
        }
コード例 #5
0
ファイル: ModulesManager.cs プロジェクト: ssnenov/ComboRox
        public IResultData ApplyModulesExpressions <TType>(
            IEnumerable <TType> collection,
            IComboRequestJson comboRequestJson,
            IModulesSettings modulesSettings = null)
            where TType : class
        {
            IResultData      resultData = new ResultData();
            IModulesSettings settings   = this.GetModulesSettings(comboRequestJson, modulesSettings);

            foreach (var module in this.Modules.Values)
            {
                collection = module.ApplyExpression(collection, settings);
                resultData = module.ConstructResult(collection, resultData);
            }

            this.DataPrepared.TriggerEvent(resultData);

            return(resultData);
        }
コード例 #6
0
ファイル: Initialize_Should.cs プロジェクト: ssnenov/ComboRox
        public void SetSortingObjectCorrectly()
        {
            // Arrange
            var sortingModule   = new SortingModule();
            var requestJson     = new ComboRequestJson();
            var modulesSettings = new ModulesSettings();

            requestJson.Sorting = new List <SortingObject>
            {
                new SortingObject {
                    Direction = SortingDirection.Asc, Prop = "Test"
                }
            };

            // Act
            IModulesSettings result = sortingModule.Initialize(requestJson, modulesSettings);

            // Assert
            Assert.IsNotNull(result.Sorting);
            Assert.IsNotNull(result.Sorting[0]);
            Assert.AreEqual(result.Sorting[0].Direction, result.Sorting[0].Direction);
            Assert.AreEqual(result.Sorting[0].Prop, result.Sorting[0].Prop);
        }
コード例 #7
0
ファイル: ModulesManager.cs プロジェクト: ssnenov/ComboRox
        public IModulesSettings GetModulesSettings(IComboRequestJson comboRequestJson, IModulesSettings modulesSettingsObj)
        {
            if (comboRequestJson == null)
            {
                throw new ArgumentNullException("comboRequestJson");
            }

            if (modulesSettingsObj == null)
            {
                modulesSettingsObj = new ModulesSettings();
            }

            foreach (var module in this.Modules.Values)
            {
                modulesSettingsObj = module.Initialize(comboRequestJson, modulesSettingsObj);
            }

            return(modulesSettingsObj);
        }
コード例 #8
0
ファイル: PaginationModule.cs プロジェクト: ssnenov/ComboRox
        public IEnumerable <TType> ApplyExpression <TType>(IEnumerable <TType> collection, IModulesSettings modulesSettings) where TType : class
        {
            if (modulesSettings.Pagination == null)
            {
                return(collection);
            }

            int pageSize = modulesSettings.Pagination.PageSize;

            return(collection.Skip((modulesSettings.Pagination.Page - 1) * pageSize)
                   .Take(pageSize));
        }
コード例 #9
0
        public IEnumerable <TType> ApplyExpression <TType>(IEnumerable <TType> collection, IModulesSettings modulesSettings) where TType : class
        {
            if (modulesSettings.Sorting != null)
            {
                var ascendingSorts  = modulesSettings.Sorting.Where(x => x.Direction == SortingDirection.Asc).ToList();
                var descendingSorts = modulesSettings.Sorting.Where(x => x.Direction == SortingDirection.Desc).ToList();

                IEnumerable <TType> result = SortingExpressionFactory.Create(collection, ascendingSorts, descendingSorts);

                return(result);
            }

            return(collection);
        }
コード例 #10
0
        public IModulesSettings Initialize(IComboRequestJson requestJson, IModulesSettings modulesSettings)
        {
            modulesSettings.Sorting = requestJson.Sorting;

            return(modulesSettings);
        }
コード例 #11
0
        public IEnumerable <TType> ApplyExpression <TType>(IEnumerable <TType> collection, IModulesSettings modulesSettings) where TType : class
        {
            var expressionToApply = FiltersExpressionFactory.Create <TType>(modulesSettings.Filters);

            if (expressionToApply == null)
            {
                return(collection);
            }

            var query = collection as IQueryable <TType>;

            if (query != null)
            {
                return(query.Where(expressionToApply));
            }

            return(collection.Where(expressionToApply.Compile()));
        }