using Common.Library; using Gready_Poang.DataLayer.Database; using Gready_Poang.EntityLayer; using Microsoft.EntityFrameworkCore; namespace Gready_Poang.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 = -1; if (entity.GameRoundId == 0) { _dataContext.GameRounds.Add(entity); await _dataContext.SaveChangesAsync(); res = entity.GameRoundId; } else { _dataContext.GameRounds.Update(entity); await _dataContext.SaveChangesAsync(); res = entity.GameRoundId; } return res; } public async Task DeleteById(int Id) { var ok = false; var delObject = await this.Get(Id); if (delObject != null) { try { ok = this.Delete(delObject); } catch (Exception ex) { throw new Exception("Unsuccessful remove of GameRound: " + ex.Message); } } return ok; } }