Infört Observable Property och observable object från Community Toolkit
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Common.Library;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GreadyPoang.DataLayer;
|
||||
using GreadyPoang.EntityLayer;
|
||||
using GreadyPoang.Services;
|
||||
@ -7,7 +8,7 @@ using System.Diagnostics;
|
||||
|
||||
namespace GreadyPoang.ViewModelLayer;
|
||||
|
||||
public class RoundStartingViewModel : ViewModelBase
|
||||
public partial class RoundStartingViewModel : ObservableObject
|
||||
{
|
||||
#region Constructors
|
||||
public RoundStartingViewModel() : base()
|
||||
@ -27,52 +28,100 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
_sharingService = sharingService;
|
||||
_combined = combined;
|
||||
_objectMessage = objectMessage;
|
||||
_roundElements = new ObservableCollection<RoundBuilderElement>();
|
||||
RoundElements = new ObservableCollection<RoundBuilderElement>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GameRound? _GameRoundObject = new();
|
||||
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
|
||||
private ObservableCollection<Participant> _ParticipantList = new();
|
||||
private readonly IRepository<GameRound>? _roundsRepo;
|
||||
private readonly IRepository<GamePoint> _pointsRepo;
|
||||
private readonly IMethodSharingService<Participant> _sharingService;
|
||||
private readonly ICombinedRepository _combined;
|
||||
private readonly IObjectMessageService _objectMessage;
|
||||
private Participant _selectedItem;
|
||||
|
||||
private ObservableCollection<RoundBuilderElement> _roundElements;
|
||||
|
||||
public ObservableCollection<RoundBuilderElement> RoundElements
|
||||
[ObservableProperty]
|
||||
private Participant selectedItem;
|
||||
partial void OnSelectedItemChanged(Participant value)
|
||||
{
|
||||
get { return _roundElements; }
|
||||
set
|
||||
if (value != null)
|
||||
{
|
||||
_roundElements = value;
|
||||
RaisePropertyChanged(nameof(RoundElements));
|
||||
OnItemSelected(value);
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<RoundBuilderElement> roundElements;
|
||||
|
||||
public Participant SelectedItem
|
||||
{
|
||||
get => _selectedItem;
|
||||
set
|
||||
{
|
||||
if (_selectedItem != value)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private GameRound? gameRoundObject = new();
|
||||
|
||||
_selectedItem = value;
|
||||
RaisePropertyChanged(nameof(SelectedItem));
|
||||
OnItemSelected(value); // Metod som triggas vid val
|
||||
}
|
||||
}
|
||||
}
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<RoundBuilderGroup> gameRoundList = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<Participant> participantList = new();
|
||||
|
||||
|
||||
#region commented out
|
||||
|
||||
//public ObservableCollection<RoundBuilderElement> RoundElements
|
||||
//{
|
||||
// get { return _roundElements; }
|
||||
// set
|
||||
// {
|
||||
// _roundElements = value;
|
||||
// OnPropertyChanged(nameof(RoundElements));
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
//public Participant SelectedItem
|
||||
//{
|
||||
// get => _selectedItem;
|
||||
// set
|
||||
// {
|
||||
// if (_selectedItem != value)
|
||||
// {
|
||||
|
||||
// _selectedItem = value;
|
||||
// OnPropertyChanged(nameof(SelectedItem));
|
||||
// OnItemSelected(value); // Metod som triggas vid val
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//public GameRound? GameRoundObject
|
||||
//{
|
||||
// get { return _GameRoundObject; }
|
||||
// set
|
||||
// {
|
||||
// _GameRoundObject = value;
|
||||
// OnPropertyChanged(nameof(GameRoundObject));
|
||||
// }
|
||||
//}
|
||||
|
||||
//public ObservableCollection<RoundBuilderGroup> GameRoundList
|
||||
//{
|
||||
// get { return _GameRoundList; }
|
||||
// set
|
||||
// {
|
||||
// _GameRoundList = value;
|
||||
// OnPropertyChanged(nameof(GameRoundList));
|
||||
// }
|
||||
//}
|
||||
//public ObservableCollection<Participant> ParticipantList
|
||||
//{
|
||||
// get { return _ParticipantList; }
|
||||
// set
|
||||
// {
|
||||
// _ParticipantList = value;
|
||||
// OnPropertyChanged(nameof(ParticipantList));
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
private void OnItemSelected(Participant item)
|
||||
{
|
||||
if (_roundElements.Count == 0)
|
||||
if (RoundElements.Count == 0)
|
||||
{
|
||||
var GameRound = new GameRound
|
||||
{
|
||||
@ -110,42 +159,12 @@ public class RoundStartingViewModel : ViewModelBase
|
||||
newElement.GameRoundId = GamePointStart.GameRoundId;
|
||||
newElement.GamePointId = GamePointStart.GamePointId;
|
||||
|
||||
_roundElements.Add(newElement);
|
||||
RoundElements.Add(newElement);
|
||||
// Gör något med det valda objektet
|
||||
Debug.WriteLine($"Du valde: {item.LastNameFirstName}");
|
||||
}
|
||||
|
||||
|
||||
public GameRound? GameRoundObject
|
||||
{
|
||||
get { return _GameRoundObject; }
|
||||
set
|
||||
{
|
||||
_GameRoundObject = value;
|
||||
RaisePropertyChanged(nameof(GameRoundObject));
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<RoundBuilderGroup> GameRoundList
|
||||
{
|
||||
get { return _GameRoundList; }
|
||||
set
|
||||
{
|
||||
_GameRoundList = value;
|
||||
RaisePropertyChanged(nameof(GameRoundList));
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<Participant> ParticipantList
|
||||
{
|
||||
get { return _ParticipantList; }
|
||||
set
|
||||
{
|
||||
_ParticipantList = value;
|
||||
RaisePropertyChanged(nameof(ParticipantList));
|
||||
}
|
||||
}
|
||||
|
||||
#region Get Method
|
||||
public ObservableCollection<RoundBuilderGroup> Get()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user