Lagt till nya entiteter för Gameround och GamePoints

Migrerat och byggt ut databasen
This commit is contained in:
2025-09-03 23:38:57 +02:00
parent ddb6719587
commit 4caeb21b0d
29 changed files with 1288 additions and 56 deletions

View File

@ -0,0 +1,61 @@
using Common.Library;
using GreadyPoang.DataLayer.Database;
using GreadyPoang.EntityLayer;
using Microsoft.EntityFrameworkCore;
namespace GreadyPoang.DataLayer;
public class GameRoundRepository : IRepository<GameRound>
{
private readonly DataContext _dataContext;
public GameRoundRepository(DataContext dataContext)
{
_dataContext = dataContext;
}
public bool Delete(GameRound entity)
{
var res = false;
try
{
_dataContext.GameRounds.Remove(entity);
_dataContext.SaveChanges();
res = true;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error deleting GameRound: {ex.Message}");
res = false;
}
return res;
}
public async Task<IEnumerable<GameRound>> Get()
{
return await _dataContext.GameRounds.ToListAsync();
}
public async Task<GameRound?> Get(int id)
{
return await _dataContext.GameRounds.FindAsync(id);
}
public async Task<bool> Save(GameRound entity)
{
var res = false;
if (entity.GameRoundId == 0)
{
_dataContext.GameRounds.Add(entity);
await _dataContext.SaveChangesAsync();
res = true;
}
else
{
_dataContext.GameRounds.Update(entity);
await _dataContext.SaveChangesAsync();
res = true;
}
return res;
}
}