This commit is contained in:
Natlinux
2022-11-13 18:10:38 +01:00
parent d2c021c5b7
commit ee8c687f5c
13 changed files with 380 additions and 8 deletions

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 ICreateNameListCommand
{
Task Execute(NameList nameList);
}
}

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 IDeleteNameListCommand
{
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 IUpdateNameListCommand
{
Task Exexute(NameList nameList);
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.Domain.Models
{
public class NameList
{
public NameList(Guid id,string firstName, string lastName, int passNumber, string society, int societyNumber, string birthday, string country)
{
Id = id;
FirstName = firstName;
LastName = lastName;
PassNumber = passNumber;
Society = society;
SocietyNumber = societyNumber;
Birthday = birthday;
Country = country;
}
public Guid Id { get; }
public string FirstName { get; }
public string LastName { get; }
public int PassNumber { get; }
public string Society { get; }
public int SocietyNumber { get; }
public string Birthday { get; }
public string Country { get; }
}
}

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 IGetAllNamesQuery
{
Task<IEnumerable<NameList>> Execute();
}
}

View File

@@ -14,6 +14,7 @@ namespace Apollon.EntityFramework
{
}
public DbSet<TournamentDto> Tournaments { get; set; }
public DbSet<NameListDto> NameList { get; set; }
public DbSet<CompetitionDto> Competition { get; set; }
}
}

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 CreateNameListCommand : ICreateNameListCommand
{
private readonly ApplicationDBContextFactory _contextFactory;
public CreateNameListCommand(ApplicationDBContextFactory dbContextFactory)
{
_contextFactory = dbContextFactory;
}
public async Task Execute(NameList nameList)
{
using (ApplicationDbContext context = _contextFactory.Create())
{
NameListDto nameListDto = new NameListDto()
{
Id = nameList.Id,
FirstName = nameList.FirstName,
LastName = nameList.Country,
PassNumber = nameList.PassNumber,
Society = nameList.Society,
SocietyNumber = nameList.SocietyNumber,
Birthday = nameList.Birthday,
Country = nameList.Country,
};
context.NameList.Add(nameListDto);
await context.SaveChangesAsync();
}
}
}
}

View File

@@ -0,0 +1,34 @@
using Apollon.Domain.Commands;
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 DeleteNameListCommand : IDeleteNameListCommand
{
private readonly ApplicationDBContextFactory _contextFactory;
public DeleteNameListCommand(ApplicationDBContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
public async Task Execute(Guid id)
{
using (ApplicationDbContext context = _contextFactory.Create())
{
NameListDto nameListDto = new NameListDto()
{
Id = id,
};
context.NameList.Remove(nameListDto);
await context.SaveChangesAsync();
}
}
}
}

View File

@@ -0,0 +1,41 @@
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 UpdateNameListCommand : IUpdateNameListCommand
{
private readonly ApplicationDBContextFactory _ContextFactory;
public UpdateNameListCommand(ApplicationDBContextFactory contextFactory)
{
_ContextFactory = contextFactory;
}
public async Task Exexute(NameList nameList)
{
using (ApplicationDbContext context = _ContextFactory.Create())
{
NameListDto nameListDto = new NameListDto()
{
Id = nameList.Id,
FirstName = nameList.FirstName,
LastName = nameList.LastName,
PassNumber = nameList.PassNumber,
Society = nameList.Society,
SocietyNumber = nameList.SocietyNumber,
Birthday = nameList.Birthday,
Country = nameList.Country,
};
context.NameList.Update(nameListDto);
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 NameListDto
{
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int PassNumber { get; set; }
public string Society { get; set; }
public int SocietyNumber { get; set; }
public string Birthday { get; set; }
public string Country { 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 GetAllNamesQuery : IGetAllNamesQuery
{
private readonly ApplicationDBContextFactory _contextFactory;
public GetAllNamesQuery(ApplicationDBContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
public async Task<IEnumerable<NameList>> Execute()
{
using (ApplicationDbContext context = _contextFactory.Create())
{
IEnumerable<NameListDto> nameListDtos = await context.NameList.ToListAsync();
return nameListDtos.Select(y => new NameList(
y.Id,
y.FirstName,
y.LastName,
y.PassNumber,
y.Society,
y.SocietyNumber,
y.Birthday,
y.Country));
}
}
}
}

View File

@@ -8,5 +8,102 @@ namespace Apollon.WPF.ViewModels
{
public class NameListViewModel : ViewModelBase
{
}
private string _firstName;
public string FirstName
{
get
{
return _firstName;
}
set
{
_firstName = value;
OnPropertyChanged(nameof(FirstName));
}
}
private string _lastName;
public string LastName
{
get
{
return _lastName;
}
set
{
_lastName = value;
OnPropertyChanged(nameof(LastName));
}
}
private int _passNumber;
public int PassNumber
{
get
{
return _passNumber;
}
set
{
_passNumber = value;
OnPropertyChanged(nameof(PassNumber));
}
}
private string _society;
public string Society
{
get
{
return _society;
}
set
{
_society = value;
OnPropertyChanged(nameof(Society));
}
}
private int _societyNumber;
public int SocietyNumber
{
get
{
return _societyNumber;
}
set
{
_societyNumber = value;
OnPropertyChanged(nameof(SocietyNumber));
}
}
private string _birthday;
public string Birthday
{
get
{
return _birthday;
}
set
{
_birthday = value;
OnPropertyChanged(nameof(Birthday));
}
}
private string _country;
public string Country
{
get
{
return _country;
}
set
{
_country = value;
OnPropertyChanged(nameof(Country));
}
}
}
}

View File

@@ -4,12 +4,22 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Apollon.WPF.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Text="Stammdaten"
FontSize="30"
TextAlignment="Center"
VerticalAlignment="Center"/>
mc:Ignorable="d">
<Grid Margin="35">
<DataGrid FontSize="14"
HorizontalAlignment="Center"
CanUserAddRows="True"
AutoGenerateColumns="True">
<DataGrid.Columns>
<DataGridTextColumn Width="120" Header="Vorname" Binding="{Binding FirstName}"/>
<DataGridTextColumn Width="120" Header="Nachname" Binding="{Binding LastName}" />
<DataGridTextColumn Width="120" Header="Passnummer" Binding="{Binding PassNumber}"/>
<DataGridTextColumn Width="150" Header="Verein" Binding="{Binding Society}" />
<DataGridTextColumn Width="120" Header="Vereinsnummer" Binding="{Binding SocietyNumber}"/>
<DataGridTextColumn Width="100" Header="Geburtsdatum" Binding="{Binding Birthday}" />
<DataGridTextColumn Header="Bundesland" Binding="{Binding Country}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>