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

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