ready for database

This commit is contained in:
Natlinux81
2022-08-20 01:41:56 +02:00
parent fcd1d90292
commit 68f0cec9d0
28 changed files with 356 additions and 36 deletions

View File

@@ -0,0 +1,44 @@
using Apollon.Domain.Commands;
using Apollon.Domain.Models;
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.Commands
{
public class CreateTournamentCommand : ICreateTournamentCommand
{
private readonly TournamentsDBContextFactory _contextFactory;
public CreateTournamentCommand(TournamentsDBContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
public async Task Execute(Tournament tournament)
{
using (TournamentsDBContext context = _contextFactory.Create())
{
TournamentDto tournamentDto = new TournamentDto()
{
Id = tournament.Id,
Organisation = tournament.Organisation,
TournamentName = tournament.TournamentName,
Competition = tournament.Competition,
StartDate = tournament.StartDate,
EndDate = tournament.EndDate,
Location = tournament.Location,
Rounds = tournament.Rounds,
};
context.Tournaments.Add(tournamentDto);
await context.SaveChangesAsync();
}
}
}
}