diff --git a/GreadyPoang.EntityLayer/HelperEntities/PlayerColumn.cs b/GreadyPoang.EntityLayer/HelperEntities/PlayerColumn.cs index 0365a40..41cae42 100644 --- a/GreadyPoang.EntityLayer/HelperEntities/PlayerColumn.cs +++ b/GreadyPoang.EntityLayer/HelperEntities/PlayerColumn.cs @@ -9,6 +9,9 @@ public class PlayerColumn : EntityBase _playerName = string.Empty; _values = new List(); } + + + private int _playerId; private string _playerName; private List _values; public string PlayerName @@ -29,4 +32,24 @@ public class PlayerColumn : EntityBase RaisePropertyChanged(nameof(Values)); } } + + public int PlayerId + { + get { return _playerId; } + set + { + _playerId = value; + RaisePropertyChanged(nameof(PlayerId)); + } + } + + private int _playerPoints; + + public int PlayerPoints + { + get { return _playerPoints; } + set { _playerPoints = value; } + } + + } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs index 201289a..6a07606 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs @@ -10,6 +10,8 @@ namespace GreadyPoang.ViewModelLayer; public class RoundRunningViewModel : ViewModelBase { + public event EventHandler RebuildRequested; + public RoundRunningViewModel() : base() { } @@ -43,6 +45,12 @@ public class RoundRunningViewModel : ViewModelBase private ObservableCollection _ParticipantList = new(); private Collection _playerColumns; + public void TriggerRebuild() + { + // Trigga eventet + RebuildRequested?.Invoke(this, EventArgs.Empty); + } + public ObservableCollection RoundElements { get { return _roundElements; } @@ -102,6 +110,7 @@ public class RoundRunningViewModel : ViewModelBase var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId); FillupResultTable(localElements); + } return RoundElements; } @@ -128,15 +137,21 @@ public class RoundRunningViewModel : ViewModelBase { RoundElements.Add(item); } + // Uppdatera spelaren som skall spela nästa var nxt = nextPlayerElement(); + BuilderObject.GameRegPoints = 0; BuilderObject.ParticipantName = RoundElements[nxt].ParticipantName; BuilderObject.ParticipantId = RoundElements[nxt].ParticipantId; BuilderObject.GameRoundId = RoundElements[0].GameRoundId; var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId); FillupResultTable(localElements); - + foreach (var col in _playerColumns) + { + RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints; + } + TriggerRebuild(); } private int nextPlayerElement() @@ -166,23 +181,28 @@ public class RoundRunningViewModel : ViewModelBase if (elements.Any(g => g.GameRegPoints > 0)) { - var oldPart = -1; PlayerColumn player = new PlayerColumn(); foreach (var element in elements) { - if (element.ParticipantId != oldPart) + player = _playerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId); + + if (player == null) { player = new PlayerColumn { - PlayerName = element.ParticipantName + PlayerName = element.ParticipantName, + PlayerId = element.ParticipantId, + PlayerPoints = 0 }; - } - if (element.GameRegPoints > 0) - player.Values.Add(element.GameRegPoints.ToString()); - oldPart = element.ParticipantId; + if (element.GameRegPoints > 0) + { + player.Values.Add(element.GameRegPoints.ToString()); + player.PlayerPoints += element.GameRegPoints; + } + //oldPart = element.ParticipantId; if (!_playerColumns.Contains(player)) { diff --git a/GreadyPoang/Views/RoundRunningView.xaml.cs b/GreadyPoang/Views/RoundRunningView.xaml.cs index 1b754b0..5347af4 100644 --- a/GreadyPoang/Views/RoundRunningView.xaml.cs +++ b/GreadyPoang/Views/RoundRunningView.xaml.cs @@ -17,8 +17,18 @@ public partial class RoundRunningView : ContentPage BindingContext = ViewModel; ViewModel.Get(); BuildScoreGrid(ViewModel.PlayerColumns); // <-- här bygger du layouten + ViewModel.RebuildRequested += ViewModel_RebuildRequested; + } + + private void ViewModel_RebuildRequested(object? sender, EventArgs e) + { + BuildScoreGrid(ViewModel.PlayerColumns); // <-- här bygger du layouten + } + + //protected override + public RoundRunningViewModelCommands ViewModel { get; set; }