From 83ce97c501be88740b5525a159fae61e349eb862 Mon Sep 17 00:00:00 2001 From: Natlinux <97396587+Natlinux81@users.noreply.github.com> Date: Fri, 11 Nov 2022 01:56:15 +0100 Subject: [PATCH] clean up a bit --- Apollon.Domain/Models/Competition.cs | 1 + ...amentsDBContext.cs => ApplicationDBContext.cs} | 5 +++-- ...tFactory.cs => ApplicationDBContextFactory.cs} | 8 ++++---- ...s => ApplicationDesignTimeDbContextFactory.cs} | 6 +++--- .../Commands/CreateTournamentCommand.cs | 6 +++--- .../Commands/DeleteTournamentCommand.cs | 6 +++--- .../Commands/UpdateTournamentCommand.cs | 6 +++--- Apollon.EntityFramework/DTOs/CompetitionDto.cs | 15 +++++++++++++++ .../Migrations/20220820005557_initial.Designer.cs | 2 +- .../20220828165744_initial1.Designer.cs | 2 +- .../20221107194347_competition.Designer.cs | 2 +- .../Migrations/20221110003817_logo.Designer.cs | 2 +- .../TournamentsDbContextModelSnapshot.cs | 2 +- .../Queries/GetAllTournamentsQuery.cs | 6 +++--- Apollon.WPF/App.xaml.cs | 6 +++--- Apollon.WPF/ViewModels/EditTournamentViewModel.cs | 1 + 16 files changed, 47 insertions(+), 29 deletions(-) rename Apollon.EntityFramework/{TournamentsDBContext.cs => ApplicationDBContext.cs} (65%) rename Apollon.EntityFramework/{TournamentsDBContextFactory.cs => ApplicationDBContextFactory.cs} (63%) rename Apollon.EntityFramework/{TournamentsDesignTimeDbContextFactory.cs => ApplicationDesignTimeDbContextFactory.cs} (65%) create mode 100644 Apollon.EntityFramework/DTOs/CompetitionDto.cs diff --git a/Apollon.Domain/Models/Competition.cs b/Apollon.Domain/Models/Competition.cs index c126f70..bcdbc75 100644 --- a/Apollon.Domain/Models/Competition.cs +++ b/Apollon.Domain/Models/Competition.cs @@ -8,6 +8,7 @@ namespace Apollon.Domain.Models { public class Competition { + public int Id { get; set; } public string CompetitionName{ get; set; } public string CompetitionImage{ get; set; } } diff --git a/Apollon.EntityFramework/TournamentsDBContext.cs b/Apollon.EntityFramework/ApplicationDBContext.cs similarity index 65% rename from Apollon.EntityFramework/TournamentsDBContext.cs rename to Apollon.EntityFramework/ApplicationDBContext.cs index a439d8a..896edcc 100644 --- a/Apollon.EntityFramework/TournamentsDBContext.cs +++ b/Apollon.EntityFramework/ApplicationDBContext.cs @@ -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 Tournaments { get; set; } + public DbSet Competition { get; set; } } } diff --git a/Apollon.EntityFramework/TournamentsDBContextFactory.cs b/Apollon.EntityFramework/ApplicationDBContextFactory.cs similarity index 63% rename from Apollon.EntityFramework/TournamentsDBContextFactory.cs rename to Apollon.EntityFramework/ApplicationDBContextFactory.cs index ae4dbb2..9807d36 100644 --- a/Apollon.EntityFramework/TournamentsDBContextFactory.cs +++ b/Apollon.EntityFramework/ApplicationDBContextFactory.cs @@ -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); } } } diff --git a/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory.cs b/Apollon.EntityFramework/ApplicationDesignTimeDbContextFactory.cs similarity index 65% rename from Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory.cs rename to Apollon.EntityFramework/ApplicationDesignTimeDbContextFactory.cs index becdad2..76b4cd9 100644 --- a/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory.cs +++ b/Apollon.EntityFramework/ApplicationDesignTimeDbContextFactory.cs @@ -8,12 +8,12 @@ using System.Threading.Tasks; namespace Apollon.EntityFramework { - public class TournamentsDesignTimeDbContextFactory : IDesignTimeDbContextFactory + public class ApplicationDesignTimeDbContextFactory : IDesignTimeDbContextFactory { - 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); } } } diff --git a/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs b/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs index c4aad26..6ff9c28 100644 --- a/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs @@ -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() { diff --git a/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs b/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs index 3230cb6..491f47c 100644 --- a/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs @@ -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() { diff --git a/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs b/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs index 1f77d45..cf88789 100644 --- a/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs @@ -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() { diff --git a/Apollon.EntityFramework/DTOs/CompetitionDto.cs b/Apollon.EntityFramework/DTOs/CompetitionDto.cs new file mode 100644 index 0000000..28c61c1 --- /dev/null +++ b/Apollon.EntityFramework/DTOs/CompetitionDto.cs @@ -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; } + } +} diff --git a/Apollon.EntityFramework/Migrations/20220820005557_initial.Designer.cs b/Apollon.EntityFramework/Migrations/20220820005557_initial.Designer.cs index 191c8b7..a639019 100644 --- a/Apollon.EntityFramework/Migrations/20220820005557_initial.Designer.cs +++ b/Apollon.EntityFramework/Migrations/20220820005557_initial.Designer.cs @@ -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 { diff --git a/Apollon.EntityFramework/Migrations/20220828165744_initial1.Designer.cs b/Apollon.EntityFramework/Migrations/20220828165744_initial1.Designer.cs index 60cb82d..a3facfd 100644 --- a/Apollon.EntityFramework/Migrations/20220828165744_initial1.Designer.cs +++ b/Apollon.EntityFramework/Migrations/20220828165744_initial1.Designer.cs @@ -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 { diff --git a/Apollon.EntityFramework/Migrations/20221107194347_competition.Designer.cs b/Apollon.EntityFramework/Migrations/20221107194347_competition.Designer.cs index ce630ff..9f650a7 100644 --- a/Apollon.EntityFramework/Migrations/20221107194347_competition.Designer.cs +++ b/Apollon.EntityFramework/Migrations/20221107194347_competition.Designer.cs @@ -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 { diff --git a/Apollon.EntityFramework/Migrations/20221110003817_logo.Designer.cs b/Apollon.EntityFramework/Migrations/20221110003817_logo.Designer.cs index ebf683b..acaa0e4 100644 --- a/Apollon.EntityFramework/Migrations/20221110003817_logo.Designer.cs +++ b/Apollon.EntityFramework/Migrations/20221110003817_logo.Designer.cs @@ -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 { diff --git a/Apollon.EntityFramework/Migrations/TournamentsDbContextModelSnapshot.cs b/Apollon.EntityFramework/Migrations/TournamentsDbContextModelSnapshot.cs index 30548d1..e4097ba 100644 --- a/Apollon.EntityFramework/Migrations/TournamentsDbContextModelSnapshot.cs +++ b/Apollon.EntityFramework/Migrations/TournamentsDbContextModelSnapshot.cs @@ -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) diff --git a/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs b/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs index e890537..f1397c7 100644 --- a/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs +++ b/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs @@ -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> Execute() { - using (TournamentsDbContext context = _contextFactory.Create()) + using (ApplicationDbContext context = _contextFactory.Create()) { IEnumerable tournamentsDtos = await context.Tournaments.ToListAsync(); diff --git a/Apollon.WPF/App.xaml.cs b/Apollon.WPF/App.xaml.cs index 691574c..d9f9be3 100644 --- a/Apollon.WPF/App.xaml.cs +++ b/Apollon.WPF/App.xaml.cs @@ -24,7 +24,7 @@ namespace Apollon.WPF { private readonly NavigationStore _navigationStore; private readonly ModalNavigationStore _modalNavigationStore; - private readonly TournamentsDbContextFactory _tournamentsDbContextFactory; + private readonly ApplicationDBContextFactory _tournamentsDbContextFactory; private readonly IGetAllTournamentsQuery _getAllTournamentQuery; private readonly ICreateTournamentCommand _createTournamentCommand; private readonly IUpdateTournamentCommand _updateTournamentCommand; @@ -38,7 +38,7 @@ namespace Apollon.WPF _navigationStore = new NavigationStore(); _modalNavigationStore = new ModalNavigationStore(); - _tournamentsDbContextFactory = new TournamentsDbContextFactory( + _tournamentsDbContextFactory = new ApplicationDBContextFactory( new DbContextOptionsBuilder().UseSqlServer(connectionString).Options); _getAllTournamentQuery = new GetAllTournamentsQuery(_tournamentsDbContextFactory); _createTournamentCommand = new CreateTournamentCommand(_tournamentsDbContextFactory); @@ -49,7 +49,7 @@ namespace Apollon.WPF } protected override void OnStartup(StartupEventArgs e) { - using(TournamentsDbContext context = _tournamentsDbContextFactory.Create()) + using(ApplicationDbContext context = _tournamentsDbContextFactory.Create()) { context.Database.Migrate(); } diff --git a/Apollon.WPF/ViewModels/EditTournamentViewModel.cs b/Apollon.WPF/ViewModels/EditTournamentViewModel.cs index cdcd058..6371b5d 100644 --- a/Apollon.WPF/ViewModels/EditTournamentViewModel.cs +++ b/Apollon.WPF/ViewModels/EditTournamentViewModel.cs @@ -24,6 +24,7 @@ namespace Apollon.WPF.ViewModels AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand) { + Logo = tournament.Logo, Organisation = tournament.Organisation, TournamentName = tournament.TournamentName, Competition = tournament.Competition,