41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using Apimanager_backend.Data;
|
|
using Apimanager_backend.Exceptions;
|
|
using Apimanager_backend.Models;
|
|
using AutoMapper;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Apimanager_backend.Services
|
|
{
|
|
public class PaymentConfigService : IPaymentConfigService
|
|
{
|
|
private ApiContext _context;
|
|
private ILogger<PaymentConfigService> _logger;
|
|
private IMapper _mapper;
|
|
public PaymentConfigService(ApiContext context,ILogger<PaymentConfigService> logger,IMapper mapper)
|
|
{
|
|
_context = context;
|
|
_logger = logger;
|
|
_mapper = mapper;
|
|
}
|
|
public async Task<List<PaymentConfigDto>> GetAllPaymentAsync()
|
|
{
|
|
var data = await _context.paymentConfigs.Where(x => x.IsEnabled).ToListAsync();
|
|
return _mapper.Map<List<PaymentConfigDto>>(data);
|
|
}
|
|
|
|
public async Task<PaymentConfig> GetPaymentConfigInfoByTypeAsync(string payType)
|
|
{
|
|
if(!Enum.TryParse(payType, true, out PaymentType parsedPayType))
|
|
{
|
|
throw new BaseException(4001, "未配置该支付方式的通道");
|
|
}
|
|
var data = await _context.paymentConfigs.SingleOrDefaultAsync(x => x.Method == parsedPayType);
|
|
if(data == null)
|
|
{
|
|
throw new BaseException(4001, "未配置该支付方式的通道");
|
|
}
|
|
return data;
|
|
}
|
|
}
|
|
}
|