using Common.Library; using GreadyPoang.DataLayer.Database; using GreadyPoang.EntityLayer; using Microsoft.EntityFrameworkCore; namespace GreadyPoang.DataLayer; public class GameRoundRepository : IRepository { 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> Get() { return await _dataContext.GameRounds.ToListAsync(); } public async Task Get(int id) { return await _dataContext.GameRounds.FindAsync(id); } public async Task 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; } }