Lagt till nya entiteter för Gameround och GamePoints
Migrerat och byggt ut databasen
This commit is contained in:
61
GreadyPoang.DataLayer/DataClasses/GameRoundRepository.cs
Normal file
61
GreadyPoang.DataLayer/DataClasses/GameRoundRepository.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user