public async Task <ActionResult <Page <StudentDto> > > ListAsync([FromQuery] StudentFilterPagedRequest request) { var pageSize = request.PageSize ?? 10; var pageIndex = request.PageIndex ?? 0; if (pageSize < 10) { pageSize = 10; } var totalItems = await _studentCrudService.CountAsync( new StudentSpecification( sex : request.Sex, fullname : request.Fullname, callsign : request.Callsign, group : request.Group)); var lastPageIndex = totalItems / pageSize; //if (totalItems == pageSize * lastPageIndex) // lastPageIndex--; if (pageIndex > lastPageIndex) { pageIndex = lastPageIndex; } if (pageIndex < 0) { pageIndex = 0; } var filter = new StudentSpecification( skip: pageSize * pageIndex, take: pageSize, sex: request.Sex, fullname: request.Fullname, callsign: request.Callsign, @group: request.Group); var students = await _studentCrudService.ListAsync(filter) .Select(DtoExtensions.ToDto) .ToArrayAsync(); return(new Page <StudentDto> { IsLastPage = pageIndex == lastPageIndex, PageIndex = pageIndex, PageSize = pageSize, Items = students, }); }
public async Task <bool> SeedAsync() { var count = await CrudService.CountAsync(); if (count > 0) { return(false); } await AddEntities(); return(true); }