ready for database
This commit is contained in:
40
Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs
Normal file
40
Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.Domain.Queries;
|
||||
using Apollon.EntityFramework.DTOs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.EntityFramework.Queries
|
||||
{
|
||||
public class GetAllTournamentsQuery : IGetAllTournamentsQuery
|
||||
{
|
||||
private readonly TournamentsDBContextFactory _contextFactory;
|
||||
|
||||
public GetAllTournamentsQuery(TournamentsDBContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Tournament>> Execute()
|
||||
{
|
||||
using (TournamentsDBContext context = _contextFactory.Create())
|
||||
{
|
||||
IEnumerable<TournamentDto> tournamentsDtos = await context.Tournaments.ToListAsync();
|
||||
|
||||
return tournamentsDtos.Select(y => new Tournament(
|
||||
y.Id,
|
||||
y.Organisation,
|
||||
y.TournamentName,
|
||||
y.Competition,
|
||||
y.StartDate,
|
||||
y.EndDate,
|
||||
y.Location,
|
||||
y.Rounds));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user