Updating
This commit is contained in:
36
teams/Services/TeamsRepository.cs
Normal file
36
teams/Services/TeamsRepository.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Teams.DbContexts;
|
||||
using Teams.Entities;
|
||||
|
||||
namespace Teams.Services
|
||||
{
|
||||
public class TeamsRepository : ITeamsRepository
|
||||
{
|
||||
private readonly MlbGameDayContext _context;
|
||||
|
||||
public TeamsRepository(MlbGameDayContext context)
|
||||
{
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
public async Task<Team?> GetTeamAsync(int teamId)
|
||||
{
|
||||
return await _context.Teams.Where(t => t.Id == teamId).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<Team>, PaginationMetadata)> GetTeamsAsync(int pageNumber, int pageSize)
|
||||
{
|
||||
var collection = _context.Teams as IQueryable<Team>;
|
||||
var totalItemCount = await collection.CountAsync();
|
||||
var paginationMetadata = new PaginationMetadata(totalItemCount, pageSize, pageNumber);
|
||||
var collectionToReturn = await collection.OrderBy(t => t.Name)
|
||||
.Skip(pageSize * (pageNumber - 1))
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return (collectionToReturn, paginationMetadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user