diff --git a/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs index d4c0263..e1c285b 100644 --- a/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs +++ b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs @@ -15,9 +15,18 @@ public class CombinedRepository : ICombinedRepository public IEnumerable roundBuilderElements() { - 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 + var latestGamePoints = _context.GamePoints + .AsEnumerable() + .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 select new RoundBuilderElement { @@ -33,4 +42,27 @@ public class CombinedRepository : ICombinedRepository return result; } + + public IEnumerable 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; + } + } diff --git a/GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs b/GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs index 3595681..208f82d 100644 --- a/GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs +++ b/GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs @@ -6,4 +6,5 @@ namespace GreadyPoang.DataLayer; public interface ICombinedRepository { IEnumerable roundBuilderElements(); + IEnumerable roundBuilderElementsTotal(); } \ No newline at end of file diff --git a/GreadyPoang/Resources/Styles/AppStyles.xaml b/GreadyPoang/Resources/Styles/AppStyles.xaml index ed314da..c163465 100644 --- a/GreadyPoang/Resources/Styles/AppStyles.xaml +++ b/GreadyPoang/Resources/Styles/AppStyles.xaml @@ -3,7 +3,14 @@ - + + + Gready Poäng diff --git a/GreadyPoang/Views/RoundRunningView.xaml b/GreadyPoang/Views/RoundRunningView.xaml index c8154bd..b8e2ba0 100644 --- a/GreadyPoang/Views/RoundRunningView.xaml +++ b/GreadyPoang/Views/RoundRunningView.xaml @@ -98,9 +98,9 @@ diff --git a/GreadyPoang/Views/RoundRunningView.xaml.cs b/GreadyPoang/Views/RoundRunningView.xaml.cs index 9a6cfd9..1b754b0 100644 --- a/GreadyPoang/Views/RoundRunningView.xaml.cs +++ b/GreadyPoang/Views/RoundRunningView.xaml.cs @@ -20,44 +20,66 @@ public partial class RoundRunningView : ContentPage } public RoundRunningViewModelCommands ViewModel { get; set; } - //public int GameRoundId { get; set; } - - //-------------------------------------------------------------- - private void BuildScoreGrid(IEnumerable columns) { ScoreGrid.ColumnDefinitions.Clear(); + ScoreGrid.RowDefinitions.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; foreach (var column in columns) { 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, - FontAttributes = FontAttributes.Bold, - HorizontalOptions = LayoutOptions.Center - }); - - foreach (var value in column.Values) - { - stack.Children.Add(new Label - { - Text = value, - HorizontalOptions = LayoutOptions.Center - }); + var value = column.Values[rowIndex]; + var cell = CreateCell(value); + ScoreGrid.Children.Add(cell); + Grid.SetRow(cell, rowIndex + 1); // +1 för att hoppa över rubrikraden + Grid.SetColumn(cell, colIndex); } - ScoreGrid.Children.Add(stack); - Grid.SetColumn(stack, colIndex++); + 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 + } + }; + } + }