ready for database
This commit is contained in:
9
Apollon.Domain/Apollon.Domain.csproj
Normal file
9
Apollon.Domain/Apollon.Domain.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
14
Apollon.Domain/Commands/ICreateTournamentCommand.cs
Normal file
14
Apollon.Domain/Commands/ICreateTournamentCommand.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Apollon.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.Domain.Commands
|
||||
{
|
||||
public interface ICreateTournamentCommand
|
||||
{
|
||||
Task Execute(Tournament tournament);
|
||||
}
|
||||
}
|
||||
13
Apollon.Domain/Commands/IDeleteTournamentCommand .cs
Normal file
13
Apollon.Domain/Commands/IDeleteTournamentCommand .cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.Domain.Commands
|
||||
{
|
||||
public interface IDeleteTournamentCommand
|
||||
{
|
||||
Task Execute (Guid id);
|
||||
}
|
||||
}
|
||||
14
Apollon.Domain/Commands/IUpdateTournamentCommand .cs
Normal file
14
Apollon.Domain/Commands/IUpdateTournamentCommand .cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Apollon.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.Domain.Commands
|
||||
{
|
||||
public interface IUpdateTournamentCommand
|
||||
{
|
||||
Task Execute(Tournament tournament);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.WPF.Models
|
||||
namespace Apollon.Domain.Models
|
||||
{
|
||||
public class Tournament
|
||||
{
|
||||
14
Apollon.Domain/Queries/IGetAllTournamentsQuery.cs
Normal file
14
Apollon.Domain/Queries/IGetAllTournamentsQuery.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Apollon.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.Domain.Queries
|
||||
{
|
||||
public interface IGetAllTournamentsQuery
|
||||
{
|
||||
Task<IEnumerable<Tournament>> Execute();
|
||||
}
|
||||
}
|
||||
18
Apollon.EntityFramework/Apollon.EntityFramework.csproj
Normal file
18
Apollon.EntityFramework/Apollon.EntityFramework.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Apollon.Domain\Apollon.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
44
Apollon.EntityFramework/Commands/CreateTournamentCommand.cs
Normal file
44
Apollon.EntityFramework/Commands/CreateTournamentCommand.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs
Normal file
35
Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Apollon.Domain.Commands;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.EntityFramework.DTOs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.EntityFramework.Commands
|
||||
{
|
||||
public class DeleteTournamentCommand : IDeleteTournamentCommand
|
||||
{
|
||||
private readonly TournamentsDBContextFactory _contextFactory;
|
||||
|
||||
public DeleteTournamentCommand(TournamentsDBContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task Execute(Guid id)
|
||||
{
|
||||
using (TournamentsDBContext context = _contextFactory.Create())
|
||||
{
|
||||
TournamentDto tournamentDto = new TournamentDto()
|
||||
{
|
||||
Id = id,
|
||||
};
|
||||
|
||||
context.Tournaments.Remove(tournamentDto);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs
Normal file
42
Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Apollon.Domain.Commands;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.EntityFramework.DTOs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.EntityFramework.Commands
|
||||
{
|
||||
public class UpdateTournamentCommand : IUpdateTournamentCommand
|
||||
{
|
||||
private readonly TournamentsDBContextFactory _contextFactory;
|
||||
|
||||
public UpdateTournamentCommand(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.Update(tournamentDto);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Apollon.EntityFramework/DTOs/TournamentDto.cs
Normal file
20
Apollon.EntityFramework/DTOs/TournamentDto.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.EntityFramework.DTOs
|
||||
{
|
||||
public class TournamentDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Organisation { get; set; }
|
||||
public string TournamentName { get; set; }
|
||||
public string Competition { get; set; }
|
||||
public DateTime StartDate { get; set; }
|
||||
public DateTime EndDate { get; set; }
|
||||
public string Location { get; set; }
|
||||
public int Rounds { get; set; }
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Apollon.EntityFramework/TournamentsDBContext.cs
Normal file
19
Apollon.EntityFramework/TournamentsDBContext.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
{
|
||||
public class TournamentsDBContext : DbContext
|
||||
{
|
||||
public TournamentsDBContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<TournamentDto> Tournaments { get; set; }
|
||||
}
|
||||
}
|
||||
24
Apollon.EntityFramework/TournamentsDBContextFactory.cs
Normal file
24
Apollon.EntityFramework/TournamentsDBContextFactory.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.EntityFramework
|
||||
{
|
||||
public class TournamentsDBContextFactory
|
||||
{
|
||||
private readonly DbContextOptions _options;
|
||||
|
||||
public TournamentsDBContextFactory(DbContextOptions options)
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public TournamentsDBContext Create()
|
||||
{
|
||||
return new TournamentsDBContext(_options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,8 @@
|
||||
<PackageReference Include="SimpleModal.WPF" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Apollon.Domain\Apollon.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Commands;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.Domain.Queries;
|
||||
using Apollon.EntityFramework;
|
||||
using Apollon.EntityFramework.Commands;
|
||||
using Apollon.EntityFramework.Queries;
|
||||
using Apollon.WPF.Stores;
|
||||
using Apollon.WPF.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
@@ -17,14 +23,27 @@ namespace Apollon.WPF
|
||||
public partial class App : Application
|
||||
{
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
private readonly TournamentsDBContextFactory _tournamentsDBContextFactory;
|
||||
private readonly IGetAllTournamentsQuery _getAllTournamentQuery;
|
||||
private readonly ICreateTournamentCommand _createTournamentCommand;
|
||||
private readonly IUpdateTournamentCommand _updateTournamentCommand;
|
||||
private readonly IDeleteTournamentCommand _deleteTournamentCommand;
|
||||
private readonly TournamentsStore _tournamentStore;
|
||||
private readonly SelectedTournamentsStore _selectedTournamentStore;
|
||||
|
||||
|
||||
public App()
|
||||
{
|
||||
string connectionString = "Server=NATHALIE-PC\NATLINUXDB;Database=OfficeOrganizer;Trusted_Connection=True;MultipleActiveResultSets=true\";
|
||||
|
||||
_modalNavigationStore = new ModalNavigationStore();
|
||||
_tournamentStore = new TournamentsStore();
|
||||
_tournamentsDBContextFactory = new TournamentsDBContextFactory(
|
||||
new DbContextOptionsBuilder().UseSqlServer(connectionString).Options);
|
||||
_getAllTournamentQuery = new GetAllTournamentsQuery();
|
||||
_createTournamentCommand = new CreateTournamentCommand();
|
||||
_updateTournamentCommand = new UpdateTournamentCommand();
|
||||
_deleteTournamentCommand = new DeleteTournamentCommand();
|
||||
_tournamentStore = new TournamentsStore(_getAllTournamentQuery, _createTournamentCommand, _updateTournamentCommand, _deleteTournamentCommand);
|
||||
_selectedTournamentStore = new SelectedTournamentsStore(_tournamentStore);
|
||||
}
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using Apollon.WPF.ViewModels;
|
||||
using System;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using Apollon.WPF.ViewModels;
|
||||
using System;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using Apollon.WPF.ViewModels;
|
||||
using System;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Apollon.WPF.Models
|
||||
{
|
||||
public class Competition
|
||||
{
|
||||
public Competition(string competitionName, byte competitionImage)
|
||||
{
|
||||
CompetitionName = competitionName;
|
||||
CompetitionImage = competitionImage;
|
||||
}
|
||||
|
||||
public string CompetitionName { get; set; }
|
||||
|
||||
public byte CompetitionImage { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Apollon.WPF.Commands;
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -40,7 +40,7 @@ namespace Apollon.WPF.ViewModels
|
||||
|
||||
private void SelectedTournamentStore_SelectedTournamentChanged()
|
||||
{
|
||||
//OnPropertyChanged(nameof(HasSelectedTournament));
|
||||
OnPropertyChanged(nameof(HasSelectedTournament));
|
||||
OnPropertyChanged(nameof(Organisation));
|
||||
OnPropertyChanged(nameof(TournamentName));
|
||||
OnPropertyChanged(nameof(Competition));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Apollon.WPF.Commands;
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Apollon.WPF.Commands;
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Apollon.WPF.Commands;
|
||||
using Apollon.WPF.Models;
|
||||
using Apollon.Domain.Models;
|
||||
using Apollon.WPF.Stores;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
14
Apollon.sln
14
Apollon.sln
@@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32630.192
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apollon.WPF", "Apollon.WPF\Apollon.WPF.csproj", "{4153202B-6527-4AC9-97B2-B75E1C836141}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apollon.WPF", "Apollon.WPF\Apollon.WPF.csproj", "{4153202B-6527-4AC9-97B2-B75E1C836141}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apollon.EntityFramework", "Apollon.EntityFramework\Apollon.EntityFramework.csproj", "{10CAC7FF-F7F7-4AC8-BFD3-7618A58A4F7F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apollon.Domain", "Apollon.Domain\Apollon.Domain.csproj", "{61741D2E-52A2-4FEA-B855-652F60820DFC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -15,6 +19,14 @@ Global
|
||||
{4153202B-6527-4AC9-97B2-B75E1C836141}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4153202B-6527-4AC9-97B2-B75E1C836141}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4153202B-6527-4AC9-97B2-B75E1C836141}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{10CAC7FF-F7F7-4AC8-BFD3-7618A58A4F7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{10CAC7FF-F7F7-4AC8-BFD3-7618A58A4F7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{10CAC7FF-F7F7-4AC8-BFD3-7618A58A4F7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{10CAC7FF-F7F7-4AC8-BFD3-7618A58A4F7F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{61741D2E-52A2-4FEA-B855-652F60820DFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{61741D2E-52A2-4FEA-B855-652F60820DFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{61741D2E-52A2-4FEA-B855-652F60820DFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{61741D2E-52A2-4FEA-B855-652F60820DFC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user