123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using Avalonia.Media;
- using FinancialManagement.Models;
- using FinancialManagement.Views;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FinancialManagement.ViewModels
- {
- public class FinanceDataAccountViewModel : ReactiveObject
- {
- FinanceTableViewModel financeTableViewModel;
- ShmelevTeamContext ppContext;
- List<Finance> finances;
- Finance? financeItem;
- int userIdLoad;
- string titleFinance;
- decimal priceFinance;
- string categoryFinTitle;
- string categoryTitle;
- int categoryIdFinance;
- int categoryFinIdFinance;
- int startsIndex = 0;
- int startsIndex1 = 0;
- string message = "";
- private IBrush colorMessage;
- public int UserIdLoad { get => userIdLoad; set => this.RaiseAndSetIfChanged(ref userIdLoad, value); }
- public FinanceTableViewModel FinanceTableVM { get => financeTableViewModel; set => financeTableViewModel = value; }
- public List<Finance> Finance { get => finances; set => this.RaiseAndSetIfChanged(ref finances, value); }
- public IBrush ColorMessage { get => colorMessage; set => this.RaiseAndSetIfChanged(ref colorMessage, value); }
- public Finance? FinanceItem { get => financeItem; set => financeItem = value; }
- public string TitleFinance { get => titleFinance; set => this.RaiseAndSetIfChanged(ref titleFinance, value); }
- public decimal PriceFinance { get => priceFinance; set => this.RaiseAndSetIfChanged(ref priceFinance, value); }
- public int CategoryIdFinance { get => categoryIdFinance; set => this.RaiseAndSetIfChanged(ref categoryIdFinance, value); }
- public int StartsIndex { get => startsIndex; set => this.RaiseAndSetIfChanged(ref startsIndex, value); }
- public int StartsIndex1 { get => startsIndex1; set => this.RaiseAndSetIfChanged(ref startsIndex1, value); }
- public string CategoryFinTitle { get => categoryFinTitle; set => this.RaiseAndSetIfChanged(ref categoryFinTitle, value); }
- public string CategoryTitle { get => categoryTitle; set => this.RaiseAndSetIfChanged(ref categoryTitle, value); }
- public int CategoryFinIdFinance { get => categoryFinIdFinance; set => this.RaiseAndSetIfChanged(ref categoryFinIdFinance, value); }
- public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); }
- public List<string> TurnoverList
- {
- get
- {
- List<string> list_turnoverList = new List<string>();
- list_turnoverList.AddRange(ppContext.Categoriesfinances.Select(x => x.FinTitle).ToList());
- return list_turnoverList;
- }
- }
- public List<string> CategoriesList
- {
- get
- {
- List<string> list_categories = new List<string>();
- list_categories.AddRange(ppContext.Categories.Where(x => x.IdUser == UserIdLoad).Select(x => x.Title).ToList());
- return list_categories;
- }
- }
- public int LoadCategoryFinId(string categoryFinId)
- {
- int financeCategory1 = -1;
- using (ShmelevTeamContext ppContext = new ShmelevTeamContext())
- {
- var financeCategory = ppContext.Categoriesfinances
- .Where(f => f.FinTitle == categoryFinId)
- .Select(f => f.IdCatFin)
- .FirstOrDefault();
- financeCategory1 = financeCategory;
- }
- return financeCategory1;
- }
- 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 FinanceDataAccountViewModel()
- {
- financeItem = new Finance();
- }
- public FinanceDataAccountViewModel(ShmelevTeamContext ppContext, User currentUser)
- {
- UserIdLoad = currentUser.UserId;
- this.ppContext = ppContext;
- financeItem = new Finance();
- }
- public FinanceDataAccountViewModel(Finance financeItem, User currentUser, ShmelevTeamContext ppContext)
- {
- UserIdLoad = currentUser.UserId;
- this.ppContext = ppContext;
- FinanceTableVM = new FinanceTableViewModel(currentUser, ppContext);
- CategoryFinTitle = FinanceTableVM.LoadCategoryFinTitle(financeItem.CategoryFinId);
- CategoryTitle = FinanceTableVM.LoadCategoryTitle(financeItem.CategoryId);
- this.financeItem = financeItem;
- titleFinance = financeItem.Title;
- priceFinance = financeItem.Price;
- categoryIdFinance = LoadCategoryId(CategoryTitle);
- categoryFinIdFinance = LoadCategoryFinId(CategoryFinTitle);
- StartsIndex = categoryFinIdFinance-1;
- StartsIndex1 = categoryIdFinance - 1;
- }
- public Dictionary<string, Finance> GetDataFinance(User currentUser)
- {
- UserIdLoad = currentUser.UserId;
- if (string.IsNullOrEmpty(TitleFinance) || PriceFinance == null || CategoryIdFinance == null || CategoryFinIdFinance == null)
- return new Dictionary<string, Finance> { { "1", null } };
- else if (TitleFinance.Length > 50) return new Dictionary<string, Finance> { { "2", null } };
- else
- {
- FinanceItem.Title = TitleFinance;
- FinanceItem.UserId = currentUser.UserId;
- FinanceItem.Price = priceFinance;
- FinanceItem.CategoryId = LoadCategoryId(CategoryTitle);
- FinanceItem.CategoryFinId = LoadCategoryFinId(CategoryFinTitle);
- return new Dictionary<string, Finance> { { "4", FinanceItem } }; ;
- }
- }
-
-
- }
- }
|