Exemplo n.º 1
0
        public async Task <PagedResultOutput <AttendanceDo> > GetAttendances(GetAttendanceDtosInput input)
        {
            try
            {
                var query = _attendanceRepository.GetAttendanceDos();
                if (input.EmployeeNumber != string.Empty)
                {
                    var employee = _employeeRepository.FirstOrDefault(emp => emp.Number == input.EmployeeNumber);
                    if (employee == null)
                    {
                        return(new PagedResultOutput <AttendanceDo>());
                    }

                    query = query.Where(at => at.EmployeeId == employee.Id);
                    if (input.StartDate != null)
                    {
                        if (input.EndDate == null)
                        {
                            query = query.Where(at => at.Date == input.StartDate.Value);
                        }
                        else
                        {
                            query = query.Where(at => at.ClockIn >= input.StartDate && at.ClockOut <= input.EndDate);
                        }
                    }
                }
                else
                {
                    if (input.StartDate != null)
                    {
                        if (input.EndDate == null)
                        {
                            query = query.Where(at => at.Date == input.StartDate.Value);
                        }
                        else
                        {
                            query = query.Where(at => at.ClockIn >= input.StartDate && at.ClockOut <= input.EndDate);
                        }
                    }
                }

                var atQuerible = query.AsQueryable();
                var itemCount  = await atQuerible.CountAsync();

                var attendanceList = await atQuerible
                                     .OrderBy(input.Sorting)
                                     .PageBy(input)
                                     .ToListAsync();

                return(new PagedResultOutput <AttendanceDo>(itemCount, attendanceList));
            }
            catch (Exception ex)
            {
                return(new PagedResultOutput <AttendanceDo>());
            }
        }
Exemplo n.º 2
0
        public List <AttendanceDto> GetAttendanceDtos(GetAttendanceDtosInput input)
        {
            var query = _attendanceRepository.GetAll();

            if (input.EmployeeNumber != string.Empty)
            {
                var employee = _employeeRepository.FirstOrDefault(emp => emp.Number == input.EmployeeNumber);
                if (employee == null)
                {
                    return(new List <AttendanceDto>());
                }
                query = query.Where(at => at.EmployeeId == employee.Id);
                if (input.StartDate != null)
                {
                    if (input.EndDate == null)
                    {
                        query = query.Where(at => at.Date == input.StartDate.Value);
                    }
                }
                else
                {
                    query = query.Where(at => at.ClockIn >= input.StartDate && at.ClockOut <= input.EndDate);
                }
            }
            else
            {
                if (input.StartDate != null)
                {
                    if (input.EndDate == null)
                    {
                        query = query.Where(at => at.Date == input.StartDate.Value);
                    }
                }
                else
                {
                    query = query.Where(at => at.ClockIn >= input.StartDate && at.ClockOut <= input.EndDate);
                }
            }
            return(Mapper.Map <List <AttendanceDto> >(query.ToList()));
        }