diff --git a/LANCommander/Data/DatabaseContext.cs b/LANCommander/Data/DatabaseContext.cs index 7a80419..af8c23b 100644 --- a/LANCommander/Data/DatabaseContext.cs +++ b/LANCommander/Data/DatabaseContext.cs @@ -37,13 +37,13 @@ namespace LANCommander.Data builder.Entity() .HasMany(g => g.Archives) .WithOne(g => g.Game) - .IsRequired(true) + .IsRequired(false) .OnDelete(DeleteBehavior.Cascade); builder.Entity() .HasMany(g => g.Scripts) .WithOne(s => s.Game) - .IsRequired(true) + .IsRequired(false) .OnDelete(DeleteBehavior.Cascade); builder.Entity() @@ -104,6 +104,18 @@ namespace LANCommander.Data .WithOne(sl => sl.Server) .IsRequired(true) .OnDelete(DeleteBehavior.Cascade); + + builder.Entity() + .HasMany(r => r.Archives) + .WithOne(a => a.Redistributable) + .IsRequired(false) + .OnDelete(DeleteBehavior.Cascade); + + builder.Entity() + .HasMany(r => r.Scripts) + .WithOne(s => s.Redistributable) + .IsRequired(false) + .OnDelete(DeleteBehavior.Cascade); } public DbSet? Games { get; set; } @@ -123,5 +135,7 @@ namespace LANCommander.Data public DbSet? Servers { get; set; } public DbSet? ServerConsoles { get; set; } + + public DbSet? Redistributables { get; set; } } } \ No newline at end of file diff --git a/LANCommander/Data/Models/Archive.cs b/LANCommander/Data/Models/Archive.cs index 8bbe4c8..4bd275b 100644 --- a/LANCommander/Data/Models/Archive.cs +++ b/LANCommander/Data/Models/Archive.cs @@ -13,12 +13,18 @@ namespace LANCommander.Data.Models [Required] public string Version { get; set; } - public Guid GameId { get; set; } + public Guid? GameId { get; set; } [JsonIgnore] [ForeignKey(nameof(GameId))] [InverseProperty("Archives")] public virtual Game? Game { get; set; } + public Guid? RedistributableId { get; set; } + [JsonIgnore] + [ForeignKey(nameof(RedistributableId))] + [InverseProperty("Archives")] + public virtual Redistributable? Redistributable { get; set; } + [Display(Name = "Last Version")] public virtual Archive? LastVersion { get; set; } diff --git a/LANCommander/Data/Models/Redistributable.cs b/LANCommander/Data/Models/Redistributable.cs new file mode 100644 index 0000000..00094f9 --- /dev/null +++ b/LANCommander/Data/Models/Redistributable.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace LANCommander.Data.Models +{ + [Table("Redistributables")] + public class Redistributable : BaseModel + { + public string Name { get; set; } + public string? Description { get; set; } + public string? Notes { get; set; } + + public virtual ICollection? Archives { get; set; } + public virtual ICollection