using Common.Library; using GreadyPoang.DataLayer.Database; using GreadyPoang.EntityLayer; using Microsoft.EntityFrameworkCore; namespace GreadyPoang.DataLayer; public class GamePointRepository : IRepository { private readonly DataContext _dataContext; public GamePointRepository(DataContext dataContext) { _dataContext = dataContext; } public async Task> Get() { return await _dataContext.GamePoints.ToListAsync(); } public async Task Get(int id) { return await _dataContext.GamePoints.FindAsync(id); } public async Task Save(GamePoint entity) { var res = false; if ((entity.GameHeatRegNr == 0) || (entity.GameRegPoints == 0)) { return res; // Validation failed } if (entity.GamePointId == 0) { _dataContext.GamePoints.Add(entity); await _dataContext.SaveChangesAsync(); res = true; } else { _dataContext.GamePoints.Update(entity); await _dataContext.SaveChangesAsync(); res = true; } return res; } public bool Delete(GamePoint entity) { var res = false; try { _dataContext.GamePoints.Remove(entity); _dataContext.SaveChanges(); res = true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error deleting participant: {ex.Message}"); res = false; } return res; } }