public async Task <ActionResult <IEnumerable <LeaveReportDTO> > > GetLeaveRequestsByProfessionId(int ProfessionId) { List <LeaveReportDTO> lstReportDTO = new List <LeaveReportDTO>(); var LeavesList = (from ex in await _context.LeaveRequests.Include(ex => ex.Employee.Profession).Include(le => le.AlternativeEmp).Include(le => le.LeaveType).Where(l => l.Employee.ProfessionID == ProfessionId).ToListAsync() select ex).GroupBy(grp => grp.EmployeeID).ToList(); foreach (var item in LeavesList) { LeaveReportDTO LeaveObj = new LeaveReportDTO(); LeaveObj.ProfessionName = item.FirstOrDefault().Employee.Profession.Name; LeaveObj.ProfessionId = item.FirstOrDefault().Employee.ProfessionID; LeaveObj.EmployeeId = item.FirstOrDefault().EmployeeID; LeaveObj.EmployeeName = item.FirstOrDefault().Employee.Name; LeaveObj.lstLeaveRequest = item.ToList(); lstReportDTO.Add(LeaveObj); } return(lstReportDTO); }
public IEnumerable <LeaveReportDTO> GetLeavesForReport() { List <LeaveReportDTO> lstReportDTO = new List <LeaveReportDTO>(); var LeavesList = (from ex in _context.LeaveRequests.Include(ex => ex.Employee.Profession).Include(le => le.AlternativeEmp).Include(le => le.LeaveType).ToList() select ex).GroupBy(grp => grp.EmployeeID).ToList(); foreach (var item in LeavesList) { LeaveReportDTO LeaveObj = new LeaveReportDTO(); LeaveObj.ProfessionName = item.FirstOrDefault().Employee.Profession.Name; LeaveObj.ProfessionId = item.FirstOrDefault().Employee.ProfessionID; LeaveObj.EmployeeId = item.FirstOrDefault().EmployeeID; LeaveObj.EmployeeName = item.FirstOrDefault().Employee.Name; LeaveObj.lstLeaveRequest = item.ToList(); lstReportDTO.Add(LeaveObj); } return(lstReportDTO); }