Samlar ihop och visar poäng från databasen

This commit is contained in:
2025-09-20 09:57:47 +02:00
parent 066503da74
commit 1bf42ef7e6
6 changed files with 109 additions and 16 deletions

View File

@ -1,5 +1,6 @@
using GreadyPoang.DataLayer.Database;
using GreadyPoang.EntityLayer;
using Microsoft.EntityFrameworkCore;
namespace GreadyPoang.DataLayer;
@ -43,6 +44,34 @@ public class CombinedRepository : ICombinedRepository
}
public IEnumerable<RoundBuilderElement> roundBuilderElementsDb()
{
var result = _context.RoundBuilderElements
.FromSqlRaw(@"
SELECT
gp.GamePointId,
gp.GameRoundId,
gp.GameRoundRegNr,
gp.GameRegPoints,
gr.GameRoundStartDate,
gr.GameStatus AS Status,
p.ParticipantId,
(p.LastName || ' ' || p.FirstName) AS ParticipantName
FROM GamePoints gp
INNER JOIN (
SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId
FROM GamePoints
GROUP BY ParticipantId, GameRoundId
) latest ON gp.GamePointId = latest.MaxGamePointId
INNER JOIN GameRounds gr ON gp.GameRoundId = gr.GameRoundId
INNER JOIN Participants p ON gp.ParticipantId = p.ParticipantId
ORDER BY gr.GameRoundStartDate DESC, p.LastName, p.FirstName, gp.GameRoundRegNr
")
.ToList();
return result;
}
public IEnumerable<RoundBuilderElement> roundBuilderElementsTotal()
{
@ -65,4 +94,28 @@ public class CombinedRepository : ICombinedRepository
return result;
}
public IEnumerable<RoundBuilderElement> roundBuilderElementsTotalById(int roundId)
{
var result = (from gameRound in _context.GameRounds
join gamePoint in _context.GamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId
join participant in _context.Participants on gamePoint.ParticipantId equals participant.ParticipantId
where gameRound.GameRoundId == roundId
orderby gameRound.GameRoundStartDate descending, participant.LastName, participant.FirstName, gamePoint.GameRoundRegNr
select new RoundBuilderElement
{
ParticipantId = participant.ParticipantId,
ParticipantName = participant.LastNameFirstName,
GamePointId = gamePoint.GamePointId,
GameRoundRegNr = gamePoint.GameRoundRegNr,
GameRegPoints = gamePoint.GameRegPoints,
GameRoundId = gameRound.GameRoundId,
GameRoundStartDate = gameRound.GameRoundStartDate,
Status = gameRound.GameStatus
}).ToList();
return result;
}
}

View File

@ -14,6 +14,8 @@ public class DataContext : DbContext
public DbSet<GamePoint> GamePoints { get; set; }
public DbSet<GameRound> GameRounds { get; set; }
public DbSet<RoundBuilderElement> RoundBuilderElements { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
@ -33,7 +35,7 @@ public class DataContext : DbContext
new GamePoint { GamePointId = 3, ParticipantId = 3, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 12, 15), GameRoundRegNr = 2, GameRegPoints = 1000 },
new GamePoint { GamePointId = 4, ParticipantId = 3, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 20, 15), GameRoundRegNr = 4, GameRegPoints = 400 }
);
modelBuilder.Entity<RoundBuilderElement>().HasNoKey();
}
}

View File

@ -6,5 +6,7 @@ namespace GreadyPoang.DataLayer;
public interface ICombinedRepository
{
IEnumerable<RoundBuilderElement> roundBuilderElements();
IEnumerable<RoundBuilderElement> roundBuilderElementsDb();
IEnumerable<RoundBuilderElement> roundBuilderElementsTotal();
IEnumerable<RoundBuilderElement> roundBuilderElementsTotalById(int roundId);
}