Files
Pf2eDataScrapper/Pf2e/WPF/EntityViewer/ViewModel/EntityFormViewModel.cs
T

91 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Pf2e.Database;
using Pf2e.Database.Model.Base;
using Pf2e.Database.Model.Enum;
using Pf2e.Scrapper.WPF.EntityViewer.Stores;
using Pf2e.WPF.EntityViewer.Stores;
namespace Pf2e.WPF.EntityViewer.ViewModel;
internal class EntityFormViewModel : ViewModelBase
{
#region "Конструктор"
public IServiceProvider ServiceProvider { get; }
public Pf2eDbContext Context { get; }
public EntityListViewModel DbEntityListViewModel { get; }
public ViewViewModel ViewViewModel { get; }
public SelectedEntityTypeStore SelectedEntityTypeStore { get; }
public SelectedEntityStore SelectedEntityStore { get; }
public EntityFormViewModel(
IServiceProvider serviceProvider,
Pf2eDbContext context,
EntityListViewModel entityListViewModel,
ViewViewModel viewViewModel,
SelectedEntityTypeStore selectedEntityTypeStore,
SelectedEntityStore selectedEntityStore
)
{
ServiceProvider = serviceProvider;
Context = context;
DbEntityListViewModel = entityListViewModel;
ViewViewModel = viewViewModel;
SelectedEntityTypeStore = selectedEntityTypeStore;
SelectedEntityStore = selectedEntityStore;
Update();
SelectedEntityStore.SelectedEntityChanged += SelectedEntityStore_SelectedEntityChanged;
}
public void Update()
{
LoadEntityTypes();
}
#endregion
#region "Выбор типа"
public IEnumerable<EntityType> EntityTypes { get; set; } = [];
public EntityType? SelectedEntityType
{
get => SelectedEntityTypeStore.SelectedEntityType;
set
{
SelectedEntityTypeStore.SelectedEntityType = value;
OnPropertyChanged();
}
}
private void LoadEntityTypes()
{
EntityTypes = Context.Entities.Select(e => e.Type).Distinct().Order().ToList();
OnPropertyChanged(nameof(EntityTypes));
SelectedEntityTypeStore.SelectedEntityType = EntityTypes.Any() ? EntityTypes.First() : null;
}
#endregion
#region "Текущий элемент"
public string SelectedEntityDescription
{
get => SelectedEntityStore.SelectedEntity?.Description ?? "";
}
private void SelectedEntityStore_SelectedEntityChanged(Entity? obj)
{
OnPropertyChanged(nameof(SelectedEntityDescription));
}
#endregion
public string TestText => SelectedEntityType?.ToString() ?? "null";
}