Пример #1
0
        public async Task <IActionResult> QueryPaginAsync(SelectAttendanceDto model)
        {
            var result = await _service.QueryPaginAsync(model);

            return(Ok(result));
        }
        public async Task <ReturnPagin <List <ReturnAttendanceDto> > > QueryPaginAsync(SelectAttendanceDto model)
        {
            var result = new ReturnPagin <List <ReturnAttendanceDto> >();

            var attendances = _context.Attendances.Include(i => i.StaffInfo).AsNoTracking();

            if (model.BeginTime.HasValue)
            {
                attendances = attendances.Where(i => i.CreateTime >= model.BeginTime);
            }

            if (model.EndTime.HasValue)
            {
                attendances = attendances.Where(i => i.CreateTime <= model.EndTime);
            }

            if (model.IsLate.HasValue)
            {
                attendances = attendances.Where(i => i.IsLate == model.IsLate);
            }

            if (model.IsLeaveEarly.HasValue)
            {
                attendances = attendances.Where(i => i.IsLeaveEarly == model.IsLeaveEarly);
            }

            if (model.StaffInfoId.HasValue)
            {
                attendances = attendances.Where(i => i.StaffInfoId == model.StaffInfoId);
            }

            result.Count = await attendances.CountAsync();

            result.Page   = model.Page;
            result.Number = model.Number;
            result.Items  = await attendances.OrderByDescending(i => i.CreateTime)
                            .Pagin(model)
                            .Select(i => new ReturnAttendanceDto
            {
                IsLate        = i.IsLate,
                IsLeaveEarly  = i.IsLeaveEarly,
                Id            = i.Id,
                OffworkTime   = i.OffworkTime,
                StaffInfoName = i.StaffInfo.Name,
                WorkingTime   = i.WorkingTime
            }).ToListAsync();

            return(result);
        }