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,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View 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);
}
}

View 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);
}
}

View 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);
}
}

View File

@@ -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
{

View 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();
}
}

View 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>

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();
}
}
}
}

View 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();
}
}
}
}

View 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();
}
}
}
}

View 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; }
}
}

View 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));
}
}
}
}

View 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; }
}
}

View 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);
}
}
}

View File

@@ -12,4 +12,8 @@
<PackageReference Include="SimpleModal.WPF" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Apollon.Domain\Apollon.Domain.csproj" />
</ItemGroup>
</Project>

View File

@@ -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)

View File

@@ -1,4 +1,4 @@
using Apollon.WPF.Models;
using Apollon.Domain.Models;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;

View File

@@ -1,4 +1,4 @@
using Apollon.WPF.Models;
using Apollon.Domain.Models;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;

View File

@@ -1,4 +1,4 @@
using Apollon.WPF.Models;
using Apollon.Domain.Models;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;

View File

@@ -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; }
}
}

View File

@@ -1,4 +1,4 @@
using Apollon.WPF.Models;
using Apollon.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,4 +1,4 @@
using Apollon.WPF.Models;
using Apollon.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -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;

View File

@@ -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));

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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