49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
namespace MyOffice.Data.Repositories.Currency;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Models.Currencies;
|
|
using MyOffice.Data.Repositories;
|
|
|
|
public class CurrencyRepository : AppRepository<Currency>, ICurrencyRepository
|
|
{
|
|
public List<Currency> GetAll(Guid userId)
|
|
{
|
|
return _context.Currencies
|
|
.Include(x => x.CurrencyGlobal)
|
|
.Where(x => x.UserId == userId)
|
|
.ToList();
|
|
}
|
|
|
|
public Currency? Get(Guid userId, Guid id)
|
|
{
|
|
return _context
|
|
.Currencies
|
|
.Include(x => x.CurrencyGlobal)
|
|
.FirstOrDefault(x => x.Id == id && x.UserId == userId);
|
|
}
|
|
|
|
public Currency? GetByGlobalCurrency(Guid userId, string globalCurrencyId)
|
|
{
|
|
return _context.Currencies.FirstOrDefault(x => x.UserId == userId && x.CurrencyGlobalId == globalCurrencyId);
|
|
}
|
|
|
|
public bool Add(Currency currency)
|
|
{
|
|
return AddBase(currency) > 0;
|
|
}
|
|
|
|
public bool Update(Currency currency)
|
|
{
|
|
return UpdateBase(currency) > 0;
|
|
}
|
|
|
|
public bool Remove(Currency currency)
|
|
{
|
|
return RemoveBase(currency) > 0;
|
|
}
|
|
|
|
public List<Currency> GetPrimaries(Guid userId)
|
|
{
|
|
return _context.Currencies.Where(x => x.UserId == userId && x.IsPrimary).ToList();
|
|
}
|
|
} |