Player models and interfaces
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace EstusShots.Server.Models
|
||||
@@ -20,5 +22,7 @@ namespace EstusShots.Server.Models
|
||||
public Guid SeasonId { get; set; }
|
||||
|
||||
public Season Season { get; set; } = default!;
|
||||
|
||||
public ICollection<EpisodePlayers> EpisodePlayers { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
13
EstusShots.Server/Models/EpisodePlayers.cs
Normal file
13
EstusShots.Server/Models/EpisodePlayers.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace EstusShots.Server.Models
|
||||
{
|
||||
public class EpisodePlayers
|
||||
{
|
||||
public Guid EpisodeId { get; set; } = default!;
|
||||
public Episode Episode { get; set; } = default!;
|
||||
|
||||
public Guid PlayerId { get; set; } = default!;
|
||||
public Player Player { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
23
EstusShots.Server/Models/Player.cs
Normal file
23
EstusShots.Server/Models/Player.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace EstusShots.Server.Models
|
||||
{
|
||||
public class Player
|
||||
{
|
||||
public Guid PlayerId { get; set; }
|
||||
|
||||
[MaxLength(4)] public string? HexId { get; set; }
|
||||
|
||||
[MaxLength(30)] public string Name { get; set; } = default!;
|
||||
|
||||
[MaxLength(30)] public string Alias { get; set; } = default!;
|
||||
|
||||
public bool Anonymous { get; set; }
|
||||
|
||||
public string DisplayName => Anonymous ? Alias : Name;
|
||||
|
||||
public ICollection<EpisodePlayers> EpisodePlayers { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,25 @@ namespace EstusShots.Server.Services
|
||||
|
||||
public DbSet<Season> Seasons { get; set; } = default!;
|
||||
public DbSet<Episode> Episodes { get; set; } = default!;
|
||||
public DbSet<Player> Players { get; set; } = default!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Season>().ToTable(nameof(Season));
|
||||
modelBuilder.Entity<Episode>().ToTable(nameof(Episode));
|
||||
|
||||
modelBuilder.Entity<EpisodePlayers>()
|
||||
.HasKey(t => new {t.EpisodeId, t.PlayerId});
|
||||
|
||||
modelBuilder.Entity<EpisodePlayers>()
|
||||
.HasOne(pt => pt.Episode)
|
||||
.WithMany(p => p.EpisodePlayers)
|
||||
.HasForeignKey(pt => pt.EpisodeId);
|
||||
|
||||
modelBuilder.Entity<EpisodePlayers>()
|
||||
.HasOne(pt => pt.Player)
|
||||
.WithMany(t => t.EpisodePlayers)
|
||||
.HasForeignKey(pt => pt.PlayerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user