first commit
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Azure.Storage.Blobs;
|
||||
using Landmark.OLA.Application.Configuration;
|
||||
using Landmark.OLA.Models.Loan;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public class BlobStorageAccess : IBlobStorageAccess
|
||||
{
|
||||
readonly BlobServiceClient _blobServiceClient;
|
||||
readonly string _containerName;
|
||||
readonly BlobContainerClient _containerClient;
|
||||
readonly BlobStorageConnectionSettings _settings;
|
||||
|
||||
public BlobStorageAccess(IOptions<BlobStorageConnectionSettings> settings)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
|
||||
_blobServiceClient = new BlobServiceClient($"AccountName={_settings.AccountName};AccountKey={_settings.AccountKey}");
|
||||
_containerName = "documents";
|
||||
_containerClient = _blobServiceClient.GetBlobContainerClient(_containerName);
|
||||
}
|
||||
|
||||
public byte[] GetBlobAsBytes(LoanApplicationFile file)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var blob = _containerClient.GetBlobClient(file.GetBlobPath());
|
||||
|
||||
var fileContent = blob.DownloadContent();
|
||||
var fileBytes = fileContent.Value.Content.ToArray();
|
||||
|
||||
return fileBytes;
|
||||
}
|
||||
|
||||
public string GetBlobAsBase64(LoanApplicationFile file)
|
||||
{
|
||||
var fileBytes = GetBlobAsBytes(file);
|
||||
|
||||
return Convert.ToBase64String(fileBytes);
|
||||
}
|
||||
|
||||
public bool SaveBlob(LoanApplicationFile file, byte[] fileBytes)
|
||||
{
|
||||
if(file == null || fileBytes == null || fileBytes.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BlobClient blobClient = _containerClient.GetBlobClient(file.GetBlobPath());
|
||||
blobClient.Upload(new BinaryData(fileBytes));
|
||||
blobClient.SetMetadata(file.GetMetadata());
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeleteBlob(LoanApplicationFile file)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BlobClient blobClient = _containerClient.GetBlobClient(file.GetBlobPath());
|
||||
return blobClient.DeleteIfExists();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using Serilog;
|
||||
using CRIF.ACTion.Configuration;
|
||||
using CRIF.ACTion.Services.Crif;
|
||||
using Landmark.OLA.Models.Loan;
|
||||
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public class BranchDataAccess : IDisposable, IBranchDataAccess
|
||||
{
|
||||
private bool disposed = false;
|
||||
private protected readonly CrifSettings _crifSettings;
|
||||
private readonly IDataClient _client;
|
||||
private readonly ICrifVendorClient _vendorClient;
|
||||
private readonly string _collectionName = "Branches";
|
||||
private readonly string _branchNameCollectionName = "ServicingChannelToBranchName";
|
||||
private readonly List<BranchNameData> _branchNameDataListDefaults = new List<BranchNameData>
|
||||
{
|
||||
new() { ChannelId = 0, BranchName = "Not Found" },
|
||||
new() { ChannelId = 1, BranchName = "ALL" }
|
||||
};
|
||||
|
||||
public BranchDataAccess(
|
||||
IDataClient dataClient,
|
||||
IOptions<CrifSettings> crifSettings,
|
||||
ICrifVendorClient vendorClient)
|
||||
{
|
||||
_client = dataClient;
|
||||
_crifSettings = crifSettings.Value;
|
||||
_vendorClient = vendorClient;
|
||||
}
|
||||
|
||||
private IMongoCollection<BranchConfig> GetBranchContainersCollection()
|
||||
{
|
||||
return _client.GetDatabase().GetCollection<BranchConfig>(_collectionName);
|
||||
}
|
||||
|
||||
private IMongoCollection<BranchNameConfig> GetBranchNameContainersCollection()
|
||||
{
|
||||
return _client.GetDatabase().GetCollection<BranchNameConfig>(_branchNameCollectionName);
|
||||
}
|
||||
|
||||
public BranchConfig GetBranchConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetBranchContainersCollection();
|
||||
var result = collection.Find(new BsonDocument()).ToList().FirstOrDefault();
|
||||
return result ?? throw new Exception("Could not find branch mapping");
|
||||
}
|
||||
catch (MongoConnectionException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Could not load branch config");
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateBranchConfig(BranchConfig branchConfig)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetBranchContainersCollection();
|
||||
|
||||
if (collection.Find(new BsonDocument()).ToList().Count > 0)
|
||||
{
|
||||
throw new Exception("Can only insert 1 branch config");
|
||||
}
|
||||
collection.InsertOne(branchConfig);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while creating branch config");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while creating branch config");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateBranchConfig(BranchConfig branchConfig)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetBranchContainersCollection();
|
||||
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachLoan => eachLoan.Id == branchConfig.Id, branchConfig);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while creating updating branch config");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while creating updating branch config");
|
||||
}
|
||||
}
|
||||
|
||||
public BranchNameConfig GetBranchNameConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetBranchNameContainersCollection();
|
||||
var result = collection.Find(new BsonDocument()).ToList().FirstOrDefault();
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
UpsertBranchNameConfig();
|
||||
}
|
||||
else if (result != null && result.BranchNamesByChannelId.Count <= _branchNameDataListDefaults.Count)
|
||||
{
|
||||
UpsertBranchNameConfig(true);
|
||||
}
|
||||
|
||||
collection = GetBranchNameContainersCollection();
|
||||
result = collection.Find(new BsonDocument()).ToList().FirstOrDefault();
|
||||
return result;
|
||||
}
|
||||
catch (MongoConnectionException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Could not load branch name config");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpsertBranchNameConfig(bool IsUpdate = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetBranchNameContainersCollection();
|
||||
|
||||
if (collection.Find(new BsonDocument()).ToList().Count > 0 && !IsUpdate)
|
||||
{
|
||||
throw new Exception("Can only insert 1 branch name config");
|
||||
}
|
||||
|
||||
SortedList<int, string> configurationDetails = _vendorClient.GetBranchNameConfiguration("getChannels").GetAwaiter().GetResult();
|
||||
BranchNameConfig branchNameConfig = new();
|
||||
|
||||
List<BranchNameData> branchNameDataList = CreateBranchNameDataList(configurationDetails);
|
||||
|
||||
branchNameConfig.Id = (Guid.NewGuid()).ToString();
|
||||
branchNameConfig.Date = DateTime.Now;
|
||||
branchNameConfig.BranchNamesByChannelId = branchNameDataList;
|
||||
|
||||
if (IsUpdate)
|
||||
{
|
||||
var oldConfig = collection.Find(new BsonDocument()).ToList().FirstOrDefault();
|
||||
branchNameConfig.Id = oldConfig.Id;
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachConfig => eachConfig.Id == branchNameConfig.Id, branchNameConfig);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
collection.InsertOne(branchNameConfig);
|
||||
}
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while creating branch names config");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while creating branch names config");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateBranchNameConfig()
|
||||
{
|
||||
UpsertBranchNameConfig(true);
|
||||
}
|
||||
|
||||
public List<BranchNameData> CreateBranchNameDataList(SortedList<int, string> configurationDetails)
|
||||
{
|
||||
List<BranchNameData> branchNameDataList = _branchNameDataListDefaults;
|
||||
|
||||
foreach (var branchNameData in configurationDetails)
|
||||
{
|
||||
try
|
||||
{
|
||||
branchNameDataList.Add(new BranchNameData { ChannelId = branchNameData.Key, BranchName = branchNameData.Value });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
return branchNameDataList;
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
public int GetDistributionChannelByZipCode(string zipCode)
|
||||
{
|
||||
var config = GetBranchConfig();
|
||||
foreach (var eachBranch in config.BranchCodesByZip)
|
||||
{
|
||||
if (eachBranch.Zipcode == zipCode)
|
||||
{
|
||||
return eachBranch.ChannelId;
|
||||
}
|
||||
}
|
||||
return _crifSettings.ServicingChannels.DefaultServicingChannel;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using Serilog;
|
||||
using Landmark.OLA.Application.Common.Domain;
|
||||
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public class ConfigurationAccess : IDisposable, IConfigurationAccess
|
||||
{
|
||||
private bool disposed = false;
|
||||
private readonly IDataClient _client;
|
||||
private readonly string _collectionName = "AppConfiguration";
|
||||
|
||||
public ConfigurationAccess(
|
||||
IDataClient dataClient)
|
||||
{
|
||||
_client = dataClient;
|
||||
}
|
||||
|
||||
private IMongoCollection<StoredSettings> GetConfigurationContainersCollection()
|
||||
{
|
||||
return _client.GetDatabase().GetCollection<StoredSettings>(_collectionName);
|
||||
}
|
||||
|
||||
public StoredSettings GetStoredSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetConfigurationContainersCollection();
|
||||
var result = collection.Find(new BsonDocument()).ToList().FirstOrDefault();
|
||||
if( result == null )
|
||||
{
|
||||
throw new Exception("Could not find app configuration.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (MongoConnectionException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Could not load app configuration.");
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateStoredSettings(StoredSettings storedSettings)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetConfigurationContainersCollection();
|
||||
|
||||
if (collection.Find(new BsonDocument()).ToList().Count > 0)
|
||||
{
|
||||
throw new Exception("Can only insert 1 configuration");
|
||||
}
|
||||
collection.InsertOne(storedSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while creating app configuration");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateStoredSettings(StoredSettings storedSettings)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetConfigurationContainersCollection();
|
||||
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachConfig => eachConfig.Id == storedSettings.Id, storedSettings);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while updating app configuration");
|
||||
}
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public class DataAccessConnection
|
||||
{
|
||||
public string DatabaseName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Security.Authentication;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
// Reference: http://mongodb.github.io/mongo-csharp-driver/2.5
|
||||
public class DataClient : IDataClient
|
||||
{
|
||||
private readonly MongoClientSettings _mongoSettings;
|
||||
private readonly DataAccessConnection _configuration;
|
||||
private readonly MongoClient _client;
|
||||
private readonly IMongoDatabase _database;
|
||||
|
||||
public DataClient(IOptions<DataAccessConnection> settings) {
|
||||
_configuration = settings.Value;
|
||||
_mongoSettings = GetMongoSettings();
|
||||
_client = new MongoClient(_mongoSettings);
|
||||
_database = _client.GetDatabase(_configuration.DatabaseName);
|
||||
}
|
||||
|
||||
public IMongoDatabase GetDatabase()
|
||||
{
|
||||
return _database;
|
||||
}
|
||||
|
||||
private MongoClientSettings GetMongoSettings()
|
||||
{
|
||||
MongoClientSettings settings = new()
|
||||
{
|
||||
Server = new MongoServerAddress(_configuration.Host, _configuration.Port),
|
||||
UseTls = true,
|
||||
SslSettings = new SslSettings()
|
||||
};
|
||||
settings.SslSettings.EnabledSslProtocols = SslProtocols.Tls12;
|
||||
|
||||
MongoIdentity identity = new MongoInternalIdentity(_configuration.DatabaseName, _configuration.UserName);
|
||||
MongoIdentityEvidence evidence = new PasswordEvidence(_configuration.Password);
|
||||
|
||||
settings.Credential = new MongoCredential("SCRAM-SHA-1", identity, evidence);
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using Landmark.OLA.Models.Loan;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public interface IBlobStorageAccess
|
||||
{
|
||||
bool SaveBlob(LoanApplicationFile file, byte[] fileBytes);
|
||||
|
||||
byte[] GetBlobAsBytes(LoanApplicationFile file);
|
||||
|
||||
string GetBlobAsBase64(LoanApplicationFile file);
|
||||
|
||||
bool DeleteBlob(LoanApplicationFile file);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using CRIF.ACTion.Services.Landmark.DistributionChannel;
|
||||
using Landmark.OLA.Models.Loan;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public interface IBranchDataAccess : IDistributionChannelLookupService
|
||||
{
|
||||
void Dispose();
|
||||
BranchConfig GetBranchConfig();
|
||||
void UpdateBranchConfig(BranchConfig branchConfig);
|
||||
void CreateBranchConfig(BranchConfig branchConfig);
|
||||
BranchNameConfig GetBranchNameConfig();
|
||||
void UpdateBranchNameConfig();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
using Landmark.OLA.Application.Common.Domain;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public interface IConfigurationAccess
|
||||
{
|
||||
void Dispose();
|
||||
StoredSettings GetStoredSettings();
|
||||
void UpdateStoredSettings(StoredSettings branchConfig);
|
||||
void CreateStoredSettings(StoredSettings branchConfig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public interface IDataClient
|
||||
{
|
||||
IMongoDatabase GetDatabase();
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using Landmark.OLA.Models.Loan;
|
||||
using Landmark.OLA.Models.Loan.Enums;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccessLayer
|
||||
{
|
||||
public interface ILoanApplicationDataAccess
|
||||
{
|
||||
void CreateContainer(LoanContainer loanContainer);
|
||||
void DeleteApplication(string id);
|
||||
void DeleteContainer(string id);
|
||||
void Dispose();
|
||||
List<LoanContainer> GetLoanContainers(Filter loanFilter);
|
||||
List<LoanContainer> GetAllMemberContainers(string memberId, string individualId);
|
||||
LoanContainer GetContainerById(string guid);
|
||||
string GetContainerIdByLoanId(string loanId);
|
||||
void UpdateContainer(LoanContainer loanContainer);
|
||||
void UpdateStatus(string id, LoanStatus status);
|
||||
void UpdateError(string id, LoanError error);
|
||||
void UpdateLoanId(string id, string loanId);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.NotificationsModels.Models;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public interface INotificationDao
|
||||
{
|
||||
Task SendEmailAsync(EmailRequest request);
|
||||
}
|
||||
}
|
||||
+426
@@ -0,0 +1,426 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using Serilog;
|
||||
using Landmark.OLA.Application.Common.Security;
|
||||
using Landmark.OLA.Application.Configuration;
|
||||
using Landmark.OLA.Application.DataAccess;
|
||||
using Landmark.OLA.Application.Services.MicroApiServices;
|
||||
using Landmark.OLA.Models.Loan;
|
||||
using Landmark.OLA.Models.Loan.Enums;
|
||||
using LCU.Library.Internal.NotificationsModels.Models;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccessLayer
|
||||
{
|
||||
public class LoanApplicationDataAccess : IDisposable, ILoanApplicationDataAccess
|
||||
{
|
||||
private bool disposed = false;
|
||||
private readonly IDataClient _client;
|
||||
private readonly INotificationsApiService _notificationsApiService;
|
||||
private readonly string _collectionName = "Applications";
|
||||
private readonly NotificationsApiConfiguration _notificationsApiConfiguration;
|
||||
private readonly Services.Email.IEmailTemplateService _emailTemplateService;
|
||||
|
||||
public LoanApplicationDataAccess(
|
||||
IDataClient dataClient,
|
||||
INotificationsApiService notificationsApiService,
|
||||
IOptions<NotificationsApiConfiguration> notificationsApiConfiguration,
|
||||
IWebHostEnvironment webHostEnvironment,
|
||||
Services.Email.IEmailTemplateService emailTemplateService)
|
||||
{
|
||||
_client = dataClient;
|
||||
_notificationsApiService = notificationsApiService;
|
||||
_notificationsApiConfiguration = notificationsApiConfiguration.Value;
|
||||
_emailTemplateService = emailTemplateService;
|
||||
}
|
||||
|
||||
|
||||
public LoanContainer GetContainerById(string guid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
var foundItems = collection.Find(eachContainer => eachContainer.Id == guid);
|
||||
if (foundItems.CountDocuments() != 1)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
return foundItems.First();
|
||||
}
|
||||
catch (MongoConnectionException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetContainerIdByLoanId(string loanId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
var foundItems = collection.Find(eachContainer => eachContainer.LoanId == loanId);
|
||||
if (foundItems.CountDocuments() != 1)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
return foundItems.First().Id;
|
||||
}
|
||||
catch (MongoConnectionException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<LoanContainer> GetAllMemberContainers(string memberId, string individualId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
var foundItems = collection.Find(eachContainer => eachContainer.MemberId == memberId && eachContainer.IndividualId == individualId && eachContainer.LoanApplication != null).ToList();
|
||||
|
||||
foreach (var container in foundItems)
|
||||
{
|
||||
MemberIdService.RemoveMemberId(container);
|
||||
}
|
||||
return foundItems;
|
||||
}
|
||||
catch (MongoConnectionException)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public List<LoanContainer> GetAllContainers()
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
return collection.Find(new BsonDocument()).ToList();
|
||||
}
|
||||
catch (MongoConnectionException)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public List<LoanContainer> GetLoanContainers(Filter filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection().Find(BuildFilter(filter)).Sort(BuildSorter(filter)).Limit(filter.Count).ToList();
|
||||
return collection;
|
||||
}
|
||||
catch (MongoConnectionException)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateContainer(LoanContainer loanContainer)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
|
||||
collection.InsertOne(loanContainer);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while creating container");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateContainer(LoanContainer loanContainer)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachLoan => eachLoan.Id == loanContainer.Id, loanContainer);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while updating container");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while updating container");
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteApplication(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
|
||||
var foundItems = collection.Find(eachContainer => eachContainer.Id == id);
|
||||
if (foundItems.CountDocuments() != 1)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
LoanContainer loanContainer = foundItems.First();
|
||||
loanContainer.LoanApplication = null;
|
||||
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachContainer => eachContainer.Id == loanContainer.Id, loanContainer);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while deleting application");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while deleting application");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateStatus(string id, LoanStatus status)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
|
||||
var foundItems = collection.Find(eachContainer => eachContainer.Id == id);
|
||||
if (foundItems.CountDocuments() != 1)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
LoanContainer loanContainer = foundItems.First();
|
||||
loanContainer.Status = status;
|
||||
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachContainer => eachContainer.Id == loanContainer.Id, loanContainer);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
if (status == LoanStatus.Vendor_Error || status == LoanStatus.Application_Error)
|
||||
{
|
||||
var reportId = id;
|
||||
|
||||
if ( loanContainer.LoanId != null)
|
||||
{
|
||||
reportId = loanContainer.LoanId;
|
||||
}
|
||||
|
||||
var contentHtml = "There was a " + status + " in loan application: " + reportId + ". <br><br>";
|
||||
|
||||
var request = new EmailRequest()
|
||||
{
|
||||
Subject = "Vendor Error In Loan Application",
|
||||
Recipient = _notificationsApiConfiguration.ErrorRecipients,
|
||||
Body = _emailTemplateService.BuildBrandedBody(contentHtml)
|
||||
};
|
||||
|
||||
_notificationsApiService.SendEmailAsync(request);
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while updating status");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while updating status");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateError(string id, LoanError error)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
|
||||
var foundItems = collection.Find(eachContainer => eachContainer.Id == id);
|
||||
if (foundItems.CountDocuments() != 1)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
LoanContainer loanContainer = foundItems.First();
|
||||
loanContainer.Error = error;
|
||||
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachContainer => eachContainer.Id == loanContainer.Id, loanContainer);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while updating error");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while updating error");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLoanId(string id, string loanId)
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
try
|
||||
{
|
||||
var foundItems = collection.Find(eachContainer => eachContainer.Id == id);
|
||||
if (foundItems.CountDocuments() != 1)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
LoanContainer loanContainer = foundItems.First();
|
||||
loanContainer.LoanId = loanId;
|
||||
|
||||
ReplaceOneResult result = collection.ReplaceOne(eachContainer => eachContainer.Id == loanContainer.Id, loanContainer);
|
||||
if (result.MatchedCount == 0 || result.ModifiedCount == 0)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while updating loan id");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while updating loan id");
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteContainer(string id)
|
||||
{
|
||||
var collection = GetLoanContainersCollection();
|
||||
try
|
||||
{
|
||||
DeleteResult result = collection.DeleteOne(_ => _.Id == id);
|
||||
if (result.DeletedCount != 1)
|
||||
{
|
||||
throw new KeyNotFoundException("Item not found");
|
||||
}
|
||||
}
|
||||
catch (KeyNotFoundException en)
|
||||
{
|
||||
Log.Error(en.Message);
|
||||
throw new KeyNotFoundException(en.Message);
|
||||
}
|
||||
catch (MongoException ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
throw new InvalidDataException("Error occured while deleting container");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new InvalidDataException("Error occured while deleting container");
|
||||
}
|
||||
}
|
||||
|
||||
private IMongoCollection<LoanContainer> GetLoanContainersCollection()
|
||||
{
|
||||
return _client.GetDatabase().GetCollection<LoanContainer>(_collectionName);
|
||||
}
|
||||
|
||||
private static FilterDefinition<LoanContainer> BuildFilter(Filter filter)
|
||||
{
|
||||
DateTime sDate = filter.StartDate.ToUniversalTime();
|
||||
DateTime eDate = filter.EndDate.ToUniversalTime();
|
||||
var builder = Builders<LoanContainer>.Filter;
|
||||
var filterValue = builder.Gt("Date", sDate) & builder.Lt("Date", eDate);
|
||||
for (int i = 0; i < filter.FilterField.Length; i++)
|
||||
{
|
||||
var field = filter.FilterField[i];
|
||||
if (field.NotEqual)
|
||||
{
|
||||
filterValue = filterValue & builder.Ne(field.Field, field.FilterValue);
|
||||
}
|
||||
else if (field.Equal)
|
||||
{
|
||||
filterValue = filterValue & builder.Eq(field.Field, field.FilterValue);
|
||||
}
|
||||
else if (field.GreaterThan)
|
||||
{
|
||||
filterValue = filterValue & builder.Gt(field.Field, field.FilterValue);
|
||||
}
|
||||
else if (field.LessThan)
|
||||
{
|
||||
filterValue = filterValue & builder.Lt(field.Field, field.FilterValue);
|
||||
}
|
||||
}
|
||||
return filterValue;
|
||||
}
|
||||
|
||||
private static string BuildSorter(Filter filter)
|
||||
{
|
||||
return "{ " + filter.SortField + ": " + (filter.SortDesc ? "-1}" : "1}");
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Landmark.OLA.Application.Configuration;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.Library.Internal.NotificationsModels.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
public class NotificationDao : INotificationDao
|
||||
{
|
||||
private readonly NotificationsApiConfiguration _configuration;
|
||||
private readonly IPostRequest _postRequest;
|
||||
|
||||
public NotificationDao(IOptions<NotificationsApiConfiguration> configuration, IPostRequest postRequest)
|
||||
{
|
||||
_configuration = configuration.Value;
|
||||
_postRequest = postRequest;
|
||||
}
|
||||
|
||||
public async Task SendEmailAsync(EmailRequest request)
|
||||
=> await _postRequest.Async(new Uri(_configuration.SendEmailEndpointUrl), request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user