fix
This commit is contained in:
@@ -83,12 +83,26 @@ public class CurrencyService
|
||||
|
||||
exists.Name = currency.Name;
|
||||
exists.ShortName = currency.ShortName;
|
||||
exists.IsPrimary = currency.IsPrimary;
|
||||
|
||||
if (!_currencyRepository.Update(exists))
|
||||
{
|
||||
return result.Set(CurrencyEditStatus.failed);
|
||||
}
|
||||
|
||||
if (exists.IsPrimary)
|
||||
{
|
||||
var primaries = _currencyRepository.GetPrimaries(userId);
|
||||
foreach (var primary in primaries)
|
||||
{
|
||||
if (primary.Id != exists.Id)
|
||||
{
|
||||
primary.IsPrimary = false;
|
||||
_currencyRepository.Update(primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ public class CurrencyEdit
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string ShortName { get; set; } = null!;
|
||||
public bool IsPrimary { get; set; }
|
||||
}
|
||||
@@ -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; }
|
||||
}*/
|
||||
@@ -11,8 +11,4 @@
|
||||
<ProjectReference Include="..\MyOffice.Data.Repositories\MyOffice.Data.Repositories.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Dashboard\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user