mmo roles

This commit is contained in:
Spirtix 2024-04-07 15:40:37 +02:00
parent 2c30736193
commit 768affd3b2
5 changed files with 29 additions and 2 deletions

View File

@ -223,7 +223,9 @@ public class AuthenticationController : Controller {
if (session != null) { if (session != null) {
info.Authenticated = true; info.Authenticated = true;
info.DisplayName = session.Viking.Name; info.DisplayName = session.Viking.Name;
info.Role = Role.User; Role? role = session.Viking.MMORoles.FirstOrDefault()?.Role;
if (role != null)
info.Role = (Role)role;
} }
return Ok(info); return Ok(info);
} }

View File

@ -21,6 +21,7 @@ public class DBContext : DbContext {
public DbSet<GameDataPair> GameDataPairs { get; set; } = null!; public DbSet<GameDataPair> GameDataPairs { get; set; } = null!;
public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!; public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!;
public DbSet<ProfileAnswer> ProfileAnswers { get; set; } = null!; public DbSet<ProfileAnswer> ProfileAnswers { get; set; } = null!;
public DbSet<MMORole> MMORoles { get; set; } = null!;
public DbSet<Party> Parties { get; set; } = null!; public DbSet<Party> Parties { get; set; } = null!;
private readonly IOptions<ApiServerConfig> config; private readonly IOptions<ApiServerConfig> config;
@ -126,6 +127,9 @@ public class DBContext : DbContext {
builder.Entity<Viking>().HasMany(v => v.Parties) builder.Entity<Viking>().HasMany(v => v.Parties)
.WithOne(e => e.Viking); .WithOne(e => e.Viking);
builder.Entity<Viking>().HasMany(v => v.MMORoles)
.WithOne(e => e.Viking);
// Dragons // Dragons
builder.Entity<Dragon>().HasOne(d => d.Viking) builder.Entity<Dragon>().HasOne(d => d.Viking)
.WithMany(e => e.Dragons) .WithMany(e => e.Dragons)
@ -232,5 +236,10 @@ public class DBContext : DbContext {
builder.Entity<SceneData>().HasOne(i => i.Viking) builder.Entity<SceneData>().HasOne(i => i.Viking)
.WithMany(i => i.SceneData) .WithMany(i => i.SceneData)
.HasForeignKey(e => e.VikingId); .HasForeignKey(e => e.VikingId);
// MMO Roles
builder.Entity<MMORole>().HasOne(r => r.Viking)
.WithMany(e => e.MMORoles)
.HasForeignKey(e => e.VikingId);
} }
} }

15
src/Model/MMORole.cs Normal file
View File

@ -0,0 +1,15 @@
using sodoff.Schema;
using System.ComponentModel.DataAnnotations;
namespace sodoff.Model;
public class MMORole {
[Key]
public int Id { get; set; }
public int VikingId { get; set; }
public Role Role { get; set; }
public virtual Viking? Viking { get; set; }
}

View File

@ -36,6 +36,7 @@ public class Viking {
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!; public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
public virtual ICollection<SavedData> SavedData { get; set; } = null!; public virtual ICollection<SavedData> SavedData { get; set; } = null!;
public virtual ICollection<Party> Parties { get; set; } = null!; public virtual ICollection<Party> Parties { get; set; } = null!;
public virtual ICollection<MMORole> MMORoles { get; set; } = null!;
public virtual Dragon? SelectedDragon { get; set; } public virtual Dragon? SelectedDragon { get; set; }
public DateTime? CreationDate { get; set; } public DateTime? CreationDate { get; set; }

View File

@ -15,5 +15,5 @@ public class AuthenticationInfo {
[Serializable] [Serializable]
public enum Role { public enum Role {
User, Admin, Moderator User = 0, Admin = 1, Moderator = 2
} }