public async Task <ActionResult <Department> > autoRevokeDelegate() { var allDept = await _clerkService.findAllDepartmentAsync(); var allEmp = await _clerkService.findEmployeesAsync(); var allDelegate = allEmp.Where(x => x.role.Equals("DELEGATE")); Boolean revoked = false; foreach (Department dp in allDept) { if (DateTime.Compare(dp.delgtEndDate, DateTime.Now) < 0) { Console.WriteLine("revoking " + dp.deptName + " delegate"); revoked = true; dp.delgtEndDate = Convert.ToDateTime(null); dp.delgtStartDate = Convert.ToDateTime(null); _deptService.updateDeptDelegate(dp); Employee currDelegate = allDelegate.Where(x => x.departmentId == dp.Id).FirstOrDefault(); if (currDelegate != null) { _deptService.updateDeptEmpRevoke(allDelegate.Where(x => x.departmentId == dp.Id).FirstOrDefault().Id, "STAFF"); } } } if (revoked) { return(Ok("done")); } else { return(Ok("nothing to revoke")); } }
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")); } }