Picture on first page and more functioning on RoundStartingView

This commit is contained in:
2025-09-16 23:21:22 +02:00
parent 4e2b71af9f
commit a955218c7a
21 changed files with 335 additions and 74 deletions

View File

@ -15,12 +15,12 @@ public class RoundStartingViewModel : ViewModelBase
}
public RoundStartingViewModel(
IRepository<GameRound> repo,
IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base()
{
_Repository = repo;
_roundsRepo = roundsRepo;
_pointsRepo = pointsRepo;
_sharingService = sharingService;
_combined = combined;
@ -30,9 +30,9 @@ public class RoundStartingViewModel : ViewModelBase
#endregion
private GameRound? _GameRoundObject = new();
private ObservableCollection<IEnumerable<GameRound>> _GameRoundList = new();
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
private readonly IRepository<GameRound>? _Repository;
private readonly IRepository<GameRound>? _roundsRepo;
private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined;
@ -76,7 +76,7 @@ public class RoundStartingViewModel : ViewModelBase
GameStatus = GamePointStatus.New,
GameRoundFinished = null
};
var gameRoundId = _Repository?.Save(GameRound).GetAwaiter().GetResult();
var gameRoundId = _roundsRepo?.Save(GameRound).GetAwaiter().GetResult();
if (gameRoundId != null && gameRoundId != -1)
{
GameRound.GameRoundId = gameRoundId.Value;
@ -122,7 +122,7 @@ public class RoundStartingViewModel : ViewModelBase
}
}
public ObservableCollection<IEnumerable<GameRound>> GameRoundList
public ObservableCollection<RoundBuilderGroup> GameRoundList
{
get { return _GameRoundList; }
set
@ -143,33 +143,36 @@ public class RoundStartingViewModel : ViewModelBase
}
#region Get Method
public ObservableCollection<GameRound> Get()
public ObservableCollection<RoundBuilderGroup> Get()
{
//if (_Repository != null)
if (_combined != null)
{
//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
.GroupBy(r => r.GameRoundId)
.Select(g => new RoundBuilderGroup
{
GameRoundId = g.Key,
GameRoundStartDate = g.First().GameRoundStartDate,
Status = g.First().Status,
Elements = g.Select(p => new RoundBuilderElement
{
ParticipantId = p.ParticipantId,
ParticipantName = p.ParticipantName,
GamePointId = p.GamePointId,
GameRoundRegNr = p.GameRoundRegNr,
GameRegPoints = p.GameRegPoints,
GameRoundId = p.GameRoundId,
GameRoundStartDate = p.GameRoundStartDate
}).ToList()
})
.ToList();
//foreach (var gameRound in gameRounds)
//{
// if (!_GameRoundList.Any(p => p.GameRoundId == gameRound.GameRoundId))
// {
// GameRoundList.Add(gameRound);
// }
//}
GameRoundList = new ObservableCollection<RoundBuilderGroup>(groupedRounds);
}
return GameRoundList;
}
@ -187,7 +190,7 @@ public class RoundStartingViewModel : ViewModelBase
{
try
{
GameRoundObject = _Repository?.Get(id).GetAwaiter().GetResult();
GameRoundObject = _roundsRepo?.Get(id).GetAwaiter().GetResult();
}
catch (Exception ex)
{
@ -198,11 +201,11 @@ public class RoundStartingViewModel : ViewModelBase
}
public virtual bool Save()
{
if (_Repository == null || GameRoundObject == null)
if (_roundsRepo == null || GameRoundObject == null)
{
return false;
}
var tmpTask = _Repository.Save(GameRoundObject);
var tmpTask = _roundsRepo.Save(GameRoundObject);
bool tmp = tmpTask.GetAwaiter().GetResult() != -1;
if (tmp)
{
@ -219,10 +222,20 @@ public class RoundStartingViewModel : ViewModelBase
{
_pointsRepo.DeleteById(element.GamePointId);
}
_Repository?.DeleteById(GameRoundObject?.GameRoundId ?? 0);
_roundsRepo?.DeleteById(GameRoundObject?.GameRoundId ?? 0);
RoundElements.Clear();
}
public void RoundSelected(RoundBuilderElement element)
{
Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}");
}
public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
{
Debug.WriteLine($"Du valde raden med Runda {roundBuilder.GameRoundId} och spelare: {roundBuilder.ParticipantName}");
}
#endregion
}