public async Task <ActionResult <IList <RequisitionDetail> > > GetAllPendingRequisitions(int id) { Console.WriteLine("android called for pending retrievals"); var clerk = await _clkService.findEmployeeByIdAsync(id); var collectionpoints = await _clkService.findAllCollectionPointAsync(); var currCollectionpoint = collectionpoints.Where(x => x.clerkId == clerk.Id); var currCollectionpoint2 = currCollectionpoint.Select(x => x.Id); var departments = await _clkService.findAllDepartmentAsync(); var currDepartments = departments.Where(x => currCollectionpoint2.Contains(x.CollectionId)); var currDepartments2 = currDepartments.Select(x => x.Id); var employees = await _clkService.findEmployeesAsync(); var currEmployees = employees.Where(x => currDepartments2.Contains(x.departmentId)); var currEmployees2 = currEmployees.Select(x => x.Id); var requisitions = await _clkService.findAllRequsitionAsync(); var allRD = await _clkService.findAllRequsitionDetailsAsync(); var nonDeliveredRD = allRD.Where(x => x.status != "Delivered"); var nonDeclinedRD = nonDeliveredRD.Where(x => x.status != "Declined"); var nonApprovedRD = nonDeclinedRD.Where(x => x.status != "Applied"); var result = nonApprovedRD.Where(x => x.reqQty != x.rcvQty); var requisition = result.Select(x => x.RequisitionId); HashSet <int> uniqueRequisitionID = new HashSet <int>(); foreach (int i in requisition) { uniqueRequisitionID.Add(i); } List <Requisition> currentRequisitions = new List <Requisition>(); foreach (Requisition r in requisitions) { foreach (int i in uniqueRequisitionID) { if (r.Id == i && currEmployees2.Contains(r.EmployeeId)) { currentRequisitions.Add(r); } } } var currentRequisitions2 = currentRequisitions.Select(x => x.Id); var result2 = result.Where(x => currentRequisitions2.Contains(x.RequisitionId)); if (result2 != null) { //convert to json file Console.WriteLine("Sent requisition details"); return(Ok(result2)); } else { //in case there is nothing to process return(NotFound("No pending requistions")); } }