Adding
This commit is contained in:
+139
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using LCU.API.Collections.CollectionsApi.Configuration;
|
||||
using TemenosCase;
|
||||
|
||||
namespace LCU.API.Collections.CollectionsApi.Mappers
|
||||
{
|
||||
public class CaseMapper
|
||||
{
|
||||
private readonly ICaseStageConfig _caseStageConfig;
|
||||
private readonly IMapper _mapToCollectionsModel;
|
||||
private const string FieldTitleOrdered = "Title Ordered Flag Case Lvl";
|
||||
private const string FieldTitleOrderedDate = "Date Title Ordered Case Lvl";
|
||||
private const string FieldRedemptionExpireDateIl = "IL Redemption Date Case Lvl";
|
||||
private const string FieldRedemptionExpireDateWi = "WI Redemption Date Case Lvl";
|
||||
private const string FieldDateAssigned = "Date Assigned to Agent";
|
||||
private const string FieldRepoAgentLookup = "Repo Agent Lookup";
|
||||
private const string FieldRepoType = "Repo Type Case Lvl";
|
||||
|
||||
public CaseMapper()
|
||||
{
|
||||
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Account1, CollectionsApiLib.Models.TemenosAccount>()
|
||||
.ForPath(dest => dest.AccountId, opts => opts.MapFrom(src => src.AccountID))
|
||||
.ForPath(dest => dest.AccountTypeId, opts => opts.MapFrom(src => src.AccountTypeID))
|
||||
.ForPath(dest => dest.DQAmount, opts => opts.MapFrom(src => src.DQAmount))
|
||||
.ForPath(dest => dest.DaysDq, opts => opts.MapFrom(src => src.DaysDQ));
|
||||
|
||||
cfg.CreateMap<Case1, CollectionsApiLib.Models.TemenosCase>()
|
||||
.ForPath(dest => dest.CaseId, opts => opts.MapFrom(src => src.CaseID))
|
||||
.ForPath(dest => dest.CaseStageId, opts => opts.MapFrom(src => src.CaseStageID))
|
||||
// Don't translate repo status here, it's not "mapped", it's looked up.
|
||||
.ForPath(dest => dest.CaseStatusId, opts => opts.MapFrom(src => src.CaseStatusID))
|
||||
.ForPath(dest => dest.CaseTypeBasisId, opts => opts.MapFrom(src => src.CaseTypeBasisId))
|
||||
.ForPath(dest => dest.CaseTypeId, opts => opts.MapFrom(src => src.CaseTypeID));
|
||||
});
|
||||
|
||||
_mapToCollectionsModel = config.CreateMapper();
|
||||
|
||||
}
|
||||
|
||||
public CollectionsApiLib.Models.TemenosCase MapToCollectionsCase(Case1 dto)
|
||||
{
|
||||
return _mapToCollectionsModel.Map<Case1, CollectionsApiLib.Models.TemenosCase>(dto);
|
||||
}
|
||||
|
||||
public static void ConvertCustomFields(Case1 temenosCase, CollectionsApiLib.Models.TemenosCase accountCase)
|
||||
{
|
||||
if (temenosCase.Repossession != null)
|
||||
{
|
||||
accountCase.DateRepossessed = temenosCase.Repossession.DateRepossessed;
|
||||
|
||||
if (temenosCase.Repossession.CustomFields != null && temenosCase.Repossession.CustomFields.Any())
|
||||
{
|
||||
foreach (var customField in temenosCase.Repossession.CustomFields)
|
||||
{
|
||||
if (string.Equals(customField._Label, FieldDateAssigned))
|
||||
{
|
||||
var dateString = customField._Value;
|
||||
if (!string.IsNullOrWhiteSpace(dateString))
|
||||
{
|
||||
accountCase.DateRepoAssigned = DateTime.Parse(dateString);
|
||||
}
|
||||
}
|
||||
|
||||
if (string.Equals(customField._Label, FieldRepoAgentLookup))
|
||||
{
|
||||
accountCase.RepoAgentId = customField._Value;
|
||||
}
|
||||
|
||||
if (string.Equals(customField._Label, FieldTitleOrdered))
|
||||
{
|
||||
accountCase.TitleOrdered = string.Equals(customField._Value, "True");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(customField._Label, FieldTitleOrderedDate))
|
||||
{
|
||||
var dateString = customField._Value;
|
||||
if (!string.IsNullOrWhiteSpace(dateString))
|
||||
{
|
||||
accountCase.TitleOrderedDate = DateTime.Parse(dateString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (temenosCase.CustomFields != null && temenosCase.CustomFields.Any())
|
||||
{
|
||||
var map = new Dictionary<string, string>();
|
||||
foreach (var customField in temenosCase.CustomFields)
|
||||
{
|
||||
if (map.ContainsKey(customField._Label))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(customField._Label, FieldRedemptionExpireDateIl))
|
||||
{
|
||||
var dateString = customField._Value;
|
||||
if (!string.IsNullOrWhiteSpace(dateString))
|
||||
{
|
||||
accountCase.RedemptionExpiredDateIl = DateTime.Parse(dateString);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(customField._Label, FieldRepoType))
|
||||
{
|
||||
accountCase.RepoTypeId = customField._Value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(customField._Label, FieldRedemptionExpireDateWi))
|
||||
{
|
||||
var dateString = customField._Value;
|
||||
if (!string.IsNullOrWhiteSpace(dateString))
|
||||
{
|
||||
accountCase.RedemptionExpiredDateWi = DateTime.Parse(dateString);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
map.Add(customField._Label, customField._Value);
|
||||
}
|
||||
|
||||
accountCase.CustomFieldMap = map;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user