Infört Observable Property och observable object från Community Toolkit
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
using Common.Library;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GreadyPoang.EntityLayer;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace GreadyPoang.ViewModelLayer;
|
||||
|
||||
public class MethodSharingService : ViewModelBase, IMethodSharingService<Participant>
|
||||
public class MethodSharingService : ObservableObject, IMethodSharingService<Participant>
|
||||
{
|
||||
private readonly IRepository<Participant> _repository;
|
||||
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
using Common.Library;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GreadyPoang.EntityLayer;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
|
||||
namespace GreadyPoang.ViewModelLayer;
|
||||
|
||||
public class ParticipantViewModel : ViewModelBase
|
||||
public partial class ParticipantViewModel : ObservableObject
|
||||
{
|
||||
#region Constructors
|
||||
public ParticipantViewModel() : base()
|
||||
@ -17,41 +18,21 @@ public class ParticipantViewModel : ViewModelBase
|
||||
{
|
||||
_Repository = repo;
|
||||
_sharingService = sharingService;
|
||||
ParticipantObject = new Participant();
|
||||
ParticipantList = new ObservableCollection<Participant>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
private Participant? _ParticipantObject = new();
|
||||
private ObservableCollection<Participant> _ParticipantList = new();
|
||||
[ObservableProperty]
|
||||
private Participant? participantObject;
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<Participant> participantList;
|
||||
private readonly IRepository<Participant>? _Repository;
|
||||
private readonly IMethodSharingService<Participant> _sharingService;
|
||||
#endregion
|
||||
|
||||
#region public Properties
|
||||
|
||||
public Participant? ParticipantObject
|
||||
{
|
||||
get { return _ParticipantObject; }
|
||||
set
|
||||
{
|
||||
_ParticipantObject = value;
|
||||
RaisePropertyChanged(nameof(ParticipantObject));
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<Participant> ParticipantList
|
||||
{
|
||||
get { return _ParticipantList; }
|
||||
set
|
||||
{
|
||||
_ParticipantList = value;
|
||||
RaisePropertyChanged(nameof(ParticipantList));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Get Method
|
||||
public ObservableCollection<Participant> Get()
|
||||
{
|
||||
|
||||
@ -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 RoundRunningViewModel : ViewModelBase
|
||||
public partial class RoundRunningViewModel : ObservableObject
|
||||
{
|
||||
|
||||
public event EventHandler RebuildRequested;
|
||||
@ -30,8 +31,8 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
_sharingService = sharingService;
|
||||
_combined = combined;
|
||||
_objectMessage = objectMessage;
|
||||
_roundElements = new ObservableCollection<RoundBuilderElement>();
|
||||
_builderObject = new();
|
||||
RoundElements = new ObservableCollection<RoundBuilderElement>();
|
||||
BuilderObject = new();
|
||||
}
|
||||
|
||||
private readonly IRepository<GameRound>? _roundsRepo;
|
||||
@ -40,11 +41,15 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
private readonly ICombinedRepository _combined;
|
||||
private readonly IObjectMessageService _objectMessage;
|
||||
|
||||
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
|
||||
private ObservableCollection<Participant> _ParticipantList = new();
|
||||
private ObservableCollection<RoundBuilderElement> _roundElements;
|
||||
private Collection<PlayerColumn> _playerColumns;
|
||||
private RoundBuilderElement _builderObject;
|
||||
//private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
|
||||
//private ObservableCollection<Participant> _ParticipantList = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<RoundBuilderElement> roundElements;
|
||||
[ObservableProperty]
|
||||
private Collection<PlayerColumn> playerColumns;
|
||||
[ObservableProperty]
|
||||
private RoundBuilderElement builderObject;
|
||||
|
||||
public void TriggerRebuild()
|
||||
{
|
||||
@ -52,35 +57,35 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
RebuildRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public ObservableCollection<RoundBuilderElement> RoundElements
|
||||
{
|
||||
get { return _roundElements; }
|
||||
set
|
||||
{
|
||||
_roundElements = value;
|
||||
RaisePropertyChanged(nameof(RoundElements));
|
||||
}
|
||||
}
|
||||
//public ObservableCollection<RoundBuilderElement> RoundElements
|
||||
//{
|
||||
// get { return _roundElements; }
|
||||
// set
|
||||
// {
|
||||
// _roundElements = value;
|
||||
// OnPropertyChanged(nameof(RoundElements));
|
||||
// }
|
||||
//}
|
||||
|
||||
public Collection<PlayerColumn> PlayerColumns
|
||||
{
|
||||
get { return _playerColumns; }
|
||||
set
|
||||
{
|
||||
_playerColumns = value;
|
||||
RaisePropertyChanged(nameof(PlayerColumns));
|
||||
}
|
||||
}
|
||||
//public Collection<PlayerColumn> PlayerColumns
|
||||
//{
|
||||
// get { return _playerColumns; }
|
||||
// set
|
||||
// {
|
||||
// _playerColumns = value;
|
||||
// OnPropertyChanged(nameof(PlayerColumns));
|
||||
// }
|
||||
//}
|
||||
|
||||
public RoundBuilderElement BuilderObject
|
||||
{
|
||||
get { return _builderObject; }
|
||||
set
|
||||
{
|
||||
_builderObject = value;
|
||||
RaisePropertyChanged(nameof(BuilderObject));
|
||||
}
|
||||
}
|
||||
//public RoundBuilderElement BuilderObject
|
||||
//{
|
||||
// get { return _builderObject; }
|
||||
// set
|
||||
// {
|
||||
// _builderObject = value;
|
||||
// OnPropertyChanged(nameof(BuilderObject));
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
public ObservableCollection<RoundBuilderElement> Get()
|
||||
@ -97,7 +102,7 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
}
|
||||
foreach (var item in _objectMessage.CurrentGroup.Elements)
|
||||
{
|
||||
_roundElements.Add(item);
|
||||
RoundElements.Add(item);
|
||||
}
|
||||
|
||||
// Räkna ut vem som är nästa spelare
|
||||
@ -113,7 +118,7 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
|
||||
|
||||
FillupResultTable(localElements);
|
||||
foreach (var col in _playerColumns)
|
||||
foreach (var col in PlayerColumns)
|
||||
{
|
||||
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
|
||||
}
|
||||
@ -166,7 +171,7 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
|
||||
var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId);
|
||||
FillupResultTable(localElements);
|
||||
foreach (var col in _playerColumns)
|
||||
foreach (var col in PlayerColumns)
|
||||
{
|
||||
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
|
||||
}
|
||||
@ -189,13 +194,13 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
|
||||
private void FillupResultTable(IEnumerable<RoundBuilderElement> elements)
|
||||
{
|
||||
if (_playerColumns != null)
|
||||
if (PlayerColumns != null)
|
||||
{
|
||||
_playerColumns.Clear();
|
||||
PlayerColumns.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerColumns = new Collection<PlayerColumn>();
|
||||
PlayerColumns = new Collection<PlayerColumn>();
|
||||
}
|
||||
|
||||
// if (elements.Any(g => g.GameRegPoints > 0))
|
||||
@ -205,7 +210,7 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
|
||||
foreach (var element in elements)
|
||||
{
|
||||
player = _playerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId);
|
||||
player = PlayerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
@ -224,9 +229,9 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
}
|
||||
//oldPart = element.ParticipantId;
|
||||
|
||||
if (!_playerColumns.Contains(player))
|
||||
if (!PlayerColumns.Contains(player))
|
||||
{
|
||||
_playerColumns.Add(player);
|
||||
PlayerColumns.Add(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -238,7 +243,9 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
{
|
||||
var player = new PlayerColumn
|
||||
{
|
||||
PlayerName = element.ParticipantName
|
||||
PlayerName = element.ParticipantName,
|
||||
PlayerId = element.ParticipantId,
|
||||
PlayerPoints = 0
|
||||
};
|
||||
|
||||
for (int i = 0; i < slumper.Next(6); i++)
|
||||
@ -246,7 +253,7 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
player.Values.Add(slumper.Next(1, 10).ToString());
|
||||
}
|
||||
|
||||
_playerColumns.Add(player);
|
||||
PlayerColumns.Add(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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