public async Task <PagedList <VendorDomainObj> > GetVendors(VendorParameters vendorParameters) { Func <VendorDomainObj, bool> filterCriteria; var vendorStatus = vendorParameters.VendorStatus.ToUpper(); if (vendorStatus == "ACTIVE") { filterCriteria = v => v.IsActive == true; } else if (vendorStatus == "INACTIVE") { filterCriteria = v => v.IsActive == false; } else { filterCriteria = v => v.IsActive == true || v.IsActive == false; } var vendorList = DbContext.VendorDomainObj.Where(filterCriteria).AsQueryable(); SearchByName(ref vendorList, vendorParameters.Name); return(await PagedList <VendorDomainObj> .ToPagedList( vendorList.OrderBy(v => v.Name), vendorParameters.PageNumber, vendorParameters.PageSize)); }
public async Task <IActionResult> List([FromQuery] int?pageNumber, int?pageSize) { var pagingParams = new VendorParameters { PageNumber = pageNumber ?? 1, PageSize = pageSize ?? 10 }; var pagedList = await _repository.Vendor.GetVendors(pagingParams); return(View(pagedList)); }
public async Task ShouldGetAllVendorDomainObjsUsingRepositoryBase() { var vendorParams = new VendorParameters { PageNumber = 1, PageSize = 10 }; var vendors = await _vendorRepo.GetVendors(vendorParams); var count = vendors.Count(); Assert.Equal(6, count); }
public async Task <IActionResult> GetAllVendors([FromQuery] VendorParameters vendorParameters) { if (vendorParameters.VendorStatus != null && !vendorParameters.IsValidVendorStatus) { return(BadRequest(new { message = "Valid vendor status codes are 'Active', 'Inactive', and 'All'." })); } var vendors = await _repository.Vendor.GetVendors(vendorParameters); var metadata = new { vendors.TotalCount, vendors.PageSize, vendors.CurrentPage, vendors.TotalPages, vendors.HasNext, vendors.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(vendors)); }