75 lines
3.2 KiB
C#
75 lines
3.2 KiB
C#
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models.ExternalActivities;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
|
|
|
|
public class NewIncentiveManagerActivityStrategy : IExternalActivityStrategy
|
|
{
|
|
private readonly IUserService _userService;
|
|
private readonly IDepartmentRepository _departmentRepository;
|
|
|
|
public NewIncentiveManagerActivityStrategy(IUserService userService, IDepartmentRepository departmentRepository)
|
|
{
|
|
_userService = userService;
|
|
_departmentRepository = departmentRepository;
|
|
}
|
|
|
|
public bool CanMapActivity(IExternalActivity activity)
|
|
{
|
|
return activity.GetActivityType() == ActivityType.Referral &&
|
|
(activity.GetProductType() == Product.ATMCard ||
|
|
activity.GetProductType() == Product.CheckCard ||
|
|
activity.GetProductType() == Product.NewChecking ||
|
|
activity.GetProductType() == Product.Mortgage ||
|
|
activity.GetProductType() == Product.DirectDeposit ||
|
|
activity.GetProductType() == Product.CreditCardBalanceTransfer ||
|
|
activity.GetProductType() == Product.LIC ||
|
|
activity.GetProductType() == Product.FirstMortgageReferral ||
|
|
activity.GetProductType() == Product.eStatement);
|
|
}
|
|
|
|
public async Task<Activity> MapToActivityManagerActivity(IExternalActivity activity)
|
|
{
|
|
AppUser appUser = null;
|
|
Department department = null;
|
|
try
|
|
{
|
|
if (activity is NewActivityManagerReferral newActivityManagerReferral)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(newActivityManagerReferral.EmployeeEmail))
|
|
{
|
|
appUser = await _userService.TryFindSingleUserByName(new UserNameSearchRequest()
|
|
{
|
|
FirstName = newActivityManagerReferral.OriginatorFirstName,
|
|
MiddleInit = newActivityManagerReferral.OriginatorMiddleInitial,
|
|
LastName = newActivityManagerReferral.OriginatorLastName
|
|
});
|
|
}
|
|
else
|
|
{
|
|
appUser = await _userService.GetUserByAdEmailAsync(newActivityManagerReferral.EmployeeEmail);
|
|
}
|
|
|
|
department =
|
|
await _departmentRepository.FindDepartmentByBranchName(newActivityManagerReferral
|
|
.OriginatingBranchName);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex,
|
|
$"Failed to get data for NewIncentiveManagerActivity with sourceId: {activity.MapToActivity().SourceId}. Falling back to basic mapping.");
|
|
}
|
|
|
|
var mappedActivity = activity.MapToActivity();
|
|
mappedActivity.AppUserId = appUser?.Id ?? Guid.Empty;
|
|
mappedActivity.EmployeeId = appUser?.EmployeeId;
|
|
mappedActivity.DepartmentId = department?.Id ?? -1;
|
|
return mappedActivity;
|
|
}
|
|
}
|