53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
|
|
public class PayoutRepository : BaseRepository, IPayoutRepository
|
|
{
|
|
public PayoutRepository(IApplicationDbContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public async Task<int> SavePayoutLineItemAsync(PayoutLineItem lineItem)
|
|
{
|
|
await _context.PayoutLineItems.AddAsync(lineItem);
|
|
return lineItem.Id;
|
|
}
|
|
|
|
public async Task SavePayoutLineItemRangeAsync(IReadOnlyCollection<PayoutLineItem> lineItems)
|
|
{
|
|
await _context.PayoutLineItems.AddRangeAsync(lineItems);
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<PayoutLineItem>> GetPayoutLineItemsForPeriodAsync(DateTime forPeriod)
|
|
{
|
|
var checkDate = new DateTime(forPeriod.Year, forPeriod.Month, 1);
|
|
return await _context.PayoutLineItems
|
|
.Where(p => p.ActivityPeriod.Date == checkDate.Date)
|
|
.OrderBy(t => t.Id)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<PayoutLineItem> GetPayoutLineItemById(int payoutId)
|
|
{
|
|
return await _context.PayoutLineItems.FindAsync(payoutId);
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<PayoutLineItem>> GetEmployeePayoutsForPeriod(AppUser appUser, DateTime forPeriod)
|
|
{
|
|
var checkDate = new DateTime(forPeriod.Year, forPeriod.Month, 1);
|
|
return await _context.PayoutLineItems.AsNoTracking()
|
|
.Include(x => x.ActivityPayouts).ThenInclude(y => y.Activity)
|
|
.Where(p => p.ActivityPeriod.Date == checkDate.Date &&
|
|
p.EmployeeId == appUser.EmployeeId)
|
|
.OrderBy(t => t.Id)
|
|
.ToListAsync();
|
|
}
|
|
}
|