12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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 Avalonia.Media;
- using FinancialManagement.Models;
- namespace FinancialManagement.ViewModels
- {
- public class CategoryDataAccountViewModel : ReactiveObject
- {
- ShmelevTeamContext ppContext;
- List<Category> categores;
- Category? categoryItem;
- int userIdLoad;
- string categoryTitle;
- int categoryIdFinance;
- string message = "";
- private IBrush colorMessage;
- public int UserIdLoad { get => userIdLoad; set => this.RaiseAndSetIfChanged(ref userIdLoad, value); }
- public int CategoryIdFinance { get => categoryIdFinance; set => this.RaiseAndSetIfChanged(ref categoryIdFinance, value); }
- public List<Category> Category { get => categores; set => this.RaiseAndSetIfChanged(ref categores, value); }
- public IBrush ColorMessage { get => colorMessage; set => this.RaiseAndSetIfChanged(ref colorMessage, value); }
- public Category? CategoryItem { get => categoryItem; set => categoryItem = value; }
- public string CategoryTitle { get => categoryTitle; set => this.RaiseAndSetIfChanged(ref categoryTitle, value); }
- public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); }
- public int LoadCategoryId(string categoryId)
- {
- int categoryId1 = -1;
- using (ShmelevTeamContext ppContext = new ShmelevTeamContext())
- {
- var financeCategory = ppContext.Categories
- .Where(f => f.Title == categoryId)
- .Select(f => f.CategoryId)
- .FirstOrDefault();
- categoryId1 = financeCategory;
- }
- return categoryId1;
- }
- public CategoryDataAccountViewModel()
- {
- categoryItem = new Category();
- }
- public CategoryDataAccountViewModel(ShmelevTeamContext ppContext, User currentUser)
- {
- UserIdLoad = currentUser.UserId;
- this.ppContext = ppContext;
- categoryItem = new Category();
- }
- public CategoryDataAccountViewModel(Category catItem, User currentUser, ShmelevTeamContext ppContext)
- {
- UserIdLoad = currentUser.UserId;
- this.ppContext = ppContext;
- this.categoryItem = catItem;
- categoryIdFinance = catItem.CategoryId;
- categoryTitle = catItem.Title;
- }
- public Dictionary<string, Category> GetDataFinance(User currentUser)
- {
- UserIdLoad = currentUser.UserId;
- if (CategoryIdFinance == null)
- return new Dictionary<string, Category> { { "1", null } };
- else if (CategoryTitle.Length > 50) return new Dictionary<string, Category> { { "2", null } };
- else
- {
- CategoryItem.IdUser = currentUser.UserId;
- CategoryItem.CategoryId = LoadCategoryId(CategoryTitle);
- CategoryItem.Title = CategoryTitle;
- return new Dictionary<string, Category> { { "4", CategoryItem } }; ;
- }
- }
- }
- }
|