diff --git a/Apollon.Domain/Commands/ICreateNameListCommand.cs b/Apollon.Domain/Commands/ICreateNameListCommand.cs new file mode 100644 index 0000000..ac782bc --- /dev/null +++ b/Apollon.Domain/Commands/ICreateNameListCommand.cs @@ -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); + } +} diff --git a/Apollon.Domain/Commands/IDeleteNameListCommand.cs b/Apollon.Domain/Commands/IDeleteNameListCommand.cs new file mode 100644 index 0000000..5abcc86 --- /dev/null +++ b/Apollon.Domain/Commands/IDeleteNameListCommand.cs @@ -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); + } +} diff --git a/Apollon.Domain/Commands/IUpdateNameListCommand.cs b/Apollon.Domain/Commands/IUpdateNameListCommand.cs new file mode 100644 index 0000000..680f191 --- /dev/null +++ b/Apollon.Domain/Commands/IUpdateNameListCommand.cs @@ -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); + } +} diff --git a/Apollon.Domain/Models/NameList.cs b/Apollon.Domain/Models/NameList.cs new file mode 100644 index 0000000..aaacbc3 --- /dev/null +++ b/Apollon.Domain/Models/NameList.cs @@ -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; } + } +} diff --git a/Apollon.Domain/Queries/IGetAllNamesQuery.cs b/Apollon.Domain/Queries/IGetAllNamesQuery.cs new file mode 100644 index 0000000..aa8c714 --- /dev/null +++ b/Apollon.Domain/Queries/IGetAllNamesQuery.cs @@ -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> Execute(); + } +} diff --git a/Apollon.EntityFramework/ApplicationDBContext.cs b/Apollon.EntityFramework/ApplicationDBContext.cs index 896edcc..e80427d 100644 --- a/Apollon.EntityFramework/ApplicationDBContext.cs +++ b/Apollon.EntityFramework/ApplicationDBContext.cs @@ -14,6 +14,7 @@ namespace Apollon.EntityFramework { } public DbSet Tournaments { get; set; } + public DbSet NameList { get; set; } public DbSet Competition { get; set; } } } diff --git a/Apollon.EntityFramework/Commands/CreateNameListCommand.cs b/Apollon.EntityFramework/Commands/CreateNameListCommand.cs new file mode 100644 index 0000000..26b1b37 --- /dev/null +++ b/Apollon.EntityFramework/Commands/CreateNameListCommand.cs @@ -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(); + } + } + } +} diff --git a/Apollon.EntityFramework/Commands/DeleteNameListCommand.cs b/Apollon.EntityFramework/Commands/DeleteNameListCommand.cs new file mode 100644 index 0000000..6fa81c6 --- /dev/null +++ b/Apollon.EntityFramework/Commands/DeleteNameListCommand.cs @@ -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(); + } + } + } +} diff --git a/Apollon.EntityFramework/Commands/UpdateNameListCommand.cs b/Apollon.EntityFramework/Commands/UpdateNameListCommand.cs new file mode 100644 index 0000000..182e077 --- /dev/null +++ b/Apollon.EntityFramework/Commands/UpdateNameListCommand.cs @@ -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(); + } + } + } +} diff --git a/Apollon.EntityFramework/DTOs/NameListDto.cs b/Apollon.EntityFramework/DTOs/NameListDto.cs new file mode 100644 index 0000000..986197e --- /dev/null +++ b/Apollon.EntityFramework/DTOs/NameListDto.cs @@ -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; } + } +} diff --git a/Apollon.EntityFramework/Queries/GetAllNamesQuery.cs b/Apollon.EntityFramework/Queries/GetAllNamesQuery.cs new file mode 100644 index 0000000..9b2e829 --- /dev/null +++ b/Apollon.EntityFramework/Queries/GetAllNamesQuery.cs @@ -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> Execute() + { + using (ApplicationDbContext context = _contextFactory.Create()) + { + IEnumerable 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)); + } + } + } +} diff --git a/Apollon.WPF/ViewModels/NameListViewModel.cs b/Apollon.WPF/ViewModels/NameListViewModel.cs index 0cace66..d71a39e 100644 --- a/Apollon.WPF/ViewModels/NameListViewModel.cs +++ b/Apollon.WPF/ViewModels/NameListViewModel.cs @@ -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)); + } + } + } } diff --git a/Apollon.WPF/Views/NameListView.xaml b/Apollon.WPF/Views/NameListView.xaml index 4db54a6..c8e25c3 100644 --- a/Apollon.WPF/Views/NameListView.xaml +++ b/Apollon.WPF/Views/NameListView.xaml @@ -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"> - - + mc:Ignorable="d"> + + + + + + + + + + + + +