예제 #1
0
        public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            ServiceOfferingClientDataTable dataTable = new ServiceOfferingClientDataTable(Request, (EducationSecurityPrincipal)User);
            var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public static DataTableResponseModel <T> GetDataTableResponse <T>(this IQueryable <T> data,
                                                                          DataTableRequestModel dataTableRequestModel) where T : class, new()
        {
            // Count or LongCount is very annoying cause an extra evaluation.

            var totalRecords = data.Count();

            var filters = new DataTableParamModelHelper();

            var outputProperties = new DataTableTypeInfoModel <T>().Properties;

            var filteredData = filters.ApplyFiltersAndSort(dataTableRequestModel, data, outputProperties);

            var totalDisplayRecords = filteredData.Count();

            var skipped = filteredData.Skip(dataTableRequestModel.DisplayStart);

            var page = (dataTableRequestModel.DisplayLength <= 0
                ? skipped
                : skipped.Take(dataTableRequestModel.DisplayLength)).ToArray();

            var result = new DataTableResponseModel <T>
            {
                TotalRecord        = totalRecords,
                TotalDisplayRecord = totalDisplayRecords,
                Echo = dataTableRequestModel.Echo,
                Data = page.Cast <object>().ToArray()
            };

            return(result);
        }
예제 #3
0
        public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            UserClientDataTable dataTable = new UserClientDataTable(Request, SecurityConfiguration);
            var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
        public JsonResult LoginAuditDataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            AuditLoginClientDataTable dataTable = new AuditLoginClientDataTable(Request);
            var viewModel = LogicManager.GenerateAuditLoginDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            StudentApprovalClientDataTable dataTable = new StudentApprovalClientDataTable(Request);
            DataTableResultModel           viewModel = LogicManager.GenerateApprovalDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public void WhenGenerateApprovalDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel { iDisplayLength = 10 };
            StudentApprovalClientDataTable dataTable = new StudentApprovalClientDataTable(MockContext.Request);

            Target.GenerateApprovalDataTableResultViewModel(model, dataTable);
        }
        public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(Request);
            var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
        private static DataTableRequestModel BindLegacyModel(IValueProvider valueProvider, int columns)
        {
            var obj = new DataTableRequestModel(columns)
            {
                DisplayStart  = GetValue <int>(valueProvider, PropertyConstants.DisplayStart),
                DisplayLength = GetValue <int>(valueProvider, PropertyConstants.DisplayLength),
                Search        = GetValue <string>(valueProvider, PropertyConstants.Search),
                EscapeRegex   = GetValue <bool>(valueProvider, PropertyConstants.EscapeRegex),
                SortingCols   = GetValue <int>(valueProvider, PropertyConstants.SortingCols),
                Echo          = GetValue <int>(valueProvider, PropertyConstants.Echo)
            };

            obj.ColReorderIndexs = GetValueArray <int>(valueProvider, PropertyConstants.ColReorderIndexs);

            for (var i = 0; i < obj.Columns; i++)
            {
                obj.ListIsSortable.Add(GetValue <bool>(valueProvider, $"{PropertyConstants.Sortable}_{i}"));
                obj.ListIsSearchable.Add(GetValue <bool>(valueProvider, $"{PropertyConstants.Searchable}_{i}"));

                // Important Legacy DataTable bind sSearch for sSearchValues
                obj.SearchValues.Add(GetValue <string>(valueProvider, $"{PropertyConstants.Search}_{i}"));

                obj.ListIsEscapeRegexColumn.Add(GetValue <bool>(valueProvider, $"{PropertyConstants.EscapeRegex}_{i}"));
                obj.SortCol.Add(GetValue <int>(valueProvider, $"{PropertyConstants.SortCol}_{i}"));
                obj.SortDir.Add(GetValue <string>(valueProvider, $"{PropertyConstants.SortDir}_{i}"));
            }

            return(obj);
        }
예제 #9
0
        public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            var dataTable = CreateClientDataTable();
            var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
예제 #10
0
        public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel)
        {
            var user = ((EducationSecurityPrincipal)HttpContext.User);
            ServiceTypeClientDataTable dataTable = new ServiceTypeClientDataTable(Request, user);
            var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
예제 #11
0
        public void WhenDataTableAjaxHandler_ThenReturnJsonResult()
        {
            DataTableRequestModel requestModel = new DataTableRequestModel();

            JsonResult actual = Target.DataTableAjaxHandler(requestModel);

            Assert.IsNotNull(actual);
        }
예제 #12
0
        public void WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            EducationSecurityPrincipal user      = new EducationSecurityPrincipal(EducationContext.Users.First());
            DataTableRequestModel      model     = new DataTableRequestModel();
            ProviderClientDataTable    dataTable = new ProviderClientDataTable(MockHttpContextFactory.CreateRequest(), user);

            Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        public void WhenGetDataTableAjaxHandler_ThenReturnViewModelFromLogicManager()
        {
            DataTableRequestModel model = new DataTableRequestModel();

            Target.DataTableAjaxHandler(model);

            MockLogicManager.AssertWasCalled(m => m.GenerateApprovalDataTableResultViewModel(Arg.Is(model), Arg <IClientDataTable <Student> > .Is.NotNull));
        }
예제 #14
0
        public void WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel {
                iDisplayLength = 10
            };
            ServiceOfferingClientDataTable dataTable = new ServiceOfferingClientDataTable(MockHttpContextFactory.CreateRequest(), User);

            Target.GenerateDataTableResultViewModel(model, dataTable);
        }
예제 #15
0
        private static DataTablePropertyInfoModel FindColumn(DataTableRequestModel dtParameters, DataTablePropertyInfoModel[] columns, int i)
        {
            if (dtParameters.ColumnNames.Any())
            {
                return(columns.First(x => x.PropertyInfo.Name == dtParameters.ColumnNames[i]));
            }

            return(columns[i]);
        }
예제 #16
0
        public void WhenRequestDataTableAjaxHandler_ThenJsonResultContainsDataTableResultModel()
        {
            DataTableRequestModel requestModel = new DataTableRequestModel();

            MockAccountManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(requestModel), Arg <IClientDataTable <User> > .Is.NotNull)).Return(new DataTableResultModel());

            JsonResult result = Target.DataTableAjaxHandler(requestModel);

            result.AssertGetData <DataTableResultModel>();
        }
        public DataTableResultModel GenerateDataTableResultViewModel(DataTableRequestModel requestModel, IClientDataTable <User> dataTable)
        {
            IQueryable <User> items = UserRepository.Items.
                                      Include("UserRoles.Role").
                                      Include("UserRoles.Schools").
                                      Include("UserRoles.Providers").
                                      Include(u => u.LoginEvents);

            return(DataTableBinder.Bind <User>(items, dataTable, requestModel));
        }
예제 #18
0
        public DataTableResultModel GenerateDataTableResultViewModel(DataTableRequestModel requestModel, IClientDataTable <ServiceAttendance> dataTable)
        {
            if (requestModel == null)
            {
                throw new ArgumentNullException("requestModel");
            }
            IQueryable <ServiceAttendance> items = ServiceAttendanceRepository.Items;

            return(DataTableBinder.Bind <ServiceAttendance>(items, dataTable, requestModel));
        }
        public DataTableResultModel GenerateAuditLoginDataTableResultViewModel(DataTableRequestModel requestModel, IClientDataTable <LoginEvent> dataTable)
        {
            if (requestModel == null)
            {
                throw new ArgumentNullException("requestModel");
            }
            IQueryable <LoginEvent> items = LoginEventRepository.Items;

            return(DataTableBinder.Bind <LoginEvent>(items, dataTable, requestModel));
        }
예제 #20
0
        private static DataTableResponseModel <UserModel> GetDataTableResponse(DataTableRequestModel model)
        {
            // Queryable Data
            var query = DummyUsers.AsQueryable();

            // Generate DataTable Response
            var result = query.GetDataTableResponse(model);

            return(result);
        }
예제 #21
0
파일: UserService.cs 프로젝트: kudogit/BET
        public Task <DataTableResponseModel <UserModel> > GetDataTableAsync(DataTableRequestModel model, CancellationToken cancellationToken = default)
        {
            var query = _userRepo.Get();

            var listData = query.QueryTo <UserModel>();

            var result = listData.GetDataTableResponse(model);

            return(Task.FromResult(result));
        }
        private static DataTableRequestModel BindModel(IValueProvider valueProvider)
        {
            var obj = new DataTableRequestModel
            {
                DisplayStart  = GetValue <int>(valueProvider, "start"),
                DisplayLength = GetValue <int>(valueProvider, "length"),
                Search        = GetValue <string>(valueProvider, "search[value]"),
                EscapeRegex   = GetValue <bool>(valueProvider, "search[regex]"),
                Echo          = GetValue <int>(valueProvider, "draw")
            };

            obj.ColReorderIndexs = GetValueArray <int>(valueProvider, PropertyConstants.ColReorderIndexs);

            var colIdx = 0;

            while (true)
            {
                var colPrefix = $"columns[{colIdx}]";
                var colName   = GetValue <string>(valueProvider, $"{colPrefix}[data]");
                if (string.IsNullOrWhiteSpace(colName))
                {
                    break;
                }
                obj.ColumnNames.Add(colName);
                obj.ListIsSortable.Add(GetValue <bool>(valueProvider, $"{colPrefix}[orderable]"));
                obj.ListIsSearchable.Add(GetValue <bool>(valueProvider, $"{colPrefix}[searchable]"));
                obj.SearchValues.Add(GetValue <string>(valueProvider, $"{colPrefix}[search][value]"));
                obj.ListIsEscapeRegexColumn.Add(GetValue <bool>(valueProvider, $"{colPrefix}[searchable][regex]"));
                colIdx++;
            }

            obj.Columns = colIdx;
            colIdx      = 0;

            while (true)
            {
                var colPrefix = $"order[{colIdx}]";

                var orderColumn = GetValue <int?>(valueProvider, $"{colPrefix}[column]");

                if (orderColumn.HasValue)
                {
                    obj.SortCol.Add(orderColumn.Value);
                    obj.SortDir.Add(GetValue <string>(valueProvider, $"{colPrefix}[dir]"));
                    colIdx++;
                }
                else
                {
                    break;
                }
            }

            obj.SortingCols = colIdx;
            return(obj);
        }
예제 #23
0
        public void GivenSortOnId_WhenGenerateApprovalDataTableResultViewModel_ThenViewModelContainsData()
        {
            DataTableRequestModel model = new DataTableRequestModel { iDisplayLength = 10 };
            MockContext.Request.Expect(m => m["iSortCol_0"]).Return("0");
            MockContext.Request.Expect(m => m["sSortDir_0"]).Return("asc");
            StudentApprovalClientDataTable dataTable = new StudentApprovalClientDataTable(MockContext.Request);

            var actual = Target.GenerateApprovalDataTableResultViewModel(model, dataTable);

            Assert.AreEqual(10, actual.aaData.Count());
        }
예제 #24
0
        public void GivenLogicManagerGeneratesViewModel_WhenDataTableAjaxHandler_ThenJsonResultContainsViewModel()
        {
            var request  = new DataTableRequestModel();
            var expected = new DataTableResultModel();

            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(request), Arg <IClientDataTable <Program> > .Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(request);

            result.AssertGetData(expected);
        }
        public void GivenAPublicField_WhenGettingTableData_ThenActionColumnDataContainsIdAndName()
        {
            var request  = new DataTableRequestModel();
            var expected = new DataTableResultModel();

            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(request), Arg <IClientDataTable <CustomField> > .Is.NotNull)).Return(expected);

            var result = Target.DataTableAjaxHandler(request) as JsonResult;

            result.AssertGetData(expected);
        }
        public void WhenDataTableAjaxHandler_ThenJsonContainsGeneratedViewModel()
        {
            DataTableRequestModel model    = new DataTableRequestModel();
            DataTableResultModel  expected = new DataTableResultModel();

            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(model), Arg <IClientDataTable <ServiceOffering> > .Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(model);

            result.AssertGetData(expected);
        }
예제 #27
0
        public static object PageResponseForTransactions(DataTableRequestModel pageRequestModel, int total, int totalFiltered, object data)
        {
            return(new
            {
                draw = pageRequestModel.Draw,
                recordsTotal = total,
                recordsFiltered = total,

                data
            });
        }
        public void WhenGetDataTableAjaxHandler_ThenReturnGeneratedViewModel()
        {
            DataTableRequestModel model    = new DataTableRequestModel();
            DataTableResultModel  expected = new DataTableResultModel();

            MockLogicManager.Expect(m => m.GenerateApprovalDataTableResultViewModel(Arg.Is(model), Arg <IClientDataTable <Student> > .Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(model);

            result.AssertGetData(expected);
        }
예제 #29
0
        public void GivenAProvider_WhenGettingTableData_ThenJsonResultContainsViewModelFromLogicManager()
        {
            var request  = new DataTableRequestModel();
            var expected = new DataTableResultModel();

            MockLogicManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(request), Arg <IClientDataTable <Provider> > .Is.NotNull)).Return(expected);

            var result = Target.DataTableAjaxHandler(request) as JsonResult;

            result.AssertGetData(expected);
        }
예제 #30
0
        public void WhenRequestDataTableAjaxHandler_ThenGenerateListViewModelReceivesCorrectDataTableRequest_AndResultPassedToJson()
        {
            DataTableResultModel  expected     = new DataTableResultModel();
            DataTableRequestModel requestModel = new DataTableRequestModel();

            MockAccountManager.Expect(m => m.GenerateDataTableResultViewModel(Arg.Is(requestModel), Arg <IClientDataTable <User> > .Is.NotNull)).Return(expected);

            JsonResult result = Target.DataTableAjaxHandler(requestModel);

            result.AssertGetData(expected);
        }