Efter flytt av statusfält och åter byygt

This commit is contained in:
2025-09-14 12:03:16 +02:00
parent b4898660f2
commit 4e2b71af9f
8 changed files with 336 additions and 45 deletions

View File

@ -1,4 +1,5 @@
using Common.Library;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using System.Collections.ObjectModel;
using System.Diagnostics;
@ -13,22 +14,28 @@ public class RoundStartingViewModel : ViewModelBase
}
public RoundStartingViewModel(IRepository<GameRound> repo, IRepository<GamePoint> pointsRepo, IMethodSharingService<Participant> sharingService) : base()
public RoundStartingViewModel(
IRepository<GameRound> repo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base()
{
_Repository = repo;
_pointsRepo = pointsRepo;
_sharingService = sharingService;
_combined = combined;
_roundElements = new ObservableCollection<RoundBuilderElement>();
}
#endregion
private GameRound? _GameRoundObject = new();
private ObservableCollection<GameRound> _GameRoundList = new();
private ObservableCollection<IEnumerable<GameRound>> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
private readonly IRepository<GameRound>? _Repository;
private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined;
private Participant _selectedItem;
private ObservableCollection<RoundBuilderElement> _roundElements;
@ -43,6 +50,7 @@ public class RoundStartingViewModel : ViewModelBase
}
}
public Participant SelectedItem
{
get => _selectedItem;
@ -65,6 +73,7 @@ public class RoundStartingViewModel : ViewModelBase
var GameRound = new GameRound
{
GameRoundStartDate = DateTime.Now,
GameStatus = GamePointStatus.New,
GameRoundFinished = null
};
var gameRoundId = _Repository?.Save(GameRound).GetAwaiter().GetResult();
@ -81,8 +90,7 @@ public class RoundStartingViewModel : ViewModelBase
GameRoundId = GameRoundObject?.GameRoundId ?? 0,
GameDate = DateTime.Now,
GameRoundRegNr = -1,
GameRegPoints = 0,
PointStatus = GamePointStatus.New
GameRegPoints = 0
};
var gamePointId = _pointsRepo.Save(GamePointStart).GetAwaiter().GetResult();
@ -93,7 +101,7 @@ public class RoundStartingViewModel : ViewModelBase
newElement.ParticipantName = item.LastNameFirstName;
newElement.GameRoundRegNr = GamePointStart.GameRoundRegNr;
newElement.GameRegPoints = GamePointStart.GameRegPoints;
newElement.Status = GamePointStart.PointStatus;
newElement.Status = GameRoundObject!.GameStatus;
newElement.GameRoundStartDate = GameRoundObject?.GameRoundStartDate ?? DateTime.Now;
newElement.GameRoundId = GamePointStart.GameRoundId;
newElement.GamePointId = GamePointStart.GamePointId;
@ -114,7 +122,7 @@ public class RoundStartingViewModel : ViewModelBase
}
}
public ObservableCollection<GameRound> GameRoundList
public ObservableCollection<IEnumerable<GameRound>> GameRoundList
{
get { return _GameRoundList; }
set
@ -137,19 +145,31 @@ public class RoundStartingViewModel : ViewModelBase
#region Get Method
public ObservableCollection<GameRound> Get()
{
if (_Repository != null)
//if (_Repository != null)
if (_combined != null)
{
var gameRoundsTask = _Repository.Get();
var gameRounds = gameRoundsTask is Task<IEnumerable<GameRound>> task
? task.GetAwaiter().GetResult()
: (IEnumerable<GameRound>)gameRoundsTask;
foreach (var gameRound in gameRounds)
{
if (!_GameRoundList.Any(p => p.GameRoundId == gameRound.GameRoundId))
{
GameRoundList.Add(gameRound);
}
}
//var gameRoundsTask = _Repository.Get();
//var gameRounds = gameRoundsTask is Task<IEnumerable<GameRound>> task
// ? task.GetAwaiter().GetResult()
// : (IEnumerable<GameRound>)gameRoundsTask;
var GameRoundSummary = _combined.roundBuilderElements();
var groupedRounds = GameRoundSummary
.GroupBy(r => r.GameRoundId)
.Select(g => g.ToList())
.ToList();
//OBS ! Här måste jag skapa en ny lista varje gång för att UI ska uppdateras korrekt
//foreach (var gameRound in gameRounds)
//{
// if (!_GameRoundList.Any(p => p.GameRoundId == gameRound.GameRoundId))
// {
// GameRoundList.Add(gameRound);
// }
//}
}
return GameRoundList;
}