Namelist
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
42
Apollon.EntityFramework/Commands/CreateNameListCommand.cs
Normal file
42
Apollon.EntityFramework/Commands/CreateNameListCommand.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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Apollon.EntityFramework/Commands/DeleteNameListCommand.cs
Normal file
34
Apollon.EntityFramework/Commands/DeleteNameListCommand.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Apollon.EntityFramework/Commands/UpdateNameListCommand.cs
Normal file
41
Apollon.EntityFramework/Commands/UpdateNameListCommand.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Apollon.EntityFramework/DTOs/NameListDto.cs
Normal file
20
Apollon.EntityFramework/DTOs/NameListDto.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 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; }
|
||||
}
|
||||
}
|
||||
40
Apollon.EntityFramework/Queries/GetAllNamesQuery.cs
Normal file
40
Apollon.EntityFramework/Queries/GetAllNamesQuery.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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user