77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.PaymentInstrumentAgg;
|
|
using CompanyManagment.App.Contracts.PaymentInstrument;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class PaymentInstrumentRepository : RepositoryBase<long, PaymentInstrument>, IPaymentInstrumentRepository
|
|
{
|
|
private readonly CompanyContext _companyContext;
|
|
|
|
public PaymentInstrumentRepository(CompanyContext context) : base(context)
|
|
{
|
|
_companyContext = context;
|
|
}
|
|
|
|
public async Task<GetPaymentInstrumentListViewModel> GetList(PaymentInstrumentSearchModel searchModel)
|
|
{
|
|
var query = _companyContext.PaymentInstruments
|
|
.Include(x => x.PaymentInstrumentGroup)
|
|
.AsNoTracking();
|
|
|
|
#region Search
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.AccountHolderName))
|
|
{
|
|
query = query.Where(x => x.AccountHolderName.Contains(searchModel.AccountHolderName));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.AccountNumber))
|
|
{
|
|
query = query.Where(x => x.AccountNumber.Contains(searchModel.AccountNumber));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.PosTerminalId))
|
|
{
|
|
query = query.Where(x => x.PosTerminalId.Contains(searchModel.PosTerminalId));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.CardNumber))
|
|
{
|
|
query = query.Where(x => x.CardNumber.Contains(searchModel.CardNumber));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.IBan))
|
|
{
|
|
query = query.Where(x => x.IBan.Contains(searchModel.IBan));
|
|
}
|
|
|
|
#endregion
|
|
|
|
var count = query.Count();
|
|
var list = new GetPaymentInstrumentListViewModel()
|
|
{
|
|
Count = count,
|
|
GropedViewModels = await query.GroupBy(x => x.PaymentInstrumentGroupId)
|
|
.OrderBy(x=>x.Key)
|
|
.Select(x => new PaymentInstrumentGroupedViewModel()
|
|
{
|
|
Name = x.First().PaymentInstrumentGroup.Name,
|
|
Items = x.Select(i => new PaymentInstrumentItemsViewModel()
|
|
{
|
|
Id = i.id,
|
|
Description = i.Description,
|
|
IBan = i.IBan,
|
|
PosTerminalId = i.PosTerminalId,
|
|
CardNumber = i.CardNumber,
|
|
AccountNumber = i.AccountNumber,
|
|
|
|
}).ToList()
|
|
}).Skip(searchModel.PageIndex).Take(30).ToListAsync()
|
|
};
|
|
return list;
|
|
}
|
|
} |