fix
This commit is contained in:
@@ -163,4 +163,22 @@ public class CurrencyService
|
||||
|
||||
return result.Set(_mapper.Map<CurrencyRateDto>(rate));
|
||||
}
|
||||
|
||||
public Exec<CurrencyDto, GeneralExecStatus> Remove(Guid userId, Guid id)
|
||||
{
|
||||
var result = new Exec<CurrencyDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var currency = _currencyRepository.Get(userId, id);
|
||||
if (currency == null)
|
||||
{
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
if (!_currencyRepository.Remove(currency))
|
||||
{
|
||||
return result.Set(GeneralExecStatus.failure);
|
||||
}
|
||||
|
||||
return result.Set(_mapper.Map<CurrencyDto>(currency));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using Core.Extensions;
|
||||
using Data.Repositories.Account;
|
||||
using Data.Repositories.Currency;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class DashboardService
|
||||
{
|
||||
@@ -70,13 +71,44 @@ public class DashboardService
|
||||
? _accountRepository.GetIncomeByCategory(userId, category.Value, from.ToUtc(), to.ToUtc())
|
||||
: _accountRepository.GetIncomeByCategories(userId, from.ToUtc(), to.ToUtc());
|
||||
|
||||
data = data
|
||||
.Where(x => x.Amount != 0)
|
||||
.ToList();
|
||||
|
||||
var currencies = data
|
||||
.Where(x => x.Amount != 0)
|
||||
.Select(x => x.CurrencyId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var rates = _currencyRateRepository
|
||||
.GetLastRates(userId, currencies, to.ToUtc())
|
||||
.ToDictionary(x => x.Key, x => x.Value.Rate * x.Value.Quantity);
|
||||
|
||||
return new DashboardIncomeData
|
||||
{
|
||||
Data = data.Select(x => new DashboardIncomeDataItem
|
||||
Data = data.Select(x => new
|
||||
{
|
||||
Id = x.Id?.ToShort(),
|
||||
Id = x.Id.ToShort(),
|
||||
Name = x.Name,
|
||||
Value = x.Amount,
|
||||
Value = (x.Amount * rates.FirstOrDefault(r => r.Key == x.CurrencyId).Value),
|
||||
})
|
||||
.GroupBy(x => new { x.Id, x.Name })
|
||||
.Select( x => new DashboardIncomeDataItem
|
||||
{
|
||||
Id = x.Key.Id,
|
||||
Name = x.Key.Name,
|
||||
Value = x.Sum(s => s.Value),
|
||||
})
|
||||
.ToList(),
|
||||
|
||||
Details = data.Select(x => new DashboardIncomeDataItem
|
||||
{
|
||||
Id = x.Id.ToShort(),
|
||||
Currency = x.CurrencyId,
|
||||
Name = x.Name,
|
||||
ValueRaw = x.Amount,
|
||||
Value = (x.Amount * rates.FirstOrDefault(r => r.Key == x.CurrencyId).Value),
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@@ -87,6 +119,12 @@ public class DashboardService
|
||||
? _accountRepository.GetOutcomeByCategory(userId, category.Value, from.ToUtc(), to.ToUtc())
|
||||
: _accountRepository.GetOutcomeByCategories(userId, from.ToUtc(), to.ToUtc());
|
||||
|
||||
var currencies = data
|
||||
.Where(x => x.Amount != 0)
|
||||
.Select(x => x.CurrencyId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
return new DashboardIncomeData
|
||||
{
|
||||
Data = data.Select(x => new DashboardIncomeDataItem
|
||||
|
||||
@@ -32,11 +32,14 @@ public class DashboardRestData
|
||||
public class DashboardIncomeData
|
||||
{
|
||||
public List<DashboardIncomeDataItem> Data { get; set; } = null!;
|
||||
public List<DashboardIncomeDataItem> Details { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class DashboardIncomeDataItem
|
||||
{
|
||||
public string? Id { get; set; } = null!;
|
||||
public string? Id { get; set; }
|
||||
public string Currency { get; set; } = null!;
|
||||
public string Name { get; set; } = null!;
|
||||
public decimal Value { get; set; }
|
||||
public decimal ValueRaw { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user