75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
using Events.EF.Data.MSSQL;
|
|
using Events.EF.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace GraphQLServer.SetupGraphQL;
|
|
|
|
public class Queries
|
|
{
|
|
[UsePaging]
|
|
[UseProjection]
|
|
[UseFiltering]
|
|
[UseSorting]
|
|
public IQueryable<Country> GetCountries([Service] EventsContext ctx) => ctx.Countries.AsNoTracking();
|
|
|
|
[UsePaging]
|
|
[UseProjection]
|
|
[UseFiltering]
|
|
[UseSorting]
|
|
public IQueryable<Sport> GetSports([Service] EventsContext ctx) => ctx.Sports.AsNoTracking();
|
|
|
|
[UsePaging]
|
|
[UseProjection]
|
|
[UseFiltering]
|
|
[UseSorting]
|
|
public IQueryable<Person> GetPeople([Service] EventsContext ctx) => ctx.People.AsNoTracking();
|
|
|
|
public async Task<PeoplePage> GetPeoplePage(
|
|
[Service] EventsContext ctx,
|
|
int pageNumber = 1,
|
|
int pageSize = 10)
|
|
{
|
|
pageNumber = Math.Max(1, pageNumber);
|
|
pageSize = Math.Clamp(pageSize, 1, 100);
|
|
|
|
var baseQuery = ctx.People
|
|
.AsNoTracking()
|
|
.OrderBy(p => p.Id);
|
|
|
|
var totalCount = await baseQuery.CountAsync();
|
|
|
|
var items = await baseQuery
|
|
.Skip((pageNumber - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToListAsync();
|
|
|
|
return new PeoplePage
|
|
{
|
|
TotalCount = totalCount,
|
|
PageNumber = pageNumber,
|
|
PageSize = pageSize,
|
|
Items = items
|
|
};
|
|
}
|
|
|
|
[UsePaging]
|
|
[UseProjection]
|
|
[UseFiltering]
|
|
[UseSorting]
|
|
public IQueryable<Event> GetEvents([Service] EventsContext ctx) => ctx.Events.AsNoTracking();
|
|
|
|
[UsePaging]
|
|
[UseProjection]
|
|
[UseFiltering]
|
|
[UseSorting]
|
|
public IQueryable<Event> GetEventsForDate([Service] EventsContext ctx, DateOnly date) =>
|
|
ctx.Events.AsNoTracking()
|
|
.Where(e => e.EventDate == date);
|
|
|
|
[UsePaging]
|
|
[UseProjection]
|
|
[UseFiltering]
|
|
[UseSorting]
|
|
public IQueryable<Registration> GetRegistrations([Service] EventsContext ctx) => ctx.Registrations.AsNoTracking();
|
|
}
|