public IHttpActionResult Get( [FromUri] AssetFilterModel filter, [FromUri] PageInfoModel pageInfo) { filter = filter ?? new AssetFilterModel(); pageInfo = pageInfo ?? new PageInfoModel(); PagedResult <AssetDto> pagedResult; var paging = MappingHelper.MapToPageInfo(pageInfo); if (!paging.OrderBy.IsValidFor(_assetRepo.Columns)) { return(BadRequest($"Unknown field : {paging.OrderBy.Name}.")); } if (filter.IsEmpty()) { pagedResult = _assetRepo.PagedQuery(paging); return(CreateActionResultFor(pagedResult)); } // Apply filter. var query = MapToQuery(filter); pagedResult = _assetRepo.PagedQuery(paging, query); return(CreateActionResultFor(pagedResult)); }
private static AssetQuery MapToQuery(AssetFilterModel filter) => new AssetQuery { CreatedBy = filter.CreatedBy, ModifiedBy = filter.ModifiedBy, IctsReference = filter.IctsReference, Tag = filter.Tag, Serial = filter.Serial, ProductId = filter.ProductId, Description = filter.Description, InvoiceDate = filter.InvoiceDate, InvoiceNumber = filter.InvoiceNumber, Price = filter.Price, PaidBy = filter.PaidBy, Owner = filter.Owner, InstallDate = filter.InstallDate, InstalledBy = filter.InstalledBy, Remark = filter.Remark, TeamAsset = filter.TeamAsset };