From 71b163e268ad7892a33b03460a8184e2e9658185 Mon Sep 17 00:00:00 2001 From: retr0volkov Date: Mon, 24 Aug 2026 14:11:12 +0300 Subject: [PATCH] New server models --- WinWARP.Core/Data/AppDbContext.cs | 8 +++ WinWARP.Core/Models/Entities/Server.cs | 11 +++- .../Models/Entities/StandaloneServer.cs | 15 +++++ WinWARP.Core/Models/Entities/Subscription.cs | 6 ++ .../Models/Entities/SubscriptionServer.cs | 18 ++++++ .../Wrappers/SubscriptionViewModel.cs | 57 ++++++++++++++++++- WinWARP.Ui/Views/SubsSettingsPage.xaml | 15 +---- 7 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 WinWARP.Core/Models/Entities/StandaloneServer.cs create mode 100644 WinWARP.Core/Models/Entities/SubscriptionServer.cs diff --git a/WinWARP.Core/Data/AppDbContext.cs b/WinWARP.Core/Data/AppDbContext.cs index 1c4b2b4..e6d20d8 100644 --- a/WinWARP.Core/Data/AppDbContext.cs +++ b/WinWARP.Core/Data/AppDbContext.cs @@ -10,6 +10,7 @@ public class AppDbContext : DbContext { public DbSet Subscriptions => Set(); + public AppDbContext(DbContextOptions options) : base(options) { @@ -21,5 +22,12 @@ public class AppDbContext : DbContext modelBuilder.Entity() .HasKey(s => s.Id); + + modelBuilder.Entity() + .HasMany(s => s.Servers) + .WithOne(s => s.Subscription) + .OnDelete(DeleteBehavior.SetNull); + + modelBuilder.Entity(); } } \ No newline at end of file diff --git a/WinWARP.Core/Models/Entities/Server.cs b/WinWARP.Core/Models/Entities/Server.cs index 5f94541..c619aea 100644 --- a/WinWARP.Core/Models/Entities/Server.cs +++ b/WinWARP.Core/Models/Entities/Server.cs @@ -5,7 +5,7 @@ using System.Text; namespace WinWARP.Core.Models.Entities; -public class Server +public abstract class Server { [Key] public int Id @@ -13,10 +13,15 @@ public class Server get; set; } - - public int SubscriptionId + [Required] + public string Name { get; set; } + [StringLength(100)] + public string CustomName + { + get; set; + } = string.Empty; } diff --git a/WinWARP.Core/Models/Entities/StandaloneServer.cs b/WinWARP.Core/Models/Entities/StandaloneServer.cs new file mode 100644 index 0000000..a9f0a8c --- /dev/null +++ b/WinWARP.Core/Models/Entities/StandaloneServer.cs @@ -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; + } +} diff --git a/WinWARP.Core/Models/Entities/Subscription.cs b/WinWARP.Core/Models/Entities/Subscription.cs index 4afb37f..4d92758 100644 --- a/WinWARP.Core/Models/Entities/Subscription.cs +++ b/WinWARP.Core/Models/Entities/Subscription.cs @@ -53,4 +53,10 @@ public class Subscription { get; set; } = string.Empty; + + + public List Servers + { + get; set; + } = []; } diff --git a/WinWARP.Core/Models/Entities/SubscriptionServer.cs b/WinWARP.Core/Models/Entities/SubscriptionServer.cs new file mode 100644 index 0000000..5150f91 --- /dev/null +++ b/WinWARP.Core/Models/Entities/SubscriptionServer.cs @@ -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; +} diff --git a/WinWARP.Core/ViewModels/Wrappers/SubscriptionViewModel.cs b/WinWARP.Core/ViewModels/Wrappers/SubscriptionViewModel.cs index 133e326..5d7328d 100644 --- a/WinWARP.Core/ViewModels/Wrappers/SubscriptionViewModel.cs +++ b/WinWARP.Core/ViewModels/Wrappers/SubscriptionViewModel.cs @@ -2,10 +2,65 @@ using System.Collections.Generic; using System.Text; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using WinWARP.Core.Models.Entities; 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; + } } diff --git a/WinWARP.Ui/Views/SubsSettingsPage.xaml b/WinWARP.Ui/Views/SubsSettingsPage.xaml index 245c62b..64fe484 100644 --- a/WinWARP.Ui/Views/SubsSettingsPage.xaml +++ b/WinWARP.Ui/Views/SubsSettingsPage.xaml @@ -10,19 +10,6 @@ mc:Ignorable="d"> - - - - - -