diff --git a/LANCommander/Components/TransferInput.razor b/LANCommander/Components/TransferInput.razor new file mode 100644 index 0000000..4a7b302 --- /dev/null +++ b/LANCommander/Components/TransferInput.razor @@ -0,0 +1,37 @@ +@typeparam TItem where TItem : BaseModel + + + +@code { + [Parameter] public string LeftTitle { get; set; } = ""; + [Parameter] public string RightTitle { get; set; } = ""; + [Parameter] public Func TitleSelector { get; set; } + [Parameter] public IEnumerable DataSource { get; set; } + [Parameter] public ICollection Values { get; set; } = new List(); + [Parameter] public EventCallback> ValuesChanged { get; set; } + + IEnumerable TransferItems { get; set; } = new List(); + List TargetKeys { get; set; } = new List(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + TransferItems = DataSource.Select(i => new TransferItem() + { + Key = i.Id.ToString(), + Title = TitleSelector.Invoke(i) + }); + + TargetKeys = Values.Select(i => i.Id.ToString()).ToList(); + } + } + + async Task OnChange(TransferChangeArgs e) + { + Values = DataSource.Where(i => e.TargetKeys.Contains(i.Id.ToString())).ToList(); + + if (ValuesChanged.HasDelegate) + await ValuesChanged.InvokeAsync(Values); + } +} \ No newline at end of file diff --git a/LANCommander/Data/DatabaseContext.cs b/LANCommander/Data/DatabaseContext.cs index af8c23b..1026939 100644 --- a/LANCommander/Data/DatabaseContext.cs +++ b/LANCommander/Data/DatabaseContext.cs @@ -81,6 +81,15 @@ namespace LANCommander.Data g => g.HasOne().WithMany().HasForeignKey("GameId") ); + builder.Entity() + .HasMany(g => g.Redistributables) + .WithMany(r => r.Games) + .UsingEntity>( + "GameRedistributable", + gr => gr.HasOne().WithMany().HasForeignKey("RedistributableId"), + gr => gr.HasOne().WithMany().HasForeignKey("GameId") + ); + builder.Entity() .HasMany(u => u.GameSaves) .WithOne(gs => gs.User) diff --git a/LANCommander/Data/Models/Game.cs b/LANCommander/Data/Models/Game.cs index c4e3987..325d059 100644 --- a/LANCommander/Data/Models/Game.cs +++ b/LANCommander/Data/Models/Game.cs @@ -34,6 +34,7 @@ namespace LANCommander.Data.Models public virtual ICollection? GameSaves { get; set; } public virtual ICollection? SavePaths { get; set; } public virtual ICollection? Servers { get; set; } + public virtual ICollection? Redistributables { get; set; } public string? ValidKeyRegex { get; set; } public virtual ICollection? Keys { get; set; } diff --git a/LANCommander/Data/Models/Redistributable.cs b/LANCommander/Data/Models/Redistributable.cs index 00094f9..9049c8d 100644 --- a/LANCommander/Data/Models/Redistributable.cs +++ b/LANCommander/Data/Models/Redistributable.cs @@ -11,5 +11,6 @@ namespace LANCommander.Data.Models public virtual ICollection? Archives { get; set; } public virtual ICollection