108 lines
4.2 KiB
C#
108 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework_b.InfraStructure;
|
|
using Company.Application.Contracts.AuthorizedBankDetails;
|
|
using Company.Domain.AuthorizedBankDetailsAgg;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CompanyManagment.EFCore.Repository
|
|
{
|
|
public class AuthorizedBankDetailsRepository : RepositoryBase<long, AuthorizedBankDetails>, IAuthorizedBankDetailsRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
|
|
public AuthorizedBankDetailsRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public EditAuthorizedBankDetails GetDetails(long id)
|
|
{
|
|
var authorizedBankDetails = _context.AuthorizedBankDetails
|
|
.Include(x => x.OwnersList)
|
|
.FirstOrDefault(x => x.id == id);
|
|
|
|
if (authorizedBankDetails == null)
|
|
return new EditAuthorizedBankDetails();
|
|
|
|
var result = new EditAuthorizedBankDetails
|
|
{
|
|
Id = authorizedBankDetails.id,
|
|
CardNumber = authorizedBankDetails.CardNumber,
|
|
AccountNumber = authorizedBankDetails.AccountNumber,
|
|
IBan = authorizedBankDetails.IBan,
|
|
BankName = authorizedBankDetails.BankName,
|
|
OwnersList = authorizedBankDetails.OwnersList.Select(o => new AuthorizedBankDetailsOwnerViewModel
|
|
{
|
|
FName = o.FName,
|
|
LName = o.LName,
|
|
NationalIdentifier = o.NationalIdentifier,
|
|
CustomerType = o.CustomerType
|
|
}).ToList()
|
|
};
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<AuthorizedBankDetailsViewModel> Search(AuthorizedBankDetailsSearchModel searchModel)
|
|
{
|
|
var query = _context.AuthorizedBankDetails
|
|
.Include(x => x.OwnersList)
|
|
.Select(x => new AuthorizedBankDetailsViewModel
|
|
{
|
|
Id = x.id,
|
|
CardNumber = x.CardNumber,
|
|
AccountNumber = x.AccountNumber,
|
|
IBan = x.IBan,
|
|
});
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.CardNumber))
|
|
query = query.Where(x => x.CardNumber.Contains(searchModel.CardNumber));
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.AccountNumber))
|
|
query = query.Where(x => x.AccountNumber.Contains(searchModel.AccountNumber));
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.IBan))
|
|
query = query.Where(x => x.IBan.Contains(searchModel.IBan));
|
|
|
|
// if (!string.IsNullOrWhiteSpace(searchModel.BankName))
|
|
// query = query.Where(x => x.BankName.Contains(searchModel.BankName));
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.NationalIdentifier))
|
|
query = query.Where(x =>
|
|
_context.AuthorizedBankDetails
|
|
.Include(a => a.OwnersList)
|
|
.Any(a => a.id == x.Id &&
|
|
a.OwnersList.Any(o => o.NationalIdentifier.Contains(searchModel.NationalIdentifier))));
|
|
|
|
return query.OrderByDescending(x => x.Id).ToList();
|
|
}
|
|
|
|
public AuthorizedBankDetailsViewModel GetByIban(string iban)
|
|
{
|
|
return _context.AuthorizedBankDetails
|
|
.Include(x => x.OwnersList)
|
|
.Where(x => x.IBan == iban)
|
|
.Select(x => new AuthorizedBankDetailsViewModel
|
|
{
|
|
Id = x.id,
|
|
CardNumber = x.CardNumber,
|
|
AccountNumber = x.AccountNumber,
|
|
IBan = x.IBan,
|
|
BankName = x.BankName,
|
|
NationalIdentifier = x.OwnersList.FirstOrDefault().NationalIdentifier,
|
|
Owners = x.OwnersList.Select(o=> new AuthorizedBankDetailsOwnerViewModel()
|
|
{
|
|
FName = o.FName,
|
|
LName = o.LName,
|
|
NationalIdentifier = o.NationalIdentifier,
|
|
CustomerType = o.CustomerType
|
|
}).ToList()
|
|
})
|
|
.FirstOrDefault();
|
|
}
|
|
}
|
|
}
|