From b4898660f2fd6e2951dbe6393e8a8cae17442d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sat, 13 Sep 2025 08:43:17 +0200 Subject: [PATCH] =?UTF-8?q?Commit=20f=C3=B6re=20flytt=20avStatusparameter?= =?UTF-8?q?=20fr=C3=A5n=20point=20till=20round?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common.Library/Interfaces/IRepository.cs | 1 + .../DataClasses/CombinedRepository.cs | 36 ++++++++ .../DataClasses/GamePointRepository.cs | 22 ++++- .../DataClasses/GameRoundRepository.cs | 20 ++++ .../DataClasses/ParticipantRepository.cs | 19 ++++ .../LocalInterfaces/ICombinedRepository.cs | 9 ++ .../EntityClasses/GamePoint.cs | 12 --- .../EntityClasses/GameRound.cs | 18 ++++ .../RoundStartingViewModel.cs | 13 ++- .../RoundStartingViewModelCommands.cs | 8 ++ GreadyPoang/MauiProgram.cs | 7 +- GreadyPoang/Views/ParticipantListView.xaml | 4 +- GreadyPoang/Views/RoundStartingView.xaml | 91 ++++++++++++++++--- 13 files changed, 226 insertions(+), 34 deletions(-) create mode 100644 GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs create mode 100644 GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs diff --git a/Common.Library/Interfaces/IRepository.cs b/Common.Library/Interfaces/IRepository.cs index 5aecb47..9f2cf62 100644 --- a/Common.Library/Interfaces/IRepository.cs +++ b/Common.Library/Interfaces/IRepository.cs @@ -6,4 +6,5 @@ public interface IRepository Task Get(int id); Task Save(TEntity entity); bool Delete(TEntity entity); + Task DeleteById(int Id); } diff --git a/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs new file mode 100644 index 0000000..335be9e --- /dev/null +++ b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs @@ -0,0 +1,36 @@ +using GreadyPoang.DataLayer.Database; +using GreadyPoang.EntityLayer; + +namespace GreadyPoang.DataLayer; + +public class CombinedRepository : ICombinedRepository +{ + private readonly DataContext _context; + + public CombinedRepository(DataContext context) + { + _context = context; + } + + + IEnumerable ICombinedRepository.roundBuilderElements() + { + var result = (from gameRound in _context.GameRounds + join gamePoint in _context.GamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId + join participant in _context.Participants on gamePoint.ParticipantId equals participant.ParticipantId + orderby gameRound.GameRoundStartDate descending, participant.LastName, participant.FirstName, gamePoint.GameRoundRegNr + select new RoundBuilderElement + { + ParticipantId = participant.ParticipantId, + ParticipantName = participant.LastNameFirstName, + GamePointId = gamePoint.GamePointId, + GameRoundRegNr = gameRound.GameRoundId, + GameRegPoints = gamePoint.GameRegPoints, + GameRoundId = gameRound.GameRoundId, + GameRoundStartDate = gameRound.GameRoundStartDate, + Status = gamePoint.PointStatus + }).ToList(); + return result; + + } +} diff --git a/GreadyPoang.DataLayer/DataClasses/GamePointRepository.cs b/GreadyPoang.DataLayer/DataClasses/GamePointRepository.cs index 178c0bd..f71a129 100644 --- a/GreadyPoang.DataLayer/DataClasses/GamePointRepository.cs +++ b/GreadyPoang.DataLayer/DataClasses/GamePointRepository.cs @@ -25,7 +25,7 @@ public class GamePointRepository : IRepository { var res = -1; if ((entity.GameRoundRegNr == 0) - || (entity.GameRegPoints == 0)) + && (entity.GameRegPoints == 0)) { return res; // Validation failed } @@ -51,7 +51,7 @@ public class GamePointRepository : IRepository try { _dataContext.GamePoints.Remove(entity); - _dataContext.SaveChanges(); + _dataContext.SaveChangesAsync(); res = true; } catch (Exception ex) @@ -62,6 +62,22 @@ public class GamePointRepository : IRepository return res; } + public async Task DeleteById(int Id) + { + var ok = false; + var delObject = await this.Get(Id); + if (delObject != null) + { - + try + { + ok = this.Delete(delObject); + } + catch (Exception ex) + { + throw new Exception("Unsuccessful remove of GamePoint: " + ex.Message); + } + } + return ok; + } } diff --git a/GreadyPoang.DataLayer/DataClasses/GameRoundRepository.cs b/GreadyPoang.DataLayer/DataClasses/GameRoundRepository.cs index 4b63b07..392e467 100644 --- a/GreadyPoang.DataLayer/DataClasses/GameRoundRepository.cs +++ b/GreadyPoang.DataLayer/DataClasses/GameRoundRepository.cs @@ -58,4 +58,24 @@ public class GameRoundRepository : IRepository } return res; } + + public async Task DeleteById(int Id) + { + var ok = false; + var delObject = await this.Get(Id); + if (delObject != null) + { + + try + { + ok = this.Delete(delObject); + } + catch (Exception ex) + { + throw new Exception("Unsuccessful remove of GameRound: " + ex.Message); + } + } + return ok; + } + } diff --git a/GreadyPoang.DataLayer/DataClasses/ParticipantRepository.cs b/GreadyPoang.DataLayer/DataClasses/ParticipantRepository.cs index 29953bf..af72206 100644 --- a/GreadyPoang.DataLayer/DataClasses/ParticipantRepository.cs +++ b/GreadyPoang.DataLayer/DataClasses/ParticipantRepository.cs @@ -62,4 +62,23 @@ public class ParticipantRepository : IRepository } return res; } + + public async Task DeleteById(int Id) + { + var ok = false; + var delObject = await this.Get(Id); + if (delObject != null) + { + + try + { + ok = this.Delete(delObject); + } + catch (Exception ex) + { + throw new Exception("Unsuccessful remove of Participant: " + ex.Message); + } + } + return ok; + } } diff --git a/GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs b/GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs new file mode 100644 index 0000000..3595681 --- /dev/null +++ b/GreadyPoang.DataLayer/LocalInterfaces/ICombinedRepository.cs @@ -0,0 +1,9 @@ + +using GreadyPoang.EntityLayer; + +namespace GreadyPoang.DataLayer; + +public interface ICombinedRepository +{ + IEnumerable roundBuilderElements(); +} \ No newline at end of file diff --git a/GreadyPoang.EntityLayer/EntityClasses/GamePoint.cs b/GreadyPoang.EntityLayer/EntityClasses/GamePoint.cs index 9fb1653..76baa0b 100644 --- a/GreadyPoang.EntityLayer/EntityClasses/GamePoint.cs +++ b/GreadyPoang.EntityLayer/EntityClasses/GamePoint.cs @@ -13,7 +13,6 @@ public class GamePoint : EntityBase _gameDate = DateTime.Now; _gameRoundRegNr = 0; _gameRegPoints = 0; - _pointStatus = GamePointStatus.New; } private int _gamePointId; @@ -22,7 +21,6 @@ public class GamePoint : EntityBase private DateTime _gameDate; private int _gameRoundRegNr; private int _gameRegPoints; - private GamePointStatus _pointStatus; [PrimaryKey] [AutoIncrement] @@ -91,16 +89,6 @@ public class GamePoint : EntityBase } } - [Column("PointStatus")] - public GamePointStatus PointStatus - { - get { return _pointStatus; } - set - { - _pointStatus = value; - RaisePropertyChanged(nameof(PointStatus)); - } - } } diff --git a/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs b/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs index b58e267..4a60878 100644 --- a/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs +++ b/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs @@ -12,11 +12,13 @@ public class GameRound : EntityBase { _gameRoundId = 0; _gameRoundStartDate = DateTime.Now; + _gameStatus = GamePointStatus.New; _gameRoundFinished = null; } private int _gameRoundId; private DateTime _gameRoundStartDate; + private GamePointStatus _gameStatus; private DateTime? _gameRoundFinished; [Column("GameRoundFinished")] @@ -41,6 +43,18 @@ public class GameRound : EntityBase } } + [Column("GameStatus")] + public GamePointStatus PointStatus + { + get { return _gameStatus; } + set + { + _gameStatus = value; + RaisePropertyChanged(nameof(PointStatus)); + } + } + + [PrimaryKey] [AutoIncrement] [Column("GameRoundId")] @@ -54,6 +68,10 @@ public class GameRound : EntityBase } } + public string GameRoundStartDateString + { + get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); } + } } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs index f4c585e..90c2c00 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs @@ -80,7 +80,7 @@ public class RoundStartingViewModel : ViewModelBase ParticipantId = item.ParticipantId, GameRoundId = GameRoundObject?.GameRoundId ?? 0, GameDate = DateTime.Now, - GameRoundRegNr = 0, + GameRoundRegNr = -1, GameRegPoints = 0, PointStatus = GamePointStatus.New }; @@ -187,11 +187,22 @@ public class RoundStartingViewModel : ViewModelBase if (tmp) { GameRoundObject = new GameRound(); + RoundElements.Clear(); this.Get(); } return tmp; } + public void Rensa() + { + foreach (var element in RoundElements) + { + _pointsRepo.DeleteById(element.GamePointId); + } + _Repository?.DeleteById(GameRoundObject?.GameRoundId ?? 0); + RoundElements.Clear(); + } + #endregion } diff --git a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs b/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs index 0815fbd..eaf8cc2 100644 --- a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs +++ b/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs @@ -35,6 +35,7 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel #region Commands public ICommand SaveCommand { get; private set; } public ICommand EditCommand { get; private set; } + public ICommand RensaCommand { get; private set; } #endregion #region Init Method @@ -43,6 +44,13 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel base.Init(); SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled); EditCommand = new Command(async (id) => await EditAsync(id), (id) => id > 0); + RensaCommand = new Command(async () => RensaAsync()); + } + + private async Task RensaAsync() + { + base.Rensa(); + await Shell.Current.GoToAsync(".."); } #endregion diff --git a/GreadyPoang/MauiProgram.cs b/GreadyPoang/MauiProgram.cs index 981a805..1fa9d07 100644 --- a/GreadyPoang/MauiProgram.cs +++ b/GreadyPoang/MauiProgram.cs @@ -15,6 +15,7 @@ public static class MauiProgram public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); + builder .UseMauiApp() .ConfigureFonts(fonts => @@ -23,6 +24,8 @@ public static class MauiProgram fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); + + builder.Services.AddDbContext(options => { var MauiDataPath = FileSystem.Current.AppDataDirectory; @@ -34,8 +37,6 @@ public static class MauiProgram options.UseSqlite($"Data Source={dbPath}"); }); - - builder.Services.AddScoped, ParticipantRepository>(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -49,6 +50,8 @@ public static class MauiProgram builder.Services.AddScoped, MethodSharingService>(); + builder.Services.AddScoped(); + #if DEBUG builder.Logging.AddDebug(); #endif diff --git a/GreadyPoang/Views/ParticipantListView.xaml b/GreadyPoang/Views/ParticipantListView.xaml index bfe2726..11bea9d 100644 --- a/GreadyPoang/Views/ParticipantListView.xaml +++ b/GreadyPoang/Views/ParticipantListView.xaml @@ -72,8 +72,8 @@ Text="{Binding LastNameFirstName}" /> -