diff --git a/Common.Library/BaseClasses/CommonBase.cs b/Common.Library/BaseClasses/CommonBase.cs deleted file mode 100644 index be93963..0000000 --- a/Common.Library/BaseClasses/CommonBase.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.ComponentModel; - -namespace Common.Library; - -public abstract class CommonBase : INotifyPropertyChanged -{ - #region Constructor - protected CommonBase() - { - Init(); - } - #endregion - - #region Init Method - public virtual void Init() - { - - } - #endregion - - - #region RaisePropertyChanged Method - public event PropertyChangedEventHandler? PropertyChanged; - public virtual void RaisePropertyChanged(string propertyName) - { - this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - #endregion -} diff --git a/Common.Library/BaseClasses/EntityBase.cs b/Common.Library/BaseClasses/EntityBase.cs deleted file mode 100644 index c9de9fe..0000000 --- a/Common.Library/BaseClasses/EntityBase.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Common.Library; - -public class EntityBase : CommonBase -{ -} diff --git a/Common.Library/BaseClasses/ViewModelBase.cs b/Common.Library/BaseClasses/ViewModelBase.cs deleted file mode 100644 index e33b2e7..0000000 --- a/Common.Library/BaseClasses/ViewModelBase.cs +++ /dev/null @@ -1,14 +0,0 @@ -//using GreadyPoang.DataLayer; - -namespace Common.Library; -public class ViewModelBase : CommonBase -{ - //private readonly LocalDbService _dbService; - - //public ViewModelBase(LocalDbService dbService) - //{ - // _dbService = dbService; - //} - -} - diff --git a/Common.Library/Common.Library.csproj b/Common.Library/Common.Library.csproj index 872f283..d555782 100644 --- a/Common.Library/Common.Library.csproj +++ b/Common.Library/Common.Library.csproj @@ -6,19 +6,9 @@ enable - - - - - - - - - - diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs index 0de91f5..b3a5184 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/ParticipantViewModel.cs @@ -1,5 +1,6 @@ using Common.Library; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using GreadyPoang.EntityLayer; using System.Collections.ObjectModel; @@ -20,6 +21,7 @@ public partial class ParticipantViewModel : ObservableObject _sharingService = sharingService; ParticipantObject = new Participant(); ParticipantList = new ObservableCollection(); + IsSaveCommandEnabled = true; } #endregion @@ -33,6 +35,11 @@ public partial class ParticipantViewModel : ObservableObject private readonly IMethodSharingService _sharingService; #endregion + + [ObservableProperty] + private bool isSaveCommandEnabled; + + #region Get Method public ObservableCollection Get() { @@ -58,7 +65,12 @@ public partial class ParticipantViewModel : ObservableObject return ParticipantObject; } - public virtual bool Save() + + #endregion + + + [RelayCommand(CanExecute = nameof(IsSaveCommandEnabled))] + private async Task Save() { if (_Repository == null || ParticipantObject == null) { @@ -70,8 +82,21 @@ public partial class ParticipantViewModel : ObservableObject { ParticipantObject = new Participant(); this.Get(); + await Shell.Current.GoToAsync(".."); } return tmp != -1; } - #endregion + + [RelayCommand] + private void DeleteAsync(Participant pp) + { + Console.WriteLine($"Valt från ViewModel: {pp.FullName}"); + if (_Repository == null || pp == null || pp.ParticipantId <= 0) + { + return; + } + var tmpTask = _Repository.Delete(pp); + this.Get(); + Shell.Current.GoToAsync(".."); + } } \ No newline at end of file diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs index 30cf0a6..b0adc92 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs @@ -1,5 +1,6 @@ using Common.Library; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using GreadyPoang.DataLayer; using GreadyPoang.EntityLayer; using GreadyPoang.Services; @@ -98,8 +99,8 @@ public partial class RoundRunningViewModel : ObservableObject return RoundElements; } - - public void StoreAndHandlePoints() + [RelayCommand] + private void StoreAndHandlePointsAsync() { var game = _roundsRepo.Get(BuilderObject.GameRoundId).GetAwaiter().GetResult(); var regNr = RoundElements.Count > 0 ? RoundElements.Max(e => e.GameRoundRegNr) + 1 : 1; @@ -147,6 +148,8 @@ public partial class RoundRunningViewModel : ObservableObject RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints; } TriggerRebuild(); + Shell.Current.GoToAsync("..").GetAwaiter().GetResult(); + } private int nextPlayerElement() diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs index 4c87b94..4b84b0d 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs @@ -1,5 +1,6 @@ using Common.Library; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using GreadyPoang.DataLayer; using GreadyPoang.EntityLayer; using GreadyPoang.Services; @@ -39,6 +40,7 @@ public partial class RoundStartingViewModel : ObservableObject private readonly ICombinedRepository _combined; private readonly IObjectMessageService _objectMessage; + [ObservableProperty] private Participant selectedItem; partial void OnSelectedItemChanged(Participant value) @@ -108,6 +110,7 @@ public partial class RoundStartingViewModel : ObservableObject } + #region Get Method public ObservableCollection Get() { @@ -167,7 +170,9 @@ public partial class RoundStartingViewModel : ObservableObject return GameRoundObject; } - public virtual bool Save() + + [RelayCommand] + public async Task SaveAsync() { if (_roundsRepo == null || GameRoundObject == null) { @@ -180,11 +185,13 @@ public partial class RoundStartingViewModel : ObservableObject GameRoundObject = new GameRound(); RoundElements.Clear(); this.Get(); + await Shell.Current.GoToAsync(".."); } return tmp; } - public void Rensa() + [RelayCommand] + private async Task RensaAsync() { foreach (var element in RoundElements) { @@ -192,22 +199,31 @@ public partial class RoundStartingViewModel : ObservableObject } _roundsRepo?.DeleteById(GameRoundObject?.GameRoundId ?? 0); RoundElements.Clear(); + await Shell.Current.GoToAsync(".."); } - public void RoundSelected(RoundBuilderElement element) + [RelayCommand] + public async Task RoundSelected(RoundBuilderElement element) { + bool goneOk = false; var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId); Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}"); if (rbGroup != null) { _objectMessage.CurrentGroup = rbGroup; - Shell.Current.GoToAsync("//RoundRunningView"); + await Shell.Current.GoToAsync("//RoundRunningView"); + goneOk = true; } + return goneOk; } - public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder) + [RelayCommand] + public async Task SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder) { + bool goneOk = false; Debug.WriteLine($"Du valde raden med Runda {roundBuilder.GameRoundId} och spelare: {roundBuilder.ParticipantName}"); + goneOk = true; + return goneOk; } #endregion diff --git a/GreadyPoang/CommandClasses/ParticipantViewModelCommands.cs b/GreadyPoang/CommandClasses/ParticipantViewModelCommands.cs deleted file mode 100644 index 7925764..0000000 --- a/GreadyPoang/CommandClasses/ParticipantViewModelCommands.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Common.Library; -using CommunityToolkit.Mvvm.ComponentModel; -using GreadyPoang.EntityLayer; -using GreadyPoang.ViewModelLayer; -using System.Windows.Input; - -namespace GreadyPoang.CommandClasses; - -public partial class ParticipantViewModelCommands : ParticipantViewModel -{ - #region constructors - public ParticipantViewModelCommands() : base() - { - - } - public ParticipantViewModelCommands(IRepository repo, IMethodSharingService sharingService) : base(repo, sharingService) - { - Init(); - IsSaveCommandEnabled = true; - } - - #endregion - - #region Private Variables - [ObservableProperty] - private bool isSaveCommandEnabled; - #endregion - - #region Commands - public ICommand SaveCommand { get; private set; } - public ICommand EditCommand { get; private set; } - #endregion - - #region Init Method - public void Init() - { - //base.Init(); - SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled); - EditCommand = new Command(async (id) => await EditAsync(id), (id) => id > 0); - } - #endregion - - protected async Task EditAsync(int id) - { - await Shell.Current.GoToAsync($"{nameof(Views.ParticipantListView)}?id={id}"); - } - - public async Task SaveAsync() - { - var ret = base.Save(); - if (ret) - { - await Shell.Current.GoToAsync(".."); - } - - return ret; - } -} diff --git a/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs b/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs deleted file mode 100644 index d0aa544..0000000 --- a/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Common.Library; -using GreadyPoang.DataLayer; -using GreadyPoang.EntityLayer; -using GreadyPoang.Services; -using GreadyPoang.ViewModelLayer; -using System.Windows.Input; - -namespace GreadyPoang.CommandClasses; - -public class RoundRunningViewModelCommands : RoundRunningViewModel -{ - public RoundRunningViewModelCommands() : base() - { - } - - public RoundRunningViewModelCommands( - IRepository roundsRepo, - IRepository pointsRepo, - IMethodSharingService sharingService, - ICombinedRepository combined, - IObjectMessageService objectMessage) - : base(roundsRepo, - pointsRepo, - sharingService, - combined, - objectMessage) - { - Init(); - } - - #region Commands - //public ICommand SaveCommand { get; private set; } - //public ICommand EditCommand { get; private set; } - //public ICommand RensaCommand { get; private set; } - //public ICommand ElementTappedCommand { get; private set; } - //public ICommand ParticipantTappedCommand { get; private set; } - public ICommand StoreAndHandlePointsCommand { get; private set; } - - #endregion - - public void Init() - { - StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync()); - } - - private async Task StoreAndHandleAsync() - { - base.StoreAndHandlePoints(); - await Shell.Current.GoToAsync(".."); - } -} diff --git a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs b/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs deleted file mode 100644 index a9b3176..0000000 --- a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs +++ /dev/null @@ -1,99 +0,0 @@ -using Common.Library; -using CommunityToolkit.Mvvm.ComponentModel; -using GreadyPoang.DataLayer; -using GreadyPoang.EntityLayer; -using GreadyPoang.Services; -using GreadyPoang.ViewModelLayer; -using System.Windows.Input; - -namespace GreadyPoang.CommandClasses; - -public partial class RoundStartingViewModelCommands : RoundStartingViewModel -{ - public RoundStartingViewModelCommands() : base() - { - - } - public RoundStartingViewModelCommands( - IRepository roundsRepo, - IRepository pointsRepo, - IMethodSharingService sharingService, - ICombinedRepository combined, - IObjectMessageService objectMessage) - : base(roundsRepo, - pointsRepo, - sharingService, - combined, - objectMessage) - { - Init(); - IsSaveCommandEnabled = true; - } - - #region Private Variables - [ObservableProperty] - private bool isSaveCommandEnabled; - #endregion - - #region Commands - public ICommand SaveCommand { get; private set; } - public ICommand EditCommand { get; private set; } - public ICommand RensaCommand { get; private set; } - public ICommand ElementTappedCommand { get; private set; } - public ICommand ParticipantTappedCommand { get; private set; } - #endregion - - #region Init Method - - public void Init() - { - //base.Init(); - SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled); - EditCommand = new Command(async (id) => await EditAsync(id), (id) => id > 0); - RensaCommand = new Command(async () => RensaAsync()); - ParticipantTappedCommand = new Command(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant)); - ElementTappedCommand = new Command((selectedElement) => RoundSelected(selectedElement)); - - } - - private async Task RensaAsync() - { - base.Rensa(); - await Shell.Current.GoToAsync(".."); - } - #endregion - - protected async Task EditAsync(int id) - { - await Shell.Current.GoToAsync($"{nameof(Views.RoundStartingView)}?id={id}"); - } - - public async Task SaveAsync() - { - var ret = base.Save(); - if (ret) - { - await Shell.Current.GoToAsync(".."); - } - - return ret; - } - - public async Task RoundSelected(RoundBuilderElement element) - { - bool goneOk = false; - base.RoundSelected(element); - goneOk = true; - return goneOk; - } - - public async Task SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder) - { - bool goneOk = false; - base.SelectNewlyAddedParticipant(roundBuilder); - goneOk = true; - return goneOk; - - } - -} diff --git a/GreadyPoang/MauiProgram.cs b/GreadyPoang/MauiProgram.cs index 3cb05c1..f3df99b 100644 --- a/GreadyPoang/MauiProgram.cs +++ b/GreadyPoang/MauiProgram.cs @@ -1,5 +1,4 @@ using Common.Library; -using GreadyPoang.CommandClasses; using GreadyPoang.DataLayer; using GreadyPoang.DataLayer.Database; using GreadyPoang.EntityLayer; @@ -39,15 +38,15 @@ public static class MauiProgram }); builder.Services.AddScoped, ParticipantRepository>(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped, GameRoundRepository>(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped, GamePointRepository>(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped, MethodSharingService>(); diff --git a/GreadyPoang/Views/ParticipantListView.xaml b/GreadyPoang/Views/ParticipantListView.xaml index 121ef2e..1df23c5 100644 --- a/GreadyPoang/Views/ParticipantListView.xaml +++ b/GreadyPoang/Views/ParticipantListView.xaml @@ -2,13 +2,15 @@ + + @@ -22,9 +24,9 @@ ViewDescription="Lägg till deltagare här" /> -