Efter flytt av statusfält och åter byygt

This commit is contained in:
2025-09-14 12:03:16 +02:00
parent b4898660f2
commit 4e2b71af9f
8 changed files with 336 additions and 45 deletions

View File

@ -13,7 +13,7 @@ public class CombinedRepository : ICombinedRepository
} }
IEnumerable<RoundBuilderElement> ICombinedRepository.roundBuilderElements() public IEnumerable<RoundBuilderElement> roundBuilderElements()
{ {
var result = (from gameRound in _context.GameRounds var result = (from gameRound in _context.GameRounds
join gamePoint in _context.GamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId join gamePoint in _context.GamePoints on gameRound.GameRoundId equals gamePoint.GameRoundId
@ -24,11 +24,11 @@ public class CombinedRepository : ICombinedRepository
ParticipantId = participant.ParticipantId, ParticipantId = participant.ParticipantId,
ParticipantName = participant.LastNameFirstName, ParticipantName = participant.LastNameFirstName,
GamePointId = gamePoint.GamePointId, GamePointId = gamePoint.GamePointId,
GameRoundRegNr = gameRound.GameRoundId, GameRoundRegNr = gamePoint.GameRoundRegNr,
GameRegPoints = gamePoint.GameRegPoints, GameRegPoints = gamePoint.GameRegPoints,
GameRoundId = gameRound.GameRoundId, GameRoundId = gameRound.GameRoundId,
GameRoundStartDate = gameRound.GameRoundStartDate, GameRoundStartDate = gameRound.GameRoundStartDate,
Status = gamePoint.PointStatus Status = gameRound.GameStatus
}).ToList(); }).ToList();
return result; return result;

View File

@ -23,15 +23,15 @@ public class DataContext : DbContext
new Participant { ParticipantId = 3, FirstName = "Mary", LastName = "White", Email = "mw@gmail.com" } new Participant { ParticipantId = 3, FirstName = "Mary", LastName = "White", Email = "mw@gmail.com" }
); );
modelBuilder.Entity<GameRound>().HasData( modelBuilder.Entity<GameRound>().HasData(
new GameRound { GameRoundId = 1, GameRoundStartDate = new DateTime(2025, 10, 15, 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 }, 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 } new GameRound { GameRoundId = 3, GameRoundStartDate = new DateTime(2025, 09, 20, 19, 10, 15), GameRoundFinished = DateTime.MinValue, GameStatus = GamePointStatus.New }
); );
modelBuilder.Entity<GamePoint>().HasData( modelBuilder.Entity<GamePoint>().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 = 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, PointStatus = GamePointStatus.New }, 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, PointStatus = GamePointStatus.New }, 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, PointStatus = GamePointStatus.New } new GamePoint { GamePointId = 4, ParticipantId = 3, GameRoundId = 2, GameDate = new DateTime(2025, 10, 15, 20, 20, 15), GameRoundRegNr = 4, GameRegPoints = 400 }
); );
} }

View File

@ -0,0 +1,178 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("GamePointId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("GameDate")
.HasColumnType("TEXT");
b.Property<int>("GameRegPoints")
.HasColumnType("INTEGER");
b.Property<int>("GameRoundId")
.HasColumnType("INTEGER");
b.Property<int>("GameRoundRegNr")
.HasColumnType("INTEGER");
b.Property<int>("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<int>("GameRoundId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime?>("GameRoundFinished")
.HasColumnType("TEXT");
b.Property<DateTime>("GameRoundStartDate")
.HasColumnType("TEXT");
b.Property<int>("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<int>("ParticipantId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,89 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace GreadyPoang.DataLayer.Migrations
{
/// <inheritdoc />
public partial class statusfieldmove : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PointStatus",
table: "GamePoints");
migrationBuilder.AddColumn<int>(
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);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "GameStatus",
table: "GameRounds");
migrationBuilder.AddColumn<int>(
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);
}
}
}

View File

@ -38,9 +38,6 @@ namespace GreadyPoang.DataLayer.Migrations
b.Property<int>("ParticipantId") b.Property<int>("ParticipantId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("PointStatus")
.HasColumnType("INTEGER");
b.HasKey("GamePointId"); b.HasKey("GamePointId");
b.ToTable("GamePoints"); b.ToTable("GamePoints");
@ -53,8 +50,7 @@ namespace GreadyPoang.DataLayer.Migrations
GameRegPoints = 1050, GameRegPoints = 1050,
GameRoundId = 2, GameRoundId = 2,
GameRoundRegNr = 1, GameRoundRegNr = 1,
ParticipantId = 1, ParticipantId = 1
PointStatus = 0
}, },
new new
{ {
@ -63,8 +59,7 @@ namespace GreadyPoang.DataLayer.Migrations
GameRegPoints = 350, GameRegPoints = 350,
GameRoundId = 2, GameRoundId = 2,
GameRoundRegNr = 3, GameRoundRegNr = 3,
ParticipantId = 1, ParticipantId = 1
PointStatus = 0
}, },
new new
{ {
@ -73,8 +68,7 @@ namespace GreadyPoang.DataLayer.Migrations
GameRegPoints = 1000, GameRegPoints = 1000,
GameRoundId = 2, GameRoundId = 2,
GameRoundRegNr = 2, GameRoundRegNr = 2,
ParticipantId = 3, ParticipantId = 3
PointStatus = 0
}, },
new new
{ {
@ -83,8 +77,7 @@ namespace GreadyPoang.DataLayer.Migrations
GameRegPoints = 400, GameRegPoints = 400,
GameRoundId = 2, GameRoundId = 2,
GameRoundRegNr = 4, GameRoundRegNr = 4,
ParticipantId = 3, ParticipantId = 3
PointStatus = 0
}); });
}); });
@ -100,6 +93,9 @@ namespace GreadyPoang.DataLayer.Migrations
b.Property<DateTime>("GameRoundStartDate") b.Property<DateTime>("GameRoundStartDate")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("GameStatus")
.HasColumnType("INTEGER");
b.HasKey("GameRoundId"); b.HasKey("GameRoundId");
b.ToTable("GameRounds"); b.ToTable("GameRounds");
@ -109,19 +105,22 @@ namespace GreadyPoang.DataLayer.Migrations
{ {
GameRoundId = 1, GameRoundId = 1,
GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 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 new
{ {
GameRoundId = 2, GameRoundId = 2,
GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 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 new
{ {
GameRoundId = 3, GameRoundId = 3,
GameRoundFinished = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 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
}); });
}); });

View File

@ -44,13 +44,13 @@ public class GameRound : EntityBase
} }
[Column("GameStatus")] [Column("GameStatus")]
public GamePointStatus PointStatus public GamePointStatus GameStatus
{ {
get { return _gameStatus; } get { return _gameStatus; }
set set
{ {
_gameStatus = value; _gameStatus = value;
RaisePropertyChanged(nameof(PointStatus)); RaisePropertyChanged(nameof(GameStatus));
} }
} }

View File

@ -1,4 +1,5 @@
using Common.Library; using Common.Library;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@ -13,22 +14,28 @@ public class RoundStartingViewModel : ViewModelBase
} }
public RoundStartingViewModel(IRepository<GameRound> repo, IRepository<GamePoint> pointsRepo, IMethodSharingService<Participant> sharingService) : base() public RoundStartingViewModel(
IRepository<GameRound> repo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base()
{ {
_Repository = repo; _Repository = repo;
_pointsRepo = pointsRepo; _pointsRepo = pointsRepo;
_sharingService = sharingService; _sharingService = sharingService;
_combined = combined;
_roundElements = new ObservableCollection<RoundBuilderElement>(); _roundElements = new ObservableCollection<RoundBuilderElement>();
} }
#endregion #endregion
private GameRound? _GameRoundObject = new(); private GameRound? _GameRoundObject = new();
private ObservableCollection<GameRound> _GameRoundList = new(); private ObservableCollection<IEnumerable<GameRound>> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new(); private ObservableCollection<Participant> _ParticipantList = new();
private readonly IRepository<GameRound>? _Repository; private readonly IRepository<GameRound>? _Repository;
private readonly IRepository<GamePoint> _pointsRepo; private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService; private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined;
private Participant _selectedItem; private Participant _selectedItem;
private ObservableCollection<RoundBuilderElement> _roundElements; private ObservableCollection<RoundBuilderElement> _roundElements;
@ -43,6 +50,7 @@ public class RoundStartingViewModel : ViewModelBase
} }
} }
public Participant SelectedItem public Participant SelectedItem
{ {
get => _selectedItem; get => _selectedItem;
@ -65,6 +73,7 @@ public class RoundStartingViewModel : ViewModelBase
var GameRound = new GameRound var GameRound = new GameRound
{ {
GameRoundStartDate = DateTime.Now, GameRoundStartDate = DateTime.Now,
GameStatus = GamePointStatus.New,
GameRoundFinished = null GameRoundFinished = null
}; };
var gameRoundId = _Repository?.Save(GameRound).GetAwaiter().GetResult(); var gameRoundId = _Repository?.Save(GameRound).GetAwaiter().GetResult();
@ -81,8 +90,7 @@ public class RoundStartingViewModel : ViewModelBase
GameRoundId = GameRoundObject?.GameRoundId ?? 0, GameRoundId = GameRoundObject?.GameRoundId ?? 0,
GameDate = DateTime.Now, GameDate = DateTime.Now,
GameRoundRegNr = -1, GameRoundRegNr = -1,
GameRegPoints = 0, GameRegPoints = 0
PointStatus = GamePointStatus.New
}; };
var gamePointId = _pointsRepo.Save(GamePointStart).GetAwaiter().GetResult(); var gamePointId = _pointsRepo.Save(GamePointStart).GetAwaiter().GetResult();
@ -93,7 +101,7 @@ public class RoundStartingViewModel : ViewModelBase
newElement.ParticipantName = item.LastNameFirstName; newElement.ParticipantName = item.LastNameFirstName;
newElement.GameRoundRegNr = GamePointStart.GameRoundRegNr; newElement.GameRoundRegNr = GamePointStart.GameRoundRegNr;
newElement.GameRegPoints = GamePointStart.GameRegPoints; newElement.GameRegPoints = GamePointStart.GameRegPoints;
newElement.Status = GamePointStart.PointStatus; newElement.Status = GameRoundObject!.GameStatus;
newElement.GameRoundStartDate = GameRoundObject?.GameRoundStartDate ?? DateTime.Now; newElement.GameRoundStartDate = GameRoundObject?.GameRoundStartDate ?? DateTime.Now;
newElement.GameRoundId = GamePointStart.GameRoundId; newElement.GameRoundId = GamePointStart.GameRoundId;
newElement.GamePointId = GamePointStart.GamePointId; newElement.GamePointId = GamePointStart.GamePointId;
@ -114,7 +122,7 @@ public class RoundStartingViewModel : ViewModelBase
} }
} }
public ObservableCollection<GameRound> GameRoundList public ObservableCollection<IEnumerable<GameRound>> GameRoundList
{ {
get { return _GameRoundList; } get { return _GameRoundList; }
set set
@ -137,19 +145,31 @@ public class RoundStartingViewModel : ViewModelBase
#region Get Method #region Get Method
public ObservableCollection<GameRound> Get() public ObservableCollection<GameRound> Get()
{ {
if (_Repository != null) //if (_Repository != null)
if (_combined != null)
{ {
var gameRoundsTask = _Repository.Get(); //var gameRoundsTask = _Repository.Get();
var gameRounds = gameRoundsTask is Task<IEnumerable<GameRound>> task //var gameRounds = gameRoundsTask is Task<IEnumerable<GameRound>> task
? task.GetAwaiter().GetResult() // ? task.GetAwaiter().GetResult()
: (IEnumerable<GameRound>)gameRoundsTask; // : (IEnumerable<GameRound>)gameRoundsTask;
foreach (var gameRound in gameRounds)
{ var GameRoundSummary = _combined.roundBuilderElements();
if (!_GameRoundList.Any(p => p.GameRoundId == gameRound.GameRoundId))
{ var groupedRounds = GameRoundSummary
GameRoundList.Add(gameRound); .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; return GameRoundList;
} }

View File

@ -1,4 +1,5 @@
using Common.Library; using Common.Library;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.ViewModelLayer; using GreadyPoang.ViewModelLayer;
using System.Windows.Input; using System.Windows.Input;
@ -11,7 +12,11 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
{ {
} }
public RoundStartingViewModelCommands(IRepository<GameRound> repo, IRepository<GamePoint> pointsRepo, IMethodSharingService<Participant> sharingService) : base(repo, pointsRepo, sharingService) public RoundStartingViewModelCommands(
IRepository<GameRound> repo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined) : base(repo, pointsRepo, sharingService, combined)
{ {
} }