fix
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace MyOffice.Services.Dashboard.Domain;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Data.Models.Accounts;
|
||||
|
||||
public class DashboardData
|
||||
{
|
||||
public decimal IncomeLastWeek { get; set; }
|
||||
public decimal IncomePreviousWeek { get; set; }
|
||||
public decimal OutcomeLastWeek { get; set; }
|
||||
public decimal OutcomePreviousWeek { get; set; }
|
||||
public List<AccountSimple>? Rests { get; set; }
|
||||
public decimal? RestTotal => Rests?.Sum(x => x.Rest);
|
||||
public decimal? RestTotalPlus => Rests?.Where(x => x.Rest > 0).Sum(x => x.Rest);
|
||||
public decimal? RestTotalMinus => Rests?.Where(x => x.Rest < 0).Sum(x => x.Rest);
|
||||
}
|
||||
|
||||
/*public class DashboardRestData
|
||||
{
|
||||
public string AccountId { get; set; }
|
||||
public string AccountName { get; set; }
|
||||
public decimal Rest { get; set; }
|
||||
}*/
|
||||
Reference in New Issue
Block a user