87c807c16c
- Implemented ChequeBooksPage for viewing and filtering cheque books. - Added NewReceivedChequePage for recording received cheques. - Created ReceivedChequesPage for listing and managing received cheques. - Introduced API endpoints for bank accounts, cheque books, and received cheques. - Defined types for payments including bank accounts, cheque books, and received cheques.
41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
using Distribution.Data;
|
|
using Distribution.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Features.BankAccount;
|
|
|
|
public class BankAccountRepository(AppDBContext context) : IBankAccountRepository
|
|
{
|
|
public async Task<Models.BankAccount?> GetByIdAsync(Guid id) =>
|
|
await context.BankAccounts.FirstOrDefaultAsync(a => a.Id == id);
|
|
|
|
public async Task<List<Models.BankAccount>> ListAsync(BankAccountType? accountType)
|
|
{
|
|
var query = context.BankAccounts.AsQueryable();
|
|
if (accountType is not null)
|
|
query = query.Where(a => a.AccountType == accountType);
|
|
return await query.OrderByDescending(a => a.CreatedAt).ToListAsync();
|
|
}
|
|
|
|
public async Task<List<string>> ListCashAccountTypeNamesAsync() =>
|
|
await context.BankAccounts
|
|
.Where(a => a.AccountType == BankAccountType.Cash && a.CashAccountTypeName != null)
|
|
.Select(a => a.CashAccountTypeName!)
|
|
.Distinct()
|
|
.OrderBy(n => n)
|
|
.ToListAsync();
|
|
|
|
public async Task<bool> ExistsByNameAsync(BankAccountType type, string accountName, Guid? excludeId = null) =>
|
|
await context.BankAccounts.AnyAsync(a =>
|
|
a.AccountType == type &&
|
|
a.AccountName == accountName &&
|
|
(excludeId == null || a.Id != excludeId));
|
|
|
|
public async Task AddAsync(Models.BankAccount account) =>
|
|
await context.BankAccounts.AddAsync(account);
|
|
|
|
public void Update(Models.BankAccount account) => context.BankAccounts.Update(account);
|
|
|
|
public void Remove(Models.BankAccount account) => context.BankAccounts.Remove(account);
|
|
}
|