using Avalonia.Controls; using ReactiveUI; using FinancialManagement.Views; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FinancialManagement.Models; namespace FinancialManagement.ViewModels { public class CategoryTableViewModel : ReactiveObject { ShmelevTeamContext ppContext; List categores = new List(); private string categoryTitle; int indexCategory; public int IndexCategory { get => indexCategory; set => indexCategory = value; } public List Categores { get => categores; set => this.RaiseAndSetIfChanged(ref categores, value); } public Category ItemCategory { get => ppContext.Categories.First(it => it.CategoryId == categores[IndexCategory].CategoryId); } public string CategoryTitle { get => categoryTitle; set => categoryTitle = value; } public CategoryTableViewModel(User currentUser, ShmelevTeamContext ppContext) { this.ppContext = ppContext; List categoriesList = ppContext.Categories .Where( c => c.IdUser == currentUser.UserId) .ToList(); categoriesList.ForEach(it => { CategoryTableView item = new CategoryTableView(); item.CategoryId = it.CategoryId; item.CategoryTitle = it.Title; categores.Add(item); }); } } public class CategoryTableView { public int CategoryId { get; set; } public string CategoryTitle { get; set; } = null!; } }