PresenceApp/Presence.Desktop/ViewModels/MainWindowViewModel.cs
2024-12-05 02:32:04 +03:00

37 lines
1.0 KiB
C#

using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using data.RemoteData.RemoteDataBase;
using System;
namespace Presence.Desktop.ViewModels
{
public class MainWindowViewModel
{
public ObservableCollection<string> GroupNames { get; set; } = new ObservableCollection<string>();
private readonly IServiceProvider _services;
public MainWindowViewModel(IServiceProvider services)
{
_services = services;
GroupNames.Add("Group 1");
GroupNames.Add("Group 2");
GroupNames.Add("Group 3");
LoadGroupNames();
}
private void LoadGroupNames()
{
using (var context = _services.GetRequiredService<RemoteDatabaseContext>())
{
var groupNames = context.Groups.Select(g => g.Name).ToList();
foreach (var name in groupNames)
{
GroupNames.Add(name);
}
}
}
}
}