public async Task <ActionResult <IList <DisbursementList> > > GetNearestDisbursementListByDeptId(int id) { var allDisbursement = await _clerkService.findAllDisbursementListAsync(); List <DisbursementList> allDisbursementUnderDept = allDisbursement.Where(x => x.DepartmentId == id).ToList(); List <DateTime> dateList = new List <DateTime>(); foreach (DisbursementList dist in allDisbursementUnderDept) { dateList.Add(dist.date); } dateList.Sort(); //below for testing //DateTime now = new DateTime(2020, 8, 31, 0, 0, 0); DateTime now = DateTime.Now; List <DateTime> dateListWithoutHistory = new List <DateTime>(); foreach (DateTime date in dateList) { if (date > now) { dateListWithoutHistory.Add(date); } } Console.WriteLine(dateListWithoutHistory.First()); DateTime nearestDisbursementDate = dateListWithoutHistory.First(); List <DisbursementList> nearestDisbursementList = new List <DisbursementList>(); foreach (DisbursementList dist in allDisbursementUnderDept) { if (dist.date == nearestDisbursementDate) { nearestDisbursementList.Add(dist); } } if (nearestDisbursementList.Any()) { //Docs says that Ok(...) will AUTO TRANSFER result into JSON Type return(Ok(nearestDisbursementList)); } else { return(NotFound("No disbursement list under this department.")); } }
public async Task <ActionResult <List <DisbursementList> > > GetAllDisbursementList(int id) { var clerk = await _clkService.findEmployeeByIdAsync(id); var collectionPts = await _clkService.findAllCollectionPointAsync(); var currCollectionPts = collectionPts.Where(x => x.clerkId == clerk.Id); var currDeliveryPoint = currCollectionPts.Select(x => x.collectionPoint); var allDL = await _clkService.findAllDisbursementListAsync(); var futureDL = allDL.Where(x => DateTime.Compare(x.date, DateTime.Now) >= 0); var result = futureDL.Where(x => currDeliveryPoint.Contains(x.deliveryPoint)); foreach (DisbursementList dl in result) { Console.WriteLine("id: " + dl.id + " dept id: " + dl.DepartmentId); } if (result != null) { return(Ok(result)); } else { return(NotFound("nothing pending")); } }
public async Task <ActionResult <DisbursementList> > GetLatestDisbursementByDeptId(int id) { var allDisbursement = await _clerkService.findAllDisbursementListAsync(); List <DisbursementList> allDisbursementUnderDept = allDisbursement.Where(x => x.DepartmentId == id).ToList(); if (allDisbursementUnderDept.Any()) { //Docs says that Ok(...) will AUTO TRANSFER result into JSON Type return(Ok(allDisbursementUnderDept[allDisbursementUnderDept.Count - 1])); } else { return(NotFound("No disbursement list under this department.")); } }
public async Task <ActionResult <List <DisbursementList> > > GetAllDisbursementList(int id) { var clerk = await _clkService.findEmployeeByIdAsync(id); var collectionPts = await _clkService.findAllCollectionPointAsync(); var currCollectionPts = collectionPts.Where(x => x.clerkId == clerk.Id); var currDeliveryPoint = currCollectionPts.Select(x => x.collectionPoint); var allDL = await _clkService.findAllDisbursementListAsync(); var result = allDL.Where(x => currDeliveryPoint.Contains(x.deliveryPoint)); List <DisbursementList> resultDL = new List <DisbursementList>(); foreach (DisbursementList dl in result) { if (dl.status.Equals("delivering")) { resultDL.Add(dl); } } foreach (DisbursementList dl in result) { if (dl.status.Equals("delivered")) { resultDL.Add(dl); } } foreach (DisbursementList dl in result) { if (dl.status.Equals("completed")) { resultDL.Add(dl); } } if (resultDL != null) { return(Ok(resultDL)); } else { return(NotFound("nothing pending")); } }
public async Task <ActionResult <Department> > disbursementreminder() { var allDisbursement = await _clerkService.findAllDisbursementListAsync(); var futureDisbursement = allDisbursement.Where(x => DateTime.Compare(x.date, DateTime.Today) > 0); var tmrDisbursement = futureDisbursement.Where(x => DateTime.Compare(x.date, DateTime.Today.AddDays(2)) < 0); var allEmp = await _clerkService.findEmployeesAsync(); var allRep = allEmp.Where(x => x.role.Equals("REPRESENTATIVE")); foreach (DisbursementList dl in tmrDisbursement) { String str = await _emailService.SendMail(allRep.Where(x => x.departmentId == dl.DepartmentId).FirstOrDefault().email, "Upcoming Disbursement", "You have an upcoming disbursement on the " + dl.date.ToString().Substring(0, 10)); } return(Ok("done")); }