Added EF and DB to the core, crude demo in the UI
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user