From 4e2b71af9f26ea192805e6119ecd51e6ad8959f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sun, 14 Sep 2025 12:03:16 +0200 Subject: [PATCH] =?UTF-8?q?Efter=20flytt=20av=20statusf=C3=A4lt=20och=20?= =?UTF-8?q?=C3=A5ter=20byygt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataClasses/CombinedRepository.cs | 6 +- GreadyPoang.DataLayer/Database/DataContext.cs | 14 +- ...20250914064850_statusfieldmove.Designer.cs | 178 ++++++++++++++++++ .../20250914064850_statusfieldmove.cs | 89 +++++++++ .../Migrations/DataContextModelSnapshot.cs | 27 ++- .../EntityClasses/GameRound.cs | 4 +- .../RoundStartingViewModel.cs | 56 ++++-- .../RoundStartingViewModelCommands.cs | 7 +- 8 files changed, 336 insertions(+), 45 deletions(-) create mode 100644 GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.Designer.cs create mode 100644 GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.cs diff --git a/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs index 335be9e..d4c0263 100644 --- a/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs +++ b/GreadyPoang.DataLayer/DataClasses/CombinedRepository.cs @@ -13,7 +13,7 @@ public class CombinedRepository : ICombinedRepository } - IEnumerable ICombinedRepository.roundBuilderElements() + public IEnumerable roundBuilderElements() { var result = (from gameRound in _context.GameRounds join gamePoint in _context.GamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId @@ -24,11 +24,11 @@ public class CombinedRepository : ICombinedRepository ParticipantId = participant.ParticipantId, ParticipantName = participant.LastNameFirstName, GamePointId = gamePoint.GamePointId, - GameRoundRegNr = gameRound.GameRoundId, + GameRoundRegNr = gamePoint.GameRoundRegNr, GameRegPoints = gamePoint.GameRegPoints, GameRoundId = gameRound.GameRoundId, GameRoundStartDate = gameRound.GameRoundStartDate, - Status = gamePoint.PointStatus + Status = gameRound.GameStatus }).ToList(); return result; diff --git a/GreadyPoang.DataLayer/Database/DataContext.cs b/GreadyPoang.DataLayer/Database/DataContext.cs index 63d5843..13a6497 100644 --- a/GreadyPoang.DataLayer/Database/DataContext.cs +++ b/GreadyPoang.DataLayer/Database/DataContext.cs @@ -23,15 +23,15 @@ public class DataContext : DbContext new Participant { ParticipantId = 3, FirstName = "Mary", LastName = "White", Email = "mw@gmail.com" } ); modelBuilder.Entity().HasData( - new GameRound { GameRoundId = 1, GameRoundStartDate = new DateTime(2025, 10, 15, 19, 10, 15), GameRoundFinished = DateTime.MinValue }, - new GameRound { GameRoundId = 2, GameRoundStartDate = new DateTime(2025, 09, 15, 19, 10, 15), GameRoundFinished = DateTime.MinValue }, - new GameRound { GameRoundId = 3, GameRoundStartDate = new DateTime(2025, 09, 20, 19, 10, 15), GameRoundFinished = DateTime.MinValue } + new GameRound { GameRoundId = 1, GameRoundStartDate = new DateTime(2025, 10, 15, 19, 10, 15), GameRoundFinished = DateTime.MinValue, GameStatus = GamePointStatus.New }, + new GameRound { GameRoundId = 2, GameRoundStartDate = new DateTime(2025, 09, 15, 19, 10, 15), GameRoundFinished = DateTime.MinValue, GameStatus = GamePointStatus.New }, + new GameRound { GameRoundId = 3, GameRoundStartDate = new DateTime(2025, 09, 20, 19, 10, 15), GameRoundFinished = DateTime.MinValue, GameStatus = GamePointStatus.New } ); modelBuilder.Entity().HasData( - new GamePoint { GamePointId = 1, ParticipantId = 1, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 10, 15), GameRoundRegNr = 1, GameRegPoints = 1050, PointStatus = GamePointStatus.New }, - new GamePoint { GamePointId = 2, ParticipantId = 1, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 15, 15), GameRoundRegNr = 3, GameRegPoints = 350, PointStatus = GamePointStatus.New }, - new GamePoint { GamePointId = 3, ParticipantId = 3, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 12, 15), GameRoundRegNr = 2, GameRegPoints = 1000, PointStatus = GamePointStatus.New }, - new GamePoint { GamePointId = 4, ParticipantId = 3, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 20, 15), GameRoundRegNr = 4, GameRegPoints = 400, PointStatus = GamePointStatus.New } + new GamePoint { GamePointId = 1, ParticipantId = 1, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 10, 15), GameRoundRegNr = 1, GameRegPoints = 1050 }, + new GamePoint { GamePointId = 2, ParticipantId = 1, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 15, 15), GameRoundRegNr = 3, GameRegPoints = 350 }, + new GamePoint { GamePointId = 3, ParticipantId = 3, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 12, 15), GameRoundRegNr = 2, GameRegPoints = 1000 }, + new GamePoint { GamePointId = 4, ParticipantId = 3, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 20, 15), GameRoundRegNr = 4, GameRegPoints = 400 } ); } diff --git a/GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.Designer.cs b/GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.Designer.cs new file mode 100644 index 0000000..e1e888f --- /dev/null +++ b/GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.Designer.cs @@ -0,0 +1,178 @@ +// +using System; +using GreadyPoang.DataLayer.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace GreadyPoang.DataLayer.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20250914064850_statusfieldmove")] + partial class statusfieldmove + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.8"); + + modelBuilder.Entity("GreadyPoang.EntityLayer.GamePoint", b => + { + b.Property("GamePointId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("GameDate") + .HasColumnType("TEXT"); + + b.Property("GameRegPoints") + .HasColumnType("INTEGER"); + + b.Property("GameRoundId") + .HasColumnType("INTEGER"); + + b.Property("GameRoundRegNr") + .HasColumnType("INTEGER"); + + b.Property("ParticipantId") + .HasColumnType("INTEGER"); + + b.HasKey("GamePointId"); + + b.ToTable("GamePoints"); + + b.HasData( + new + { + GamePointId = 1, + GameDate = new DateTime(2025, 10, 15, 20, 10, 15, 0, DateTimeKind.Unspecified), + GameRegPoints = 1050, + GameRoundId = 2, + GameRoundRegNr = 1, + ParticipantId = 1 + }, + new + { + GamePointId = 2, + GameDate = new DateTime(2025, 10, 15, 20, 15, 15, 0, DateTimeKind.Unspecified), + GameRegPoints = 350, + GameRoundId = 2, + GameRoundRegNr = 3, + ParticipantId = 1 + }, + new + { + GamePointId = 3, + GameDate = new DateTime(2025, 10, 15, 20, 12, 15, 0, DateTimeKind.Unspecified), + GameRegPoints = 1000, + GameRoundId = 2, + GameRoundRegNr = 2, + ParticipantId = 3 + }, + new + { + GamePointId = 4, + GameDate = new DateTime(2025, 10, 15, 20, 20, 15, 0, DateTimeKind.Unspecified), + GameRegPoints = 400, + GameRoundId = 2, + GameRoundRegNr = 4, + ParticipantId = 3 + }); + }); + + modelBuilder.Entity("GreadyPoang.EntityLayer.GameRound", b => + { + b.Property("GameRoundId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("GameRoundFinished") + .HasColumnType("TEXT"); + + b.Property("GameRoundStartDate") + .HasColumnType("TEXT"); + + b.Property("GameStatus") + .HasColumnType("INTEGER"); + + b.HasKey("GameRoundId"); + + b.ToTable("GameRounds"); + + b.HasData( + new + { + GameRoundId = 1, + GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + GameRoundStartDate = new DateTime(2025, 10, 15, 19, 10, 15, 0, DateTimeKind.Unspecified), + GameStatus = 0 + }, + new + { + GameRoundId = 2, + GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + GameRoundStartDate = new DateTime(2025, 9, 15, 19, 10, 15, 0, DateTimeKind.Unspecified), + GameStatus = 0 + }, + new + { + GameRoundId = 3, + GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + GameRoundStartDate = new DateTime(2025, 9, 20, 19, 10, 15, 0, DateTimeKind.Unspecified), + GameStatus = 0 + }); + }); + + modelBuilder.Entity("GreadyPoang.EntityLayer.Participant", b => + { + b.Property("ParticipantId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("ParticipantId"); + + b.ToTable("Participants"); + + b.HasData( + new + { + ParticipantId = 1, + Email = "John.Doe@gmail.com", + FirstName = "John", + LastName = "Doe" + }, + new + { + ParticipantId = 2, + Email = "jb@gmail.com", + FirstName = "Jane", + LastName = "Black" + }, + new + { + ParticipantId = 3, + Email = "mw@gmail.com", + FirstName = "Mary", + LastName = "White" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.cs b/GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.cs new file mode 100644 index 0000000..cfed5ae --- /dev/null +++ b/GreadyPoang.DataLayer/Migrations/20250914064850_statusfieldmove.cs @@ -0,0 +1,89 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace GreadyPoang.DataLayer.Migrations +{ + /// + public partial class statusfieldmove : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PointStatus", + table: "GamePoints"); + + migrationBuilder.AddColumn( + name: "GameStatus", + table: "GameRounds", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.UpdateData( + table: "GameRounds", + keyColumn: "GameRoundId", + keyValue: 1, + column: "GameStatus", + value: 0); + + migrationBuilder.UpdateData( + table: "GameRounds", + keyColumn: "GameRoundId", + keyValue: 2, + column: "GameStatus", + value: 0); + + migrationBuilder.UpdateData( + table: "GameRounds", + keyColumn: "GameRoundId", + keyValue: 3, + column: "GameStatus", + value: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "GameStatus", + table: "GameRounds"); + + migrationBuilder.AddColumn( + name: "PointStatus", + table: "GamePoints", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.UpdateData( + table: "GamePoints", + keyColumn: "GamePointId", + keyValue: 1, + column: "PointStatus", + value: 0); + + migrationBuilder.UpdateData( + table: "GamePoints", + keyColumn: "GamePointId", + keyValue: 2, + column: "PointStatus", + value: 0); + + migrationBuilder.UpdateData( + table: "GamePoints", + keyColumn: "GamePointId", + keyValue: 3, + column: "PointStatus", + value: 0); + + migrationBuilder.UpdateData( + table: "GamePoints", + keyColumn: "GamePointId", + keyValue: 4, + column: "PointStatus", + value: 0); + } + } +} diff --git a/GreadyPoang.DataLayer/Migrations/DataContextModelSnapshot.cs b/GreadyPoang.DataLayer/Migrations/DataContextModelSnapshot.cs index a0e2054..0eabf33 100644 --- a/GreadyPoang.DataLayer/Migrations/DataContextModelSnapshot.cs +++ b/GreadyPoang.DataLayer/Migrations/DataContextModelSnapshot.cs @@ -38,9 +38,6 @@ namespace GreadyPoang.DataLayer.Migrations b.Property("ParticipantId") .HasColumnType("INTEGER"); - b.Property("PointStatus") - .HasColumnType("INTEGER"); - b.HasKey("GamePointId"); b.ToTable("GamePoints"); @@ -53,8 +50,7 @@ namespace GreadyPoang.DataLayer.Migrations GameRegPoints = 1050, GameRoundId = 2, GameRoundRegNr = 1, - ParticipantId = 1, - PointStatus = 0 + ParticipantId = 1 }, new { @@ -63,8 +59,7 @@ namespace GreadyPoang.DataLayer.Migrations GameRegPoints = 350, GameRoundId = 2, GameRoundRegNr = 3, - ParticipantId = 1, - PointStatus = 0 + ParticipantId = 1 }, new { @@ -73,8 +68,7 @@ namespace GreadyPoang.DataLayer.Migrations GameRegPoints = 1000, GameRoundId = 2, GameRoundRegNr = 2, - ParticipantId = 3, - PointStatus = 0 + ParticipantId = 3 }, new { @@ -83,8 +77,7 @@ namespace GreadyPoang.DataLayer.Migrations GameRegPoints = 400, GameRoundId = 2, GameRoundRegNr = 4, - ParticipantId = 3, - PointStatus = 0 + ParticipantId = 3 }); }); @@ -100,6 +93,9 @@ namespace GreadyPoang.DataLayer.Migrations b.Property("GameRoundStartDate") .HasColumnType("TEXT"); + b.Property("GameStatus") + .HasColumnType("INTEGER"); + b.HasKey("GameRoundId"); b.ToTable("GameRounds"); @@ -109,19 +105,22 @@ namespace GreadyPoang.DataLayer.Migrations { GameRoundId = 1, GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - GameRoundStartDate = new DateTime(2025, 10, 15, 19, 10, 15, 0, DateTimeKind.Unspecified) + GameRoundStartDate = new DateTime(2025, 10, 15, 19, 10, 15, 0, DateTimeKind.Unspecified), + GameStatus = 0 }, new { GameRoundId = 2, GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - GameRoundStartDate = new DateTime(2025, 9, 15, 19, 10, 15, 0, DateTimeKind.Unspecified) + GameRoundStartDate = new DateTime(2025, 9, 15, 19, 10, 15, 0, DateTimeKind.Unspecified), + GameStatus = 0 }, new { GameRoundId = 3, GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - GameRoundStartDate = new DateTime(2025, 9, 20, 19, 10, 15, 0, DateTimeKind.Unspecified) + GameRoundStartDate = new DateTime(2025, 9, 20, 19, 10, 15, 0, DateTimeKind.Unspecified), + GameStatus = 0 }); }); diff --git a/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs b/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs index 4a60878..f1e638e 100644 --- a/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs +++ b/GreadyPoang.EntityLayer/EntityClasses/GameRound.cs @@ -44,13 +44,13 @@ public class GameRound : EntityBase } [Column("GameStatus")] - public GamePointStatus PointStatus + public GamePointStatus GameStatus { get { return _gameStatus; } set { _gameStatus = value; - RaisePropertyChanged(nameof(PointStatus)); + RaisePropertyChanged(nameof(GameStatus)); } } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs index 90c2c00..28f5b60 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs @@ -1,4 +1,5 @@ using Common.Library; +using GreadyPoang.DataLayer; using GreadyPoang.EntityLayer; using System.Collections.ObjectModel; using System.Diagnostics; @@ -13,22 +14,28 @@ public class RoundStartingViewModel : ViewModelBase } - public RoundStartingViewModel(IRepository repo, IRepository pointsRepo, IMethodSharingService sharingService) : base() + public RoundStartingViewModel( + IRepository repo, + IRepository pointsRepo, + IMethodSharingService sharingService, + ICombinedRepository combined) : base() { _Repository = repo; _pointsRepo = pointsRepo; _sharingService = sharingService; + _combined = combined; _roundElements = new ObservableCollection(); } #endregion private GameRound? _GameRoundObject = new(); - private ObservableCollection _GameRoundList = new(); + private ObservableCollection> _GameRoundList = new(); private ObservableCollection _ParticipantList = new(); private readonly IRepository? _Repository; private readonly IRepository _pointsRepo; private readonly IMethodSharingService _sharingService; + private readonly ICombinedRepository _combined; private Participant _selectedItem; private ObservableCollection _roundElements; @@ -43,6 +50,7 @@ public class RoundStartingViewModel : ViewModelBase } } + public Participant SelectedItem { get => _selectedItem; @@ -65,6 +73,7 @@ public class RoundStartingViewModel : ViewModelBase var GameRound = new GameRound { GameRoundStartDate = DateTime.Now, + GameStatus = GamePointStatus.New, GameRoundFinished = null }; var gameRoundId = _Repository?.Save(GameRound).GetAwaiter().GetResult(); @@ -81,8 +90,7 @@ public class RoundStartingViewModel : ViewModelBase GameRoundId = GameRoundObject?.GameRoundId ?? 0, GameDate = DateTime.Now, GameRoundRegNr = -1, - GameRegPoints = 0, - PointStatus = GamePointStatus.New + GameRegPoints = 0 }; var gamePointId = _pointsRepo.Save(GamePointStart).GetAwaiter().GetResult(); @@ -93,7 +101,7 @@ public class RoundStartingViewModel : ViewModelBase newElement.ParticipantName = item.LastNameFirstName; newElement.GameRoundRegNr = GamePointStart.GameRoundRegNr; newElement.GameRegPoints = GamePointStart.GameRegPoints; - newElement.Status = GamePointStart.PointStatus; + newElement.Status = GameRoundObject!.GameStatus; newElement.GameRoundStartDate = GameRoundObject?.GameRoundStartDate ?? DateTime.Now; newElement.GameRoundId = GamePointStart.GameRoundId; newElement.GamePointId = GamePointStart.GamePointId; @@ -114,7 +122,7 @@ public class RoundStartingViewModel : ViewModelBase } } - public ObservableCollection GameRoundList + public ObservableCollection> GameRoundList { get { return _GameRoundList; } set @@ -137,19 +145,31 @@ public class RoundStartingViewModel : ViewModelBase #region Get Method public ObservableCollection Get() { - if (_Repository != null) + //if (_Repository != null) + if (_combined != null) { - var gameRoundsTask = _Repository.Get(); - var gameRounds = gameRoundsTask is Task> task - ? task.GetAwaiter().GetResult() - : (IEnumerable)gameRoundsTask; - foreach (var gameRound in gameRounds) - { - if (!_GameRoundList.Any(p => p.GameRoundId == gameRound.GameRoundId)) - { - GameRoundList.Add(gameRound); - } - } + //var gameRoundsTask = _Repository.Get(); + //var gameRounds = gameRoundsTask is Task> task + // ? task.GetAwaiter().GetResult() + // : (IEnumerable)gameRoundsTask; + + var GameRoundSummary = _combined.roundBuilderElements(); + + var groupedRounds = GameRoundSummary + .GroupBy(r => r.GameRoundId) + .Select(g => g.ToList()) + .ToList(); + + //OBS ! Här måste jag skapa en ny lista varje gång för att UI ska uppdateras korrekt + + + //foreach (var gameRound in gameRounds) + //{ + // if (!_GameRoundList.Any(p => p.GameRoundId == gameRound.GameRoundId)) + // { + // GameRoundList.Add(gameRound); + // } + //} } return GameRoundList; } diff --git a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs b/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs index eaf8cc2..4af8860 100644 --- a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs +++ b/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs @@ -1,4 +1,5 @@ using Common.Library; +using GreadyPoang.DataLayer; using GreadyPoang.EntityLayer; using GreadyPoang.ViewModelLayer; using System.Windows.Input; @@ -11,7 +12,11 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel { } - public RoundStartingViewModelCommands(IRepository repo, IRepository pointsRepo, IMethodSharingService sharingService) : base(repo, pointsRepo, sharingService) + public RoundStartingViewModelCommands( + IRepository repo, + IRepository pointsRepo, + IMethodSharingService sharingService, + ICombinedRepository combined) : base(repo, pointsRepo, sharingService, combined) { }