49 lines
2.1 KiB
C#
49 lines
2.1 KiB
C#
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
|
using LCU.Library.Internal.IncentiveApiModels.Results;
|
|
using LCU.Library.Internal.LCUServiceFactory.Configurations;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.NightlyIncentiveProcesses;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Services.NightlyDecisionServices;
|
|
|
|
public class EStatementReferralActivityDecisionService : NightlyIncentiveProcessesService, INightlyIncentiveProcessesService
|
|
{
|
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
private readonly ProcessResult _processResult;
|
|
|
|
public EStatementReferralActivityDecisionService(ServicesFactoryConfiguration servicesFactoryConfiguration,
|
|
IServiceScopeFactory serviceScopeFactory)
|
|
: base(servicesFactoryConfiguration)
|
|
{
|
|
_serviceScopeFactory = serviceScopeFactory;
|
|
_processResult = new ProcessResult();
|
|
}
|
|
|
|
public async Task<ProcessResult> RunProductDecisionProcess(NightlyIncentiveProcessRequest request)
|
|
{
|
|
try
|
|
{
|
|
var result = await UpdateAndDecideActivities();
|
|
var message = $"{result.Count()} E-Statement Referrals were updated";
|
|
Log.Information(message);
|
|
_processResult.MessageStack.Add(message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = $"There was an issue with the E-Statement Referral Update process. Exception Message: {exception.Message}.";
|
|
_processResult.MessageStack.Add(message);
|
|
_processResult.Success = false;
|
|
}
|
|
return _processResult;
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<ActivityStateChange>> UpdateAndDecideActivities()
|
|
{
|
|
using var scope = _serviceScopeFactory.CreateScope();
|
|
var changes = await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IEStatementService>().UpdateOrExpireEStatementReferral());
|
|
|
|
return changes;
|
|
}
|
|
}
|