Skapat möjlighet att spara in flera resultat per participant och round

This commit is contained in:
2025-09-19 17:21:58 +02:00
parent 0a56d8ffc8
commit 066503da74
5 changed files with 89 additions and 27 deletions

View File

@ -15,9 +15,18 @@ public class CombinedRepository : ICombinedRepository
public IEnumerable<RoundBuilderElement> roundBuilderElements() public IEnumerable<RoundBuilderElement> roundBuilderElements()
{ {
var result = (from gameRound in _context.GameRounds var latestGamePoints = _context.GamePoints
join gamePoint in _context.GamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId .AsEnumerable()
join participant in _context.Participants on gamePoint.ParticipantId equals participant.ParticipantId .GroupBy(gp => new { gp.GameRoundId, gp.ParticipantId })
.Select(g => g.OrderByDescending(gp => gp.GamePointId).First())
.ToList();
var gamerounds = _context.GameRounds.AsEnumerable();
var participants = _context.Participants.AsEnumerable();
var result = (from gameRound in gamerounds
join gamePoint in latestGamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId
join participant in participants on gamePoint.ParticipantId equals participant.ParticipantId
orderby gameRound.GameRoundStartDate descending, participant.LastName, participant.FirstName, gamePoint.GameRoundRegNr orderby gameRound.GameRoundStartDate descending, participant.LastName, participant.FirstName, gamePoint.GameRoundRegNr
select new RoundBuilderElement select new RoundBuilderElement
{ {
@ -33,4 +42,27 @@ public class CombinedRepository : ICombinedRepository
return result; return result;
} }
public IEnumerable<RoundBuilderElement> roundBuilderElementsTotal()
{
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
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

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

View File

@ -4,6 +4,13 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Style x:Key="ScoreCellStyle" TargetType="Border">
<Setter Property="Stroke" Value="Gray" />
<Setter Property="StrokeThickness" Value="1" />
<Setter Property="Padding" Value="5" />
<Setter Property="BackgroundColor" Value="LightGray" />
</Style>
<x:String x:Key="ApplicationTitle"> <x:String x:Key="ApplicationTitle">
Gready Poäng Gready Poäng
</x:String> </x:String>

View File

@ -98,9 +98,9 @@
<ScrollView Grid.Row="4"> <ScrollView Grid.Row="4">
<Grid <Grid
x:Name="ScoreGrid" x:Name="ScoreGrid"
ColumnSpacing="10" ColumnSpacing="5"
RowSpacing="10" RowSpacing="5"
Padding="10" Padding="3"
HorizontalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" /> VerticalOptions="FillAndExpand" />
</ScrollView> </ScrollView>

View File

@ -20,44 +20,66 @@ public partial class RoundRunningView : ContentPage
} }
public RoundRunningViewModelCommands ViewModel { get; set; } public RoundRunningViewModelCommands ViewModel { get; set; }
//public int GameRoundId { get; set; }
//--------------------------------------------------------------
private void BuildScoreGrid(IEnumerable<PlayerColumn> columns) private void BuildScoreGrid(IEnumerable<PlayerColumn> columns)
{ {
ScoreGrid.ColumnDefinitions.Clear(); ScoreGrid.ColumnDefinitions.Clear();
ScoreGrid.RowDefinitions.Clear();
ScoreGrid.Children.Clear(); ScoreGrid.Children.Clear();
int maxRows = columns.Max(c => c.Values.Count);
// Skapa rader
for (int row = 0; row < maxRows + 1; row++) // +1 f<>r rubrikraden
{
ScoreGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
}
int colIndex = 0; int colIndex = 0;
foreach (var column in columns) foreach (var column in columns)
{ {
ScoreGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); ScoreGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var stack = new VerticalStackLayout(); var headerCell = CreateCell(column.PlayerName, isHeader: true);
ScoreGrid.Children.Add(headerCell);
Grid.SetRow(headerCell, 0);
Grid.SetColumn(headerCell, colIndex);
stack.Children.Add(new Label // V<>rdeceller
for (int rowIndex = 0; rowIndex < column.Values.Count; rowIndex++)
{ {
Text = column.PlayerName, var value = column.Values[rowIndex];
FontAttributes = FontAttributes.Bold, var cell = CreateCell(value);
HorizontalOptions = LayoutOptions.Center ScoreGrid.Children.Add(cell);
}); Grid.SetRow(cell, rowIndex + 1); // +1 f<>r att hoppa <20>ver rubrikraden
Grid.SetColumn(cell, colIndex);
foreach (var value in column.Values)
{
stack.Children.Add(new Label
{
Text = value,
HorizontalOptions = LayoutOptions.Center
});
} }
ScoreGrid.Children.Add(stack); colIndex++;
Grid.SetColumn(stack, colIndex++);
} }
} }
private View CreateCell(string text, bool isHeader = false)
{
return new Border
{
Stroke = Colors.Gray,
StrokeThickness = 1,
BackgroundColor = isHeader ? Colors.DarkGray : Colors.Yellow,
Margin = 1,
Padding = 2,
Content = new Label
{
Text = text,
FontAttributes = isHeader ? FontAttributes.Bold : FontAttributes.None,
TextColor = isHeader ? Colors.White : Colors.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
}
};
}
} }