44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
namespace MyOffice.Data.Repositories.Currency;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Models.Currencies;
|
|
|
|
public class CurrencyRateRepository : AppRepository<CurrencyRate>, ICurrencyRateRepository
|
|
{
|
|
public List<CurrencyRate> GetLastRates(Guid currencyId, int count = 1)
|
|
{
|
|
return _context.CurrencyRates
|
|
.Where(x => x.CurrencyId == currencyId)
|
|
.OrderByDescending(x => x.DateTime)
|
|
.ThenByDescending(x => x.Id)
|
|
.Take(count)
|
|
.ToList();
|
|
}
|
|
|
|
public List<CurrencyRate> GetLastRates(List<string> currencyIds)
|
|
{
|
|
return _context.CurrencyRates
|
|
.Include(x => x.Currency)
|
|
.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();
|
|
}
|
|
|
|
public bool AddRate(CurrencyRate currencyRate)
|
|
{
|
|
return this.AddBase(currencyRate) > 0;
|
|
}
|
|
|
|
public List<CurrencyRate> GetAtDate(Guid currencyId, DateTime date)
|
|
{
|
|
return _context.CurrencyRates
|
|
.Where(x => x.CurrencyId == currencyId && x.DateTime == date)
|
|
.ToList();
|
|
|
|
}
|
|
} |