Added EF and DB to the core, crude demo in the UI
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WinWARP.Core.Models.Entities;
|
||||
|
||||
namespace WinWARP.Core.Data;
|
||||
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<Subscription> Subscriptions => Set<Subscription>();
|
||||
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Subscription>()
|
||||
.HasKey(s => s.Id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace WinWARP.Core.Models.Entities;
|
||||
|
||||
public class Server
|
||||
{
|
||||
[Key]
|
||||
public int Id
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
||||
public int SubscriptionId
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace WinWARP.Core.Models.Entities;
|
||||
|
||||
public class Subscription
|
||||
{
|
||||
[Key]
|
||||
public int Id
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
[Required]
|
||||
[StringLength(100)]
|
||||
public string Link
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
[StringLength(100)]
|
||||
public string WebPage
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
[StringLength(100)]
|
||||
public string DefaultTitle
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public int DefaultUpdateInterval
|
||||
{
|
||||
get; set;
|
||||
} = 1;
|
||||
|
||||
[StringLength(100)]
|
||||
public string Title
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public int UpdateInterval
|
||||
{
|
||||
get; set;
|
||||
} = 1;
|
||||
|
||||
[StringLength(100)]
|
||||
public string SupportURL
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WinWARP.Core.Data;
|
||||
using WinWARP.Core.Models.Entities;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Core.Services.Implementations;
|
||||
|
||||
public class SubscriptionDbService : ISubscriptionDbService
|
||||
{
|
||||
private IDbContextFactory<AppDbContext> _dbContextFactory;
|
||||
|
||||
public SubscriptionDbService(IDbContextFactory<AppDbContext> dbContextFactory)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
public async Task<List<Subscription>> GetSubscriptionsAsync()
|
||||
{
|
||||
using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await dbContext.Subscriptions.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task AddSubscriptionAsync(Subscription subscription)
|
||||
{
|
||||
using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
dbContext.Subscriptions.Add(subscription);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WinWARP.Core.Services;
|
||||
namespace WinWARP.Core.Services.Interfaces;
|
||||
|
||||
public interface ILocalizationService
|
||||
{
|
||||
+1
-1
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace WinWARP.Core.Services;
|
||||
namespace WinWARP.Core.Services.Interfaces;
|
||||
|
||||
public interface INavigationService
|
||||
{
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using WinWARP.Core.Models.Entities;
|
||||
|
||||
namespace WinWARP.Core.Services.Interfaces;
|
||||
|
||||
public interface ISubscriptionDbService
|
||||
{
|
||||
public Task<List<Subscription>> GetSubscriptionsAsync();
|
||||
public Task AddSubscriptionAsync(Subscription subscription);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using WinWARP.Core.Services;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Core.ViewModels;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using WinWARP.Core.Services;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Core.ViewModels;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using WinWARP.Core.Services;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Core.ViewModels;
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using WinWARP.Core.Models.Entities;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Core.ViewModels;
|
||||
|
||||
public partial class SubsSettingsViewModel(ISubscriptionDbService dbService) : ObservableObject
|
||||
{
|
||||
private readonly ISubscriptionDbService _dbService = dbService;
|
||||
|
||||
public ObservableCollection<Subscription> Subscriptions { get; } = [];
|
||||
|
||||
public async Task LoadSubscriptionsAsync()
|
||||
{
|
||||
Subscriptions.Clear();
|
||||
var data = await _dbService.GetSubscriptionsAsync();
|
||||
foreach (var subscription in data)
|
||||
{
|
||||
Subscriptions.Add(subscription);
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(AddSubscriptionCommand))]
|
||||
public partial string NewSubscriptionLink { get; set; } = string.Empty;
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanAddSubscription))]
|
||||
public async Task AddSubscriptionAsync()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(NewSubscriptionLink))
|
||||
{
|
||||
var subscription = new Subscription
|
||||
{
|
||||
Link = NewSubscriptionLink,
|
||||
Title = "New Subscription",
|
||||
UpdateInterval = 60 // Default update interval
|
||||
};
|
||||
await _dbService.AddSubscriptionAsync(subscription);
|
||||
Subscriptions.Add(subscription);
|
||||
NewSubscriptionLink = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanAddSubscription()
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(NewSubscriptionLink);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace WinWARP.Core.ViewModels;
|
||||
namespace WinWARP.Core.ViewModels.Wrappers;
|
||||
|
||||
public class SubsSettingsViewModel : ObservableObject
|
||||
public partial class SubscriptionViewModel : ObservableObject
|
||||
{
|
||||
|
||||
}
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SingBoxLib" Version="1.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user