97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Collections.RepoApi.Exceptions;
|
|
using LCU.API.Collections.RepoApi.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Exceptions;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
|
using Serilog;
|
|
|
|
namespace LCU.API.Collections.RepoApi.Services
|
|
{
|
|
public class ProcessingReceiptService : IProcessingReceiptService
|
|
{
|
|
private readonly IProcessingReceiptRepository _repository;
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
|
public ProcessingReceiptService(
|
|
IProcessingReceiptRepository repository,
|
|
IUnitOfWork unitOfWork)
|
|
{
|
|
_repository = repository;
|
|
_unitOfWork = unitOfWork;
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<ProcessingReceipt>> FindReceiptsAsync(string accountNo,
|
|
string accountId = "", string caseId = "")
|
|
{
|
|
try
|
|
{
|
|
return await _repository.FindReceiptsAsync(accountNo, accountId, caseId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Failure retrieving receipts");
|
|
throw new ServerErrorException();
|
|
}
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<ProcessingReceipt>> GetReceiptsByAccountNoAsync(string accountNo)
|
|
{
|
|
try
|
|
{
|
|
return await _repository.GetReceiptsByAccountNoAsync(accountNo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Failure retrieving receipts by accountNo");
|
|
throw new ServerErrorException();
|
|
}
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<ProcessingReceipt>> GetRetryListAsync()
|
|
{
|
|
try
|
|
{
|
|
return await _repository.GetRetryListAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Failure retrieving retry list of receipts");
|
|
throw new ServerErrorException();
|
|
}
|
|
}
|
|
|
|
public async Task SaveAsync(ProcessingReceipt receipt)
|
|
{
|
|
try
|
|
{
|
|
await _repository.AddOrUpdateAsync(receipt);
|
|
await _unitOfWork.CompleteAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Failure saving receipt");
|
|
throw new ServerErrorException();
|
|
}
|
|
}
|
|
|
|
public async Task SaveAllAsync(IReadOnlyCollection<ProcessingReceipt> receipts)
|
|
{
|
|
try
|
|
{
|
|
await _repository.SaveAllAsync(receipts);
|
|
await _unitOfWork.CompleteAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Failure saving receipts");
|
|
throw new ServerErrorException();
|
|
}
|
|
}
|
|
|
|
}
|
|
} |