New server models
This commit is contained in:
@@ -10,6 +10,7 @@ public class AppDbContext : DbContext
|
|||||||
{
|
{
|
||||||
public DbSet<Subscription> Subscriptions => Set<Subscription>();
|
public DbSet<Subscription> Subscriptions => Set<Subscription>();
|
||||||
|
|
||||||
|
|
||||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -21,5 +22,12 @@ public class AppDbContext : DbContext
|
|||||||
|
|
||||||
modelBuilder.Entity<Subscription>()
|
modelBuilder.Entity<Subscription>()
|
||||||
.HasKey(s => s.Id);
|
.HasKey(s => s.Id);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Subscription>()
|
||||||
|
.HasMany(s => s.Servers)
|
||||||
|
.WithOne(s => s.Subscription)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
|
modelBuilder.Entity<StandaloneServer>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace WinWARP.Core.Models.Entities;
|
namespace WinWARP.Core.Models.Entities;
|
||||||
|
|
||||||
public class Server
|
public abstract class Server
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public int Id
|
public int Id
|
||||||
@@ -13,10 +13,15 @@ public class Server
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Required]
|
||||||
public int SubscriptionId
|
public string Name
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StringLength(100)]
|
||||||
|
public string CustomName
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
} = string.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace WinWARP.Core.Models.Entities;
|
||||||
|
|
||||||
|
public class StandaloneServer : Server
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string FilePath
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,4 +53,10 @@ public class Subscription
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
} = string.Empty;
|
} = string.Empty;
|
||||||
|
|
||||||
|
|
||||||
|
public List<SubscriptionServer> Servers
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
} = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace WinWARP.Core.Models.Entities;
|
||||||
|
|
||||||
|
public class SubscriptionServer : Server
|
||||||
|
{
|
||||||
|
public Subscription Subscription
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Region
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
} = string.Empty;
|
||||||
|
}
|
||||||
@@ -2,10 +2,65 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using WinWARP.Core.Models.Entities;
|
||||||
|
|
||||||
namespace WinWARP.Core.ViewModels.Wrappers;
|
namespace WinWARP.Core.ViewModels.Wrappers;
|
||||||
|
|
||||||
public partial class SubscriptionViewModel : ObservableObject
|
public partial class SubscriptionViewModel : ObservableValidator
|
||||||
{
|
{
|
||||||
|
private readonly Subscription _subscription;
|
||||||
|
|
||||||
|
public SubscriptionViewModel(Subscription subscription)
|
||||||
|
{
|
||||||
|
_subscription = subscription;
|
||||||
|
Link = subscription.Link;
|
||||||
|
WebPage = subscription.WebPage;
|
||||||
|
DefaultTitle = subscription.DefaultTitle;
|
||||||
|
DefaultUpdateInterval = subscription.DefaultUpdateInterval;
|
||||||
|
Title = subscription.Title;
|
||||||
|
UpdateInterval = subscription.UpdateInterval;
|
||||||
|
SupportURL = subscription.SupportURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial string Link { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial string WebPage { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial string DefaultTitle { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial int DefaultUpdateInterval { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial string Title { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial int UpdateInterval { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial string SupportURL { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
|
||||||
|
public partial bool IsDirty { get; private set; }
|
||||||
|
|
||||||
|
[RelayCommand(CanExecute = nameof(CanSave))]
|
||||||
|
private void Save()
|
||||||
|
{
|
||||||
|
ValidateAllProperties();
|
||||||
|
|
||||||
|
if (!HasErrors)
|
||||||
|
{
|
||||||
|
// Save logic here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanSave()
|
||||||
|
{
|
||||||
|
return IsDirty && !HasErrors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,19 +10,6 @@
|
|||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="Auto" />
|
|
||||||
<RowDefinition Height="Auto" />
|
|
||||||
<RowDefinition Height="*" />
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
<Button Grid.Row="0" Command="{x:Bind ViewModel.AddSubscriptionCommand}" Content="Add Subscription" />
|
|
||||||
<TextBox Grid.Row="1" Text="{x:Bind ViewModel.NewSubscriptionLink, Mode=TwoWay}" />
|
|
||||||
<ListBox Grid.Row="2" ItemsSource="{x:Bind ViewModel.Subscriptions}">
|
|
||||||
<ListBox.ItemTemplate>
|
|
||||||
<DataTemplate x:DataType="m:Subscription">
|
|
||||||
<TextBlock Text="{x:Bind Link}" />
|
|
||||||
</DataTemplate>
|
|
||||||
</ListBox.ItemTemplate>
|
|
||||||
</ListBox>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
Reference in New Issue
Block a user