43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
|
|
public class CommissionRepository : BaseRepository, ICommissionRepository
|
|
{
|
|
public CommissionRepository(IApplicationDbContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public async Task<Commission> FindExistingCommission(int id)
|
|
{
|
|
return await _context.Commissions.FindAsync(id);
|
|
}
|
|
|
|
public async Task<Commission> FindExistingCommission(Role role, Product product)
|
|
{
|
|
return await _context.Commissions.FirstOrDefaultAsync(x => x.Role == role &&
|
|
x.Product == product);
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<Commission>> GetCommissionsAsync()
|
|
{
|
|
return await _context.Commissions.ToListAsync();
|
|
}
|
|
|
|
public async Task SaveCommission(Commission commission)
|
|
{
|
|
await _context.Commissions.AddAsync(commission);
|
|
}
|
|
|
|
public async Task<IList<Commission>> FindProductCommissions(Role employeeRole)
|
|
{
|
|
return await _context.Commissions.AsNoTracking().Where(x => x.Role == employeeRole).ToListAsync();
|
|
}
|
|
}
|