public IHttpActionResult TISPaginatedList([FromBody] IList <FilterModel> filters, FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <NatisExport>(filter, (FilterJoin)filterJoin); var query = dbContext .NatisExports .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <NatisExportModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <NatisExportModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <NatisExport>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var paginationList = new PaginationListModel <NatisExportModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; var totalPages = Math.Ceiling(totalCount / (float)pageSize); paginationList.Models = entities.Select(f => new Models.TISCapture.NatisExportModel { //ID = f.ID, VehicleRegistration = f.VehicleRegistration, InfringementDate = f.InfringementDate, ReferenceNumber = f.ReferenceNumber, ExportDate = f.ExportDate, DistrictID = f.DistrictID, LockedByCredentialID = f.LockedByCredentialID, LockedByName = f.LockedByCredentialID.HasValue ? string.Format("{0}, {1}", f.User.LastName, f.User.FirstName) : string.Empty, DistrictName = f.District.BranchName, }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
public IHttpActionResult GetCameraPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.Camera>(filter, (Kapsch.Core.Filters.FilterJoin)filterJoin); var query = dbContext .Cameras .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <CameraModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <CameraModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <Camera>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var paginationList = new PaginationListModel <CameraModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; paginationList.Models = entities.Select(f => new CameraModel { ID = f.ID, AdapterType = (Models.Enums.CameraAdapterType)f.CameraAdapterType, ConfigJson = f.ConfigJson, CreatedTimeStamp = f.CreatedTimeStamp, ConnectToHost = f.ConnectToHost == "1", DeviceConnectionType = (Models.Enums.CameraConnectionType)f.CameraConnectionType, DeviceStatus = (Models.Enums.CameraStatusType)f.CameraStatusType, FriendlyName = f.FriendlyName, GpsLatitude = f.GpsLatitude, GpsLongitude = f.GpsLongitude, IsEnabled = f.IsEnabled == "1", ModifiedTimeStamp = f.ModifiedTimeStamp }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
public IHttpActionResult GetInfringementLocationPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.InfringementLocation>(filter, (Kapsch.Core.Filters.FilterJoin)filterJoin); var query = dbContext .InfringementLocations .Include(f => f.Court) .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <InfringementLocationModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <InfringementLocationModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <InfringementLocation>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var paginationList = new PaginationListModel <InfringementLocationModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; paginationList.Models = entities.Select(f => new InfringementLocationModel { ID = f.ID, Code = f.Code, Description = f.Description, CourtID = f.CourtID, CourtName = f.Court == null ? string.Empty : f.Court.CourtName, GpsLatitude = f.GpsLatitude, GpsLongitude = f.GpsLongitude, InfringementLocationType = (Models.Enums.InfringementLocationType)f.InfringementLocationType }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
public IHttpActionResult GetPaginatedList([FromBody] IList <FilterModel> filters, FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.MobileDevice>(filter, (FilterJoin)filterJoin); var query = dbContext .MobileDevices .Include(f => f.District) .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <MobileDeviceModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <MobileDeviceModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <MobileDevice>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var totalPages = Math.Ceiling(totalCount / (float)pageSize); var paginationList = new PaginationListModel <MobileDeviceModel>(); paginationList.Models = entities.Select(f => new MobileDeviceModel { ID = f.ID, DeviceID = f.DeviceID, CreatedTimestamp = f.CreatedTimestamp, DistrictID = f.District == null ? default(long?) : f.District.ID, DistrictName = f.District == null ? string.Empty : f.District.BranchName, SerialNumber = f.SerialNumber, Status = (Models.Enums.MobileDeviceStatus)f.Status }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
public IHttpActionResult GetCountryPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { if (string.IsNullOrWhiteSpace(orderPropertyName)) { orderPropertyName = "Description"; } using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.Country>(filter, (Kapsch.Core.Filters.FilterJoin)filterJoin); var query = dbContext .Countries .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <CountryModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <CountryModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <Country>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var paginationList = new PaginationListModel <CountryModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; paginationList.Models = entities.Select(f => new CountryModel { ID = f.ID, Description = f.Description, ModifiedTimestamp = f.ModifiedTimestamp }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
protected override IQueryable <Role> ApplyFilter(IQueryable <Role> query, RoleFilter filter) { if (filter == null) { return(query); } var exp = FilterConverter.Convert <IRole, Role>(filter.Expression); return(query.Where(exp)); }
public IHttpActionResult GetSystemFunctionPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { //dbContext.Database.Log = (s) => Debug.WriteLine(s); var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.SystemFunction>(filter, (Kapsch.Core.Filters.FilterJoin)filterJoin); var query = dbContext .SystemFunctions .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <SystemFunctionModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <SystemFunctionModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .OrderByMember(PropertyHelper.GetSortingValue <SystemFunctionModel>(orderPropertyName)) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <SystemFunction>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = (asc ? pageResults.OrderBy(orderPropertyName) : pageResults.OrderByDescending(orderPropertyName)).ToList(); } var paginationList = new PaginationListModel <SystemFunctionModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; paginationList.Models = entities.Select(f => new SystemFunctionModel { ID = f.ID, Name = f.Name, Description = f.Description }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
public void Convert_ValidSourceFilter_ReturnConvertedFilter() { // Arrange var filterClause = MakeFilter("[Name] IN ('john')", "[Surname] IN ('doe', 'smith')", "[AGE] IN (18, 65)"); // Act var filter = FilterConverter.Convert(filterClause.Clause); // Assert filter.Should().Be( "(Name != null && (Name = \"john\")) AND (Surname != null && (Surname = \"doe\" OR Surname = \"smith\")) AND (AGE != null && (AGE = 18 OR AGE = 65))"); }
public void Convert_StringFieldWithNumberValues_ReturnEscapedNumbers() { // Arrange var filterClause = MakeFilter("[Name] IN ('john', '1')", "[AGE] IN (18, 65)"); // Act var filter = FilterConverter.Convert(filterClause.Clause); // Assert filter.Should().Be( "(Name != null && (Name = \"john\" OR Name = \"1\")) AND (AGE != null && (AGE = 18 OR AGE = 65))"); }
public string GetCondition(string TableName, params Packet[] packets) { string Condition = ""; packets[packets.Length - 1].Couple = Couple.None; foreach (Packet packet in packets) { IFilter filter = new Filter(TableName, packet.Left, packet.Right.ToString(), packet.Sign, packet.Couple); Condition += $"{FilterConverter.Convert(filter)} "; } return(Condition); }
public IHttpActionResult GetPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Kapsch.Core.Data.CameraStatus>(filter, (Kapsch.Core.Filters.FilterJoin)filterJoin); var query = dbContext .DeviceStatuses .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <CameraStatusModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <CameraStatusModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <CameraStatus>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var totalPages = Math.Ceiling(totalCount / (float)pageSize); var paginationList = new PaginationListModel <CameraStatusModel>(); paginationList.Models = entities.Select(f => new CameraStatusModel { DeviceID = f.CameraID, CreatedTimeStamp = f.CreatedTimeStamp, CameraStatusType = (Core.Gateway.Models.Enums.CameraStatusType)f.CameraStatusType }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
protected override IQueryable <StarredThread> ApplyFilter(IQueryable <StarredThread> query, StarredThreadFilter filter) { if (filter == null) { return(query); } var exp = FilterConverter.Convert <IStarredTread, StarredThread>(filter.Expression, new Dictionary <Type, Type> { [typeof(IUserReference)] = typeof(UserReference), }); return(query.Where(exp)); }
public IHttpActionResult GetPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new Kapsch.RTE.Data.DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <CameraPointData>(filter, (Core.Filters.FilterJoin)filterJoin); var query = dbContext .CameraPointsData .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <CameraPointData>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <CameraPointData>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <CameraPointData>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var totalPages = Math.Ceiling(totalCount / (float)pageSize); var paginationList = new PaginationListModel <AtPointModel>(); foreach (CameraPointData cameraPointData in entities) { AtPointModel model = JsonConvert.DeserializeObject <AtPointModel>(cameraPointData.Json); paginationList.Models.Add(model); } paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
protected override IQueryable <UserReference> ApplyFilter(IQueryable <UserReference> query, UserReferenceFilter filter) { if (filter == null) { return(query); } var exp = FilterConverter.Convert <IUserReference, UserReference>(filter.Expression, new Dictionary <Type, Type> { [typeof(IRole)] = typeof(Role), }); return(query.Where(exp)); }
public string GetOnCondition(string TableName, params Packet[] Packets) { string Condition = ""; foreach (Packet packet in Packets) { if (packet.Right.ToString().Contains(".")) { IFilter filter = new Filter(TableName, packet.Left, packet.Right.ToString(), packet.Sign, packet.Couple); Condition += $"{FilterConverter.Convert(filter,true)}"; } else { Condition += GetCondition(TableName, packet); } } return(Condition); }
public string GetCondition(string TableName, Packet packet) { Filter filter = new Filter(TableName, packet.Left, packet.Right.ToString(), packet.Sign, packet.Couple); return(FilterConverter.Convert(filter)); }
public IHttpActionResult GetDistrictPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.District>(filter, (Kapsch.Core.Filters.FilterJoin)filterJoin); var query = dbContext .Districts .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <DistrictModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <DistrictModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <District>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var paginationList = new PaginationListModel <DistrictModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; paginationList.Models = entities.Select(f => new DistrictModel { ID = f.ID, Province = f.Province, Town = f.Town, Suburb = f.Suburb, Street = f.Street, Code = f.Code, POBox = f.POBox, PostalCode = f.PostalCode, PostalStreet = f.PostalStreet, PostalSuburb = f.PostalSuburb, PostalTown = f.PostalTown, TicketPre = f.TicketPre, TicketPost = f.TicketPost, TicketSequenceName = f.TicketSequenceName, CaseSequenceName = f.CaseSequenceName, Section56TicketPre = f.Section56TicketPre, Section56TicketPost = f.Section56TicketPost, TrafficTicketPre = f.TrafficTicketPre, TrafficTicketPost = f.TrafficTicketPost, DepartmantName = f.DepartmantName, Telephone = f.Telephone, Faks = f.Faks, CaseNoPre = f.CaseNoPre, CaseNoPost = f.CaseNoPost, DistrictAll = f.DistrictAll, RegionID = f.RegionID, DistrictTypeID = f.DistrictTypeID, AccountNo = f.AccountNo, Bank = f.Bank, Branch = f.Branch, BranchCode = f.BranchCode, AccountType = f.AccountType, BankDetails = f.BankDetails, ExtTicketPost = f.ExtTicketPost, IACode = f.IACode, NatisNumber = f.NatisNumber, NatisSequenceName = f.NatisSequenceName, OfficeHours = f.OfficeHours, Sectiontion67Pre = f.Sectiontion67Pre, Section67Post = f.Section67Post, J175Printing = f.J175Printing, CentralCaptureIndicator = f.CentralCaptureIndicator, ActiveIndicator = f.ActiveIndicator, EmailAddress = f.EmailAddress, ITicketPre56 = f.ITicketPre56, ITicketSeqName56 = f.ITicketSeqName56, ITicketPre341 = f.ITicketPre341, ITicketSeqName341 = f.ITicketSeqName341, BranchName = f.BranchName, SiteLogo = f.SiteLogo, PaymentOptions = f.PaymentOptions }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
public IHttpActionResult GetCourtPaginatedList([FromBody] IList <FilterModel> filters, Kapsch.Gateway.Models.Shared.Enums.FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.Court>(filter, (Kapsch.Core.Filters.FilterJoin)filterJoin); var query = dbContext .Courts .Include(f => f.AddressInfo) .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <CourtModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <CourtModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <Court>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var paginationList = new PaginationListModel <CourtModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; paginationList.Models = entities.Select(f => new CourtModel { ID = f.ID, CourtName = f.CourtName, CourtTime = f.CourtTime, PersonInfoID = f.PersonInfoID, ContemptAmount = f.ContemptAmount, ContemptDays = f.ContemptDays, BankingInfoID = f.BankingInfoID, DistrictID = f.DistrictID, CasePost = f.CasePost, CasePre = f.CasePre, SequenceName = f.SequenceName, Status = (Models.Enums.Status)f.Status, WarrantExpireDays = f.WarrantExpireDays, WarrantLetterGrace = f.WarrantLetterGrace, WarrantPost = f.WarrantPost, WarrantPre = f.WarrantPre, CaptureDate = f.CaptureDate, DaysToCourtDate = f.DaysToCourtDate, OverAllocation = f.OverAllocation, ReIssueInvalidServing = f.ReIssueInvalidServing, SummonsExpireDays = f.SummonsExpireDays, TypeOfServiceAllowed = f.TypeOfServiceAllowed, UserId = f.CredentialID, Address = f.AddressInfo == null ? null : new AddressInfoModel { ID = f.AddressInfo.ID, AddressTypeID = (long)f.AddressInfo.AddressTypeID, SourceID = f.AddressInfo.SourceID, PersonInfoID = f.AddressInfo.PersonInfoID, Line1 = f.AddressInfo.Line1, Line2 = f.AddressInfo.Line2, Suburb = f.AddressInfo.Suburb, Town = f.AddressInfo.Town, Country = f.AddressInfo.Country, Code = f.AddressInfo.Code, CreatedDate = f.AddressInfo.CreatedDate, CreatedUserDetailID = f.AddressInfo.CreatedCredentialID, IsPrefferedIndicator = f.AddressInfo.IsPrefferedIndicator, Latitude = f.AddressInfo.Latitude, Longitude = f.AddressInfo.Longitude } }) .ToList(); paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }
public IHttpActionResult GetPaginatedList([FromBody] IList <FilterModel> filters, FilterJoin filterJoin, bool asc, string orderPropertyName, int pageIndex, int pageSize) { using (var dbContext = new DataContext()) { var totalCount = 0; var filter = filters.Select(f => FilterConverter.Convert(f)).ToList(); var func = ExpressionBuilder.GetExpression <Data.User>(filter, (FilterJoin)filterJoin); var query = dbContext .Users .AsNoTracking(); if (func != null) { query = query.Where(func); } var orderedQuery = asc ? query.OrderByMember(PropertyHelper.GetSortingValue <UserModel>(orderPropertyName)) : query.OrderByMemberDescending(PropertyHelper.GetSortingValue <UserModel>(orderPropertyName)); var resultsToSkip = (pageIndex - 1) * pageSize; var pageResults = orderedQuery .Skip(resultsToSkip) .Take(pageSize) .GroupBy(f => new { Total = query.Count() }) .FirstOrDefault(); var entities = new List <User>(); if (pageResults != null) { totalCount = pageResults.Key.Total; entities = pageResults.ToList(); } var paginationList = new PaginationListModel <UserModel>(); paginationList.PageIndex = pageIndex; paginationList.PageSize = pageSize; var userIDs = entities.Select(f => f.ID).ToList(); var credentials = dbContext.Credentials .Where(f => f.EntityType == Data.Enums.EntityType.User && userIDs.Contains(f.EntityID)) .ToList(); var models = new List <UserModel>(); foreach (var entity in entities) { var userModel = new UserModel { ID = entity.ID, FirstName = entity.FirstName, LastName = entity.LastName, MobileNumber = entity.MobileNumber, CreatedTimestamp = entity.CreatedTimestamp, Status = (Models.Enums.UserStatus)entity.Status, Email = entity.Email, IsOfficer = entity.IsOfficer == "1", ExternalID = entity.ExternalID }; var credential = credentials.FirstOrDefault(f => f.EntityID == userModel.ID); if (credential != null) { userModel.UserName = credential.UserName; } models.Add(userModel); } paginationList.Models = models; paginationList.TotalCount = totalCount; return(Ok(paginationList)); } }