public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel) { ServiceOfferingClientDataTable dataTable = new ServiceOfferingClientDataTable(Request, (EducationSecurityPrincipal)User); var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable); return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
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); }
public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel) { UserClientDataTable dataTable = new UserClientDataTable(Request, SecurityConfiguration); var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable); return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
public JsonResult LoginAuditDataTableAjaxHandler(DataTableRequestModel requestModel) { AuditLoginClientDataTable dataTable = new AuditLoginClientDataTable(Request); var viewModel = LogicManager.GenerateAuditLoginDataTableResultViewModel(requestModel, dataTable); return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel) { StudentApprovalClientDataTable dataTable = new StudentApprovalClientDataTable(Request); DataTableResultModel viewModel = LogicManager.GenerateApprovalDataTableResultViewModel(requestModel, dataTable); return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
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); }
public JsonResult DataTableAjaxHandler(DataTableRequestModel requestModel) { var dataTable = CreateClientDataTable(); var viewModel = LogicManager.GenerateDataTableResultViewModel(requestModel, dataTable); return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
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)); }
public void WhenDataTableAjaxHandler_ThenReturnJsonResult() { DataTableRequestModel requestModel = new DataTableRequestModel(); JsonResult actual = Target.DataTableAjaxHandler(requestModel); Assert.IsNotNull(actual); }
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)); }
public void WhenGenerateDataTableResultViewModel_ThenSucceed() { DataTableRequestModel model = new DataTableRequestModel { iDisplayLength = 10 }; ServiceOfferingClientDataTable dataTable = new ServiceOfferingClientDataTable(MockHttpContextFactory.CreateRequest(), User); Target.GenerateDataTableResultViewModel(model, dataTable); }
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]); }
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)); }
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)); }
private static DataTableResponseModel <UserModel> GetDataTableResponse(DataTableRequestModel model) { // Queryable Data var query = DummyUsers.AsQueryable(); // Generate DataTable Response var result = query.GetDataTableResponse(model); return(result); }
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); }
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()); }
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); }
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); }
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); }
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); }