Ejemplo n.º 1
0
        public async Task <PagedList <Farmer> > GetFarmersPaginated(FarmerParams farmerParams, int?userCommodityId, int?StateId)
        {
            var farmers = from f in Context.Farmers select f;

            farmers = userCommodityId == null ? farmers : farmers.Where(c => c.CommodityId == userCommodityId);
            farmers = StateId == null ? farmers : farmers.Where(c => c.stateofresidenceId == StateId);
            farmers = farmerParams.BVN == null ? farmers : farmers.Where(c => c.BVN == farmerParams.BVN);

            farmers = farmers.OrderByDescending(u => u.Id).AsQueryable();

            //ToList();

            // farmers=farmers.AsQueryable();
            //AsQueryable();

            return(await PagedList <Farmer> .CreateAsync(farmers, farmerParams.PageNumber, farmerParams.PageSize));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get([FromQuery] FarmerParams farmerParams)
        {
            ClaimsPrincipal currentUser = _contextAccessor.HttpContext.User;


            if (currentUser.HasClaim(c => c.Type == "State"))
            {
                StateId = int.Parse(currentUser.Claims.FirstOrDefault(c => c.Type == "State").Value);
            }

            if (currentUser.HasClaim(c => c.Type == "Commodity"))
            {
                CommodityId = int.Parse(currentUser.Claims.FirstOrDefault(c => c.Type == "Commodity").Value);
            }

            var farmers = await _farmerService.GetFarmersPaginated(farmerParams, CommodityId, StateId);

            var farmersToReturn = _mapper.Map <IEnumerable <FarmerForListDTO> >(farmers);

            Response.AddPagination(farmers.CurrentPage, farmers.PageSize,
                                   farmers.TotalCount, farmers.TotalPages);

            return(Ok(farmersToReturn));
        }