fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace MyOffice.Data.Repositories.Currency;
|
||||
|
||||
using System.Xml.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Currencies;
|
||||
|
||||
@@ -18,18 +19,23 @@ public class CurrencyRateRepository : AppRepository<CurrencyRate>, ICurrencyRate
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CurrencyRate> GetLastRates(List<string> currencyIds)
|
||||
public Dictionary<string, CurrencyRate> GetLastRates(Guid userId, List<string> currencyIds, DateTime? before = null)
|
||||
{
|
||||
return _context.CurrencyRates
|
||||
.Include(x => x.Currency)
|
||||
.Include(x => x.Currency!.CurrencyGlobal)
|
||||
.Where(x => x.DateTime <= before)
|
||||
.Where(x => x.Currency!.UserId == userId)
|
||||
.Where(x => currencyIds.Contains(x.Currency!.CurrencyGlobalId))
|
||||
.GroupBy(x => new
|
||||
{
|
||||
x.CurrencyId,
|
||||
//x.Currency!.Name,
|
||||
//x.Currency!.CurrencyGlobalId,
|
||||
}, (key, g) => g.OrderByDescending(x => x.DateTime).First())
|
||||
.ToList();
|
||||
x.Currency!.CurrencyGlobalId
|
||||
}, (key, g) => new
|
||||
{
|
||||
key.CurrencyGlobalId,
|
||||
rate = g.OrderByDescending(x => x.DateTime).First()
|
||||
})
|
||||
.ToDictionary(x => x.CurrencyGlobalId, x => x.rate);
|
||||
}
|
||||
|
||||
public bool AddRate(CurrencyRate currencyRate)
|
||||
|
||||
@@ -5,7 +5,7 @@ using Models.Currencies;
|
||||
public interface ICurrencyRateRepository
|
||||
{
|
||||
List<CurrencyRate> GetLastRates(Guid currencyId, DateTime? before = null, int count = 1);
|
||||
List<CurrencyRate> GetLastRates(List<string> currencyIds);
|
||||
Dictionary<string, CurrencyRate> GetLastRates(Guid userId, List<string> currencyIds, DateTime? before = null);
|
||||
bool AddRate(CurrencyRate currencyRate);
|
||||
List<CurrencyRate> GetAtDate(Guid currencyId, DateTime date);
|
||||
}
|
||||
Reference in New Issue
Block a user