112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.PaymentTransactionAgg;
|
|
using CompanyManagment.App.Contracts.PaymentTransaction;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class PaymentTransactionRepository : RepositoryBase<long, PaymentTransaction>, IPaymentTransactionRepository
|
|
{
|
|
private readonly CompanyContext _companyContext;
|
|
public PaymentTransactionRepository(CompanyContext companyContext) : base(companyContext)
|
|
{
|
|
_companyContext = companyContext;
|
|
}
|
|
|
|
public async Task<List<GetPaymentTransactionListViewModel>> GetPaymentTransactionList(GetPaymentTransactionListSearchModel searchModel)
|
|
{
|
|
var query = _companyContext.PaymentTransactions.AsQueryable();
|
|
|
|
if (searchModel.ContractingPartyId > 0)
|
|
{
|
|
query = query.Where(x => x.ContractingPartyId == searchModel.ContractingPartyId);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.FromDate) && !string.IsNullOrWhiteSpace(searchModel.ToDate))
|
|
{
|
|
searchModel.FromDate.TryToGeorgianDateTime(out var fromDateGr);
|
|
searchModel.ToDate.TryToGeorgianDateTime(out var toDateGr);
|
|
query = query.Where(x => x.TransactionDate >= fromDateGr && x.TransactionDate <= toDateGr);
|
|
}
|
|
|
|
if (searchModel.FromAmount > 0 || searchModel.ToAmount > 0)
|
|
{
|
|
if (searchModel.FromAmount > 0 && searchModel.ToAmount > 0)
|
|
{
|
|
query = query.Where(x => x.Amount >= searchModel.FromAmount && x.Amount <= searchModel.ToAmount);
|
|
}
|
|
else if (searchModel.FromAmount > 0)
|
|
{
|
|
query = query.Where(x => x.Amount >= searchModel.FromAmount);
|
|
}
|
|
else if (searchModel.ToAmount > 0)
|
|
{
|
|
query = query.Where(x => x.Amount <= searchModel.ToAmount);
|
|
}
|
|
}
|
|
|
|
if (searchModel.StatusEnum != null)
|
|
{
|
|
query = query.Where(x => x.Status == searchModel.StatusEnum);
|
|
}
|
|
|
|
var paymentTransactionsData = await query
|
|
.AsNoTracking()
|
|
.Skip(searchModel.PageIndex)
|
|
.Take(30)
|
|
.ToListAsync();
|
|
|
|
var result = paymentTransactionsData
|
|
.Select(x => new GetPaymentTransactionListViewModel
|
|
{
|
|
Id = x.id,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
BankName = x.BankName,
|
|
CardNumber = x.CardNumber,
|
|
Status = x.Status switch
|
|
{
|
|
PaymentTransactionStatus.Failed => "ناموفق",
|
|
PaymentTransactionStatus.Success => "موفق",
|
|
_ => "نامشخص"
|
|
},
|
|
StatusEnum = x.Status,
|
|
Amount = x.Amount,
|
|
TransactionId = x.TransactionId,
|
|
PaymentDate = x.TransactionDate.ToFarsi(),
|
|
PaymentTime = $"{x.TransactionDate:HH:mm}"
|
|
})
|
|
.ToList();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
public async Task<PaymentTransactionDetailsViewModel> GetDetails(long id)
|
|
{
|
|
var transaction = await _companyContext.PaymentTransactions.FirstOrDefaultAsync(x => x.id == id);
|
|
|
|
if (transaction == null)
|
|
return null;
|
|
|
|
var result = new PaymentTransactionDetailsViewModel()
|
|
{
|
|
Id = transaction.id,
|
|
Amount = transaction.Amount,
|
|
CallBackUrl = transaction.CallBackUrl,
|
|
ContractingPartyId = transaction.ContractingPartyId,
|
|
CardNumber = transaction.CardNumber,
|
|
TransactionId = transaction.TransactionId,
|
|
Status = transaction.Status,
|
|
ContractingPartyName = transaction.ContractingPartyName,
|
|
BankName = transaction.BankName,
|
|
TransactionDate = transaction.TransactionDate
|
|
};
|
|
|
|
return result;
|
|
}
|
|
} |