56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
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;
|
|
|
|
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.AddDays(-7).StartOfDay();
|
|
var lastDaysEnd = lastDaysStart.AddDays(7).EndOfDay();
|
|
var previousDaysStart = lastDaysStart.AddDays(-7).StartOfDay();
|
|
var previousDaysEnd = previousDaysStart.AddDays(7).EndOfDay();
|
|
var rests = _accountRepository.GetRestAtDate(userId, DateTime.UtcNow);
|
|
|
|
var currencyIds = rests
|
|
.Select(x => x.CurrencyId)
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
var lastrates = _currencyRateRepository.GetLastRates(currencyIds);
|
|
foreach (var rest in rests)
|
|
{
|
|
//var rate = lastrates.FirstOrDefault(x => x.CurrencyId == rest.CurrencyId)
|
|
}
|
|
|
|
return new DashboardData
|
|
{
|
|
IncomeLastWeek = _accountRepository.GetPeriodIncome(userId, lastDaysStart, lastDaysEnd),
|
|
IncomePreviousWeek = _accountRepository.GetPeriodIncome(userId, previousDaysStart, previousDaysEnd),
|
|
OutcomeLastWeek = _accountRepository.GetPeriodOutcome(userId, lastDaysStart, lastDaysEnd),
|
|
OutcomePreviousWeek = _accountRepository.GetPeriodOutcome(userId, previousDaysStart, previousDaysEnd),
|
|
Rests = rests,
|
|
};
|
|
}
|
|
}
|