clean up a bit

This commit is contained in:
Natlinux
2022-11-11 01:56:15 +01:00
parent d4dd7a545a
commit 83ce97c501
16 changed files with 47 additions and 29 deletions

View File

@@ -8,11 +8,12 @@ using System.Threading.Tasks;
namespace Apollon.EntityFramework
{
public class TournamentsDbContext : DbContext
public class ApplicationDbContext : DbContext
{
public TournamentsDbContext(DbContextOptions options) : base(options)
public ApplicationDbContext(DbContextOptions options) : base(options)
{
}
public DbSet<TournamentDto> Tournaments { get; set; }
public DbSet<CompetitionDto> Competition { get; set; }
}
}

View File

@@ -7,18 +7,18 @@ using System.Threading.Tasks;
namespace Apollon.EntityFramework
{
public class TournamentsDbContextFactory
public class ApplicationDBContextFactory
{
private readonly DbContextOptions _options;
public TournamentsDbContextFactory(DbContextOptions options)
public ApplicationDBContextFactory(DbContextOptions options)
{
_options = options;
}
public TournamentsDbContext Create()
public ApplicationDbContext Create()
{
return new TournamentsDbContext(_options);
return new ApplicationDbContext(_options);
}
}
}

View File

@@ -8,12 +8,12 @@ using System.Threading.Tasks;
namespace Apollon.EntityFramework
{
public class TournamentsDesignTimeDbContextFactory : IDesignTimeDbContextFactory<TournamentsDbContext>
public class ApplicationDesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public TournamentsDbContext CreateDbContext(string[] args = null)
public ApplicationDbContext CreateDbContext(string[] args = null)
{
return new TournamentsDbContext(new DbContextOptionsBuilder().UseSqlServer("Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true").Options);
return new ApplicationDbContext(new DbContextOptionsBuilder().UseSqlServer("Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true").Options);
}
}
}

View File

@@ -12,16 +12,16 @@ namespace Apollon.EntityFramework.Commands
{
public class CreateTournamentCommand : ICreateTournamentCommand
{
private readonly TournamentsDbContextFactory _contextFactory;
private readonly ApplicationDBContextFactory _contextFactory;
public CreateTournamentCommand(TournamentsDbContextFactory contextFactory)
public CreateTournamentCommand(ApplicationDBContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
public async Task Execute(Tournament tournament)
{
using (TournamentsDbContext context = _contextFactory.Create())
using (ApplicationDbContext context = _contextFactory.Create())
{
TournamentDto tournamentDto = new TournamentDto()
{

View File

@@ -11,16 +11,16 @@ namespace Apollon.EntityFramework.Commands
{
public class DeleteTournamentCommand : IDeleteTournamentCommand
{
private readonly TournamentsDbContextFactory _contextFactory;
private readonly ApplicationDBContextFactory _contextFactory;
public DeleteTournamentCommand(TournamentsDbContextFactory contextFactory)
public DeleteTournamentCommand(ApplicationDBContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
public async Task Execute(Guid id)
{
using (TournamentsDbContext context = _contextFactory.Create())
using (ApplicationDbContext context = _contextFactory.Create())
{
TournamentDto tournamentDto = new TournamentDto()
{

View File

@@ -11,16 +11,16 @@ namespace Apollon.EntityFramework.Commands
{
public class UpdateTournamentCommand : IUpdateTournamentCommand
{
private readonly TournamentsDbContextFactory _contextFactory;
private readonly ApplicationDBContextFactory _contextFactory;
public UpdateTournamentCommand(TournamentsDbContextFactory contextFactory)
public UpdateTournamentCommand(ApplicationDBContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
public async Task Execute(Tournament tournament)
{
using (TournamentsDbContext context = _contextFactory.Create())
using (ApplicationDbContext context = _contextFactory.Create())
{
TournamentDto tournamentDto = new TournamentDto()
{

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.EntityFramework.DTOs
{
public class CompetitionDto
{
public int Id { get; set; }
public string CompetitionName { get; set; }
public string CompetitionImage { get; set; }
}
}

View File

@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Apollon.EntityFramework.Migrations
{
[DbContext(typeof(TournamentsDbContext))]
[DbContext(typeof(ApplicationDbContext))]
[Migration("20220820005557_initial")]
partial class initial
{

View File

@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Apollon.EntityFramework.Migrations
{
[DbContext(typeof(TournamentsDbContext))]
[DbContext(typeof(ApplicationDbContext))]
[Migration("20220828165744_initial1")]
partial class initial1
{

View File

@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Apollon.EntityFramework.Migrations
{
[DbContext(typeof(TournamentsDbContext))]
[DbContext(typeof(ApplicationDbContext))]
[Migration("20221107194347_competition")]
partial class competition
{

View File

@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Apollon.EntityFramework.Migrations
{
[DbContext(typeof(TournamentsDbContext))]
[DbContext(typeof(ApplicationDbContext))]
[Migration("20221110003817_logo")]
partial class logo
{

View File

@@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Apollon.EntityFramework.Migrations
{
[DbContext(typeof(TournamentsDbContext))]
[DbContext(typeof(ApplicationDbContext))]
partial class TournamentsDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)

View File

@@ -12,16 +12,16 @@ namespace Apollon.EntityFramework.Queries
{
public class GetAllTournamentsQuery : IGetAllTournamentsQuery
{
private readonly TournamentsDbContextFactory _contextFactory;
private readonly ApplicationDBContextFactory _contextFactory;
public GetAllTournamentsQuery(TournamentsDbContextFactory contextFactory)
public GetAllTournamentsQuery(ApplicationDBContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
public async Task<IEnumerable<Tournament>> Execute()
{
using (TournamentsDbContext context = _contextFactory.Create())
using (ApplicationDbContext context = _contextFactory.Create())
{
IEnumerable<TournamentDto> tournamentsDtos = await context.Tournaments.ToListAsync();