Till slut fick jag personvalet att fungera

This commit is contained in:
2025-09-06 11:59:04 +02:00
parent d3c9dcb208
commit a2d47debfe
11 changed files with 223 additions and 46 deletions

View File

@ -13,9 +13,10 @@ public class RoundStartingViewModel : ViewModelBase
}
public RoundStartingViewModel(IRepository<GameRound> repo, IMethodSharingService<Participant> sharingService) : base()
public RoundStartingViewModel(IRepository<GameRound> repo, IRepository<GamePoint> pointsRepo, IMethodSharingService<Participant> sharingService) : base()
{
_Repository = repo;
_pointsRepo = pointsRepo;
_sharingService = sharingService;
_roundElements = new ObservableCollection<RoundBuilderElement>();
}
@ -26,6 +27,7 @@ public class RoundStartingViewModel : ViewModelBase
private ObservableCollection<GameRound> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
private readonly IRepository<GameRound>? _Repository;
private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService;
private Participant _selectedItem;
@ -65,8 +67,38 @@ public class RoundStartingViewModel : ViewModelBase
GameRoundStartDate = DateTime.Now,
GameRoundFinished = null
};
_Repository?.Save(GameRound).GetAwaiter().GetResult();
var gameRoundId = _Repository?.Save(GameRound).GetAwaiter().GetResult();
if (gameRoundId != null && gameRoundId != -1)
{
GameRound.GameRoundId = gameRoundId.Value;
}
GameRoundObject = GameRound;
}
var GamePointStart = new GamePoint
{
ParticipantId = item.ParticipantId,
GameRoundId = GameRoundObject?.GameRoundId ?? 0,
GameDate = DateTime.Now,
GameRoundRegNr = 0,
GameRegPoints = 0,
PointStatus = GamePointStatus.New
};
var gamePointId = _pointsRepo.Save(GamePointStart).GetAwaiter().GetResult();
GamePointStart.GamePointId = gamePointId;
var newElement = new RoundBuilderElement();
newElement.ParticipantId = item.ParticipantId;
newElement.ParticipantName = item.LastNameFirstName;
newElement.GameRoundRegNr = GamePointStart.GameRoundRegNr;
newElement.GameRegPoints = GamePointStart.GameRegPoints;
newElement.Status = GamePointStart.PointStatus;
newElement.GameRoundStartDate = GameRoundObject?.GameRoundStartDate ?? DateTime.Now;
newElement.GameRoundId = GamePointStart.GameRoundId;
newElement.GamePointId = GamePointStart.GamePointId;
_roundElements.Add(newElement);
// Gör något med det valda objektet
Debug.WriteLine($"Du valde: {item.LastNameFirstName}");
}
@ -151,7 +183,7 @@ public class RoundStartingViewModel : ViewModelBase
return false;
}
var tmpTask = _Repository.Save(GameRoundObject);
bool tmp = tmpTask.GetAwaiter().GetResult();
bool tmp = tmpTask.GetAwaiter().GetResult() != -1;
if (tmp)
{
GameRoundObject = new GameRound();