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.
47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
using Distribution.Data;
|
|
using Distribution.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Features.ChequeBook;
|
|
|
|
public class ChequeBookRepository(AppDBContext context) : IChequeBookRepository
|
|
{
|
|
public async Task<Models.ChequeBook?> GetByNoAsync(string chequeBookNo, bool includePages)
|
|
{
|
|
var query = context.ChequeBooks.AsQueryable();
|
|
if (includePages) query = query.Include(b => b.Pages);
|
|
return await query.FirstOrDefaultAsync(b => b.ChequeBookNo == chequeBookNo);
|
|
}
|
|
|
|
public async Task<(List<Models.ChequeBook> Items, int TotalCount)> ListAsync(
|
|
Guid? bankAccountId, int? branchId, ChequeBookStatus? status, int page, int pageSize)
|
|
{
|
|
var query = context.ChequeBooks.AsQueryable();
|
|
if (bankAccountId is not null) query = query.Where(b => b.FK_BankAccountId == bankAccountId);
|
|
if (branchId is not null) query = query.Where(b => b.BranchId == branchId);
|
|
if (status is not null) query = query.Where(b => b.Status == status);
|
|
|
|
var total = await query.CountAsync();
|
|
var items = await query
|
|
.OrderByDescending(b => b.CreatedAt)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToListAsync();
|
|
return (items, total);
|
|
}
|
|
|
|
public async Task<bool> BookNoExistsAsync(string chequeBookNo) =>
|
|
await context.ChequeBooks.AnyAsync(b => b.ChequeBookNo == chequeBookNo);
|
|
|
|
public async Task AddAsync(Models.ChequeBook book) => await context.ChequeBooks.AddAsync(book);
|
|
|
|
public void Update(Models.ChequeBook book) => context.ChequeBooks.Update(book);
|
|
|
|
public async Task<Models.ChequePage?> GetPageByNoAsync(string chequeNo) =>
|
|
await context.ChequePages
|
|
.Include(p => p.ChequeBook)
|
|
.FirstOrDefaultAsync(p => p.ChequeNo == chequeNo);
|
|
|
|
public void UpdatePage(Models.ChequePage page) => context.ChequePages.Update(page);
|
|
}
|