Adding
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.LoanRateModels.Entities;
|
||||
using LCU.Library.Internal.LoanRateModels.Requests;
|
||||
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses;
|
||||
|
||||
public class InitiateRatesEvaluationsResponse
|
||||
{
|
||||
public bool Success { get; set; } = true;
|
||||
public InitiateRatesEvaluationsRequest Request { get; set; }
|
||||
public List<RateEvaluation> RateEvaluationResults { get; set; } = new();
|
||||
public List<string> Messages { get; set; } = new();
|
||||
|
||||
}
|
||||
|
||||
public static class InitiateRatesEvaluationsResponseUtilities
|
||||
{
|
||||
public static InitiateRatesEvaluationsResponse AddSuccessMessage(this InitiateRatesEvaluationsResponse response, string message)
|
||||
{
|
||||
response.Success = true;
|
||||
response.Messages.Add(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static InitiateRatesEvaluationsResponse AddFailureMessage(this InitiateRatesEvaluationsResponse response, string message)
|
||||
{
|
||||
response.Success = false;
|
||||
response.Messages.Add(message);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses;
|
||||
|
||||
public class RateResponse
|
||||
{
|
||||
public bool Success { get; set; } = true;
|
||||
public decimal Rate { get; set; }
|
||||
public List<string> Messages { get; set; } = new();
|
||||
}
|
||||
|
||||
public static class RateResponseUtilities
|
||||
{
|
||||
private const decimal RateDefaultValue = (decimal)99.0;
|
||||
|
||||
public static RateResponse AddErrorMessage(this RateResponse rateResponse, string message)
|
||||
{
|
||||
rateResponse.Messages.Add(message);
|
||||
rateResponse.Success = false;
|
||||
return rateResponse;
|
||||
}
|
||||
|
||||
public static RateResponse AddErrorMessage(this RateResponse rateResponse, IEnumerable<string> message)
|
||||
{
|
||||
rateResponse.Messages.AddRange(message);
|
||||
return rateResponse;
|
||||
}
|
||||
|
||||
public static RateResponse SetDefault(this RateResponse rateResponse)
|
||||
{
|
||||
return new RateResponse
|
||||
{
|
||||
Messages = rateResponse.Messages,
|
||||
Rate = RateDefaultValue
|
||||
};
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using LCU.Library.Internal.LCUFilterModels.Pagination;
|
||||
using LCU.Library.Internal.LoanRateModels.Entities;
|
||||
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses;
|
||||
|
||||
public class RateUploadInfoFilterResponse : PagedResponse<RateUploadInfo>
|
||||
{
|
||||
public RateUploadInfoFilterResponse() { }
|
||||
|
||||
public RateUploadInfoFilterResponse(RateUploadInfoFilterResult pagedResult, RateUploadInfoFilter filter)
|
||||
{
|
||||
TotalCount = pagedResult.TotalCount;
|
||||
LatestRateUploadInfo = pagedResult.LatestRateUploadInfo;
|
||||
PagedResponse = new PagedResponse<RateUploadInfo>(pagedResult, filter);
|
||||
}
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
public RateUploadInfo LatestRateUploadInfo { get; set; }
|
||||
public PagedResponse<RateUploadInfo> PagedResponse { get; set; }
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using LCU.Library.Internal.LCUFilterModels.Pagination;
|
||||
using LCU.Library.Internal.LoanRateModels.Entities;
|
||||
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses;
|
||||
|
||||
public class RateUploadInfoFilterResult : PagedResult<RateUploadInfo>
|
||||
{
|
||||
public int TotalCount { get; set; }
|
||||
public RateUploadInfo LatestRateUploadInfo { get; set; }
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses.Validation.RateSheetValidations;
|
||||
public static class RateSheetValidation
|
||||
{
|
||||
public static RateSheetValidationItem IsWithinTrendRange(decimal oldValue, decimal newValue, List<decimal> history)
|
||||
{
|
||||
var validation = new RateSheetValidationItem
|
||||
{
|
||||
Label = "Within Trend Range",
|
||||
Description = "If there is a history of change, is the current trend within the trend history's max and min values.",
|
||||
RateSheetValidationType = RateSheetValidationTypes.IsWithinTrendRange
|
||||
};
|
||||
|
||||
if (newValue == 0 || oldValue == 0)
|
||||
{
|
||||
validation.Pass = false;
|
||||
validation.Message = $"Values cannot be zero. OldValue: {oldValue} | NewValue: {newValue}";
|
||||
return validation;
|
||||
}
|
||||
|
||||
var currentTrend = oldValue / newValue;
|
||||
var trends = history.Zip(history.Skip(1), (x, y) => y / x).ToList();
|
||||
|
||||
var currentTrendString = Math.Round(currentTrend * 100, 2).ToString("0.##");
|
||||
var minTrendString = Math.Round(trends.Min() * 100, 2).ToString("0.##");
|
||||
var maxTrendString = Math.Round(trends.Max() * 100, 2).ToString("0.##");
|
||||
|
||||
validation.Value = currentTrendString;
|
||||
validation.Formula = trends.Count == 0
|
||||
? "No history found"
|
||||
: $"{currentTrendString} >= {minTrendString} && {currentTrendString} <= {maxTrendString}";
|
||||
validation.Criteria = trends.Count == 0
|
||||
? "No history found"
|
||||
: $"{minTrendString}% - {maxTrendString}%";
|
||||
validation.Pass = trends.Count == 0 || currentTrend >= trends.Min() && currentTrend <= trends.Max();
|
||||
return validation;
|
||||
}
|
||||
|
||||
public static RateSheetValidationItem IsWithinRange(decimal value, decimal min, decimal max)
|
||||
=> new()
|
||||
{
|
||||
Label = "Within Range",
|
||||
Description = "Value is within the min and max values.",
|
||||
Value = value.ToString("0.##"),
|
||||
Formula = $"{value:0.##} >= {min:0.##} && {value:0.##} <= {max:0.##}",
|
||||
Criteria = $"{min:0.##} - {max:0.##}",
|
||||
Pass = value >= min && value <= max,
|
||||
RateSheetValidationType = RateSheetValidationTypes.IsWithinRange
|
||||
};
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses.Validation.RateSheetValidations;
|
||||
public class RateSheetValidationItem : ValidationItem
|
||||
{
|
||||
public RateSheetValidationTypes RateSheetValidationType { get; set; }
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.LoanRateModels.Entities;
|
||||
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses.Validation.RateSheetValidations;
|
||||
public class RateSheetValidationResult : ValidationResult<Rate, RateSheetValidationItem>
|
||||
{
|
||||
public override List<RateSheetValidationItem> Validations { get; set; }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses.Validation.RateSheetValidations;
|
||||
public enum RateSheetValidationTypes
|
||||
{
|
||||
IsWithinTrendRange,
|
||||
IsWithinRange
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses.Validation;
|
||||
public class ValidationItem
|
||||
{
|
||||
public string Label { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Criteria { get; set; } = string.Empty;
|
||||
public string Formula { get; set; } = string.Empty;
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public bool Pass { get; set; }
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LCU.Library.Internal.LoanRateModels.Responses.Validation;
|
||||
public class ValidationResult<TEntity, TValidationItem> where TValidationItem : ValidationItem
|
||||
{
|
||||
public TEntity NewItem { get; set; }
|
||||
public TEntity? OriginalItem { get; set; }
|
||||
public virtual List<TValidationItem> Validations { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public bool Pass { get; set; } = true;
|
||||
|
||||
public List<string> ValidationMessages => Validations.Where(x => !string.IsNullOrWhiteSpace(x.Message))
|
||||
.Select(x => x.Message).ToList();
|
||||
public List<TValidationItem> PassedValidations => Validations.Where(x => x.Pass).ToList();
|
||||
public List<TValidationItem> FailedValidations => Validations.Where(x => !x.Pass).ToList();
|
||||
public double Percentage => Math.Round(((double)PassedValidations.Count / Validations.Count) * 100, 2);
|
||||
|
||||
public bool CheckValidation()
|
||||
{
|
||||
Pass = Validations.Count == 0 || Validations.All(x => x.Pass);
|
||||
return Pass;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user