Files
GreadyPoang/GreadyPoang.DataLayer/Database/DataContext.cs

40 lines
2.3 KiB
C#

using GreadyPoang.EntityLayer;
using Microsoft.EntityFrameworkCore;
namespace GreadyPoang.DataLayer.Database;
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options) : base(options)
{
}
//public DbSet<User> Users => Set<User>();
public DbSet<Participant> Participants { get; set; }
public DbSet<GamePoint> GamePoints { get; set; }
public DbSet<GameRound> GameRounds { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Participant>().HasData(
new Participant { ParticipantId = 1, FirstName = "John", LastName = "Doe", Email = "John.Doe@gmail.com" },
new Participant { ParticipantId = 2, FirstName = "Jane", LastName = "Black", Email = "jb@gmail.com" },
new Participant { ParticipantId = 3, FirstName = "Mary", LastName = "White", Email = "mw@gmail.com" }
);
modelBuilder.Entity<GameRound>().HasData(
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<GamePoint>().HasData(
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 }
);
}
}