namespace MyOffice.Services.Dashboard; using MyOffice.Services.Dashboard.Domain; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Core.Extensions; using Data.Repositories.Account; using Data.Repositories.Currency; using MyOffice.Data.Models.Accounts; public class DashboardService { private readonly IAccountRepository _accountRepository; private readonly ICurrencyRateRepository _currencyRateRepository; public DashboardService( IAccountRepository accountRepository, ICurrencyRateRepository currencyRateRepository ) { _accountRepository = accountRepository; _currencyRateRepository = currencyRateRepository; } public DashboardData GetDashboardRestData(Guid userId) { /*var lastDaysStart = DateTime.UtcNow.AddMonths(-3).StartOfDay(); var lastDaysEnd = lastDaysStart.AddMonths(3).EndOfDay(); var previousDaysStart = lastDaysStart.AddMonths(-3).StartOfDay(); var previousDaysEnd = previousDaysStart.AddMonths(3).EndOfDay();*/ var rests = _accountRepository.GetRestAtDate(userId, DateTime.UtcNow); var result = new DashboardData { //IncomeLast = _accountRepository.GetPeriodIncome(userId, lastDaysStart, lastDaysEnd), //IncomePrevious = _accountRepository.GetPeriodIncome(userId, previousDaysStart, previousDaysEnd), //OutcomeLast = _accountRepository.GetPeriodOutcome(userId, lastDaysStart, lastDaysEnd), //OutcomePrevious = _accountRepository.GetPeriodOutcome(userId, previousDaysStart, previousDaysEnd), Balance = rests.Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)), BalanceDebit = rests.Where(x => x.Balance > 0).Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)), BalanceCredit = rests.Where(x => x.Balance < 0).Sum(x => x.Balance * (x.CurrencyRate * x.CurrencyQuantity)), }; return result; } }