Refactored AgeGroup namespace and services, added RegistrationKey functionality.

This commit is contained in:
2026-01-25 21:30:05 +01:00
parent 91dd8d1603
commit ce26a30693
12 changed files with 173 additions and 37 deletions

View File

@@ -0,0 +1,68 @@
using API.Database;
using API.Models.Internal.Altersgruppen;
using Microsoft.EntityFrameworkCore;
namespace API.Repository.AgeGroupRepo
{
public class AgeGroupService : IAgeGroupService
{
private ApplicationDbContext _context;
public AgeGroupService(ApplicationDbContext context)
{
_context = context;
}
public async Task<AltersGruppe> CreateAsync(AltersGruppe altersGruppe)
{
await _context.Altersgruppen.AddAsync(altersGruppe);
await _context.SaveChangesAsync();
return altersGruppe;
}
public async Task<AltersGruppe?> DeleteAsync(string id)
{
var group = await _context.Altersgruppen.FirstOrDefaultAsync(x => x.Id == id);
if (group == null)
{
return null;
}
_context.Altersgruppen.Remove(group);
_context.SaveChanges();
return group;
}
public async Task<List<AltersGruppe>> GetAllAsync()
{
var allGroups = await _context.Altersgruppen.ToListAsync();
return allGroups;
}
public async Task<AltersGruppe?> GetAsync(string id)
{
return await _context.Altersgruppen.FindAsync(id);
}
public async Task<AltersGruppe?> UpdateAsync(string id, AltersGruppe altersGruppe)
{
var existingGroup = await _context.Altersgruppen.FirstOrDefaultAsync(x => x.Id == id);
if (existingGroup == null)
{
return null;
}
existingGroup.Name = altersGruppe.Name;
existingGroup.StartingAge = altersGruppe.StartingAge;
existingGroup.EndingAge = altersGruppe.EndingAge;
await _context.SaveChangesAsync();
return existingGroup;
}
}
}