private CdsEntity BuildCdsEntity(CollateralAssetBase assertRequestResponse, string cr_reference_id, bool skipId = false) { var collateral = new CdsEntity(); Guid collateralId = Guid.Empty; if (skipId == false && Guid.TryParse(cr_reference_id, out collateralId) == false) { throw new Exception(_invalidCrReferenceIdError); } else if (skipId == false) { collateral.Attributes["msfsi_collateralid"] = collateralId; collateral.Id = collateralId; } if (string.IsNullOrEmpty(assertRequestResponse.CollateralAssetType) == false) { collateral.Attributes["msfsi_collateraltype"] = ParseCollateralType(assertRequestResponse.CollateralAssetType); } if (string.IsNullOrEmpty(assertRequestResponse.CollateralAssetDescription) == false) { collateral.Attributes["msfsi_description"] = assertRequestResponse.CollateralAssetDescription; } if (string.IsNullOrEmpty(assertRequestResponse.CollateralAssetTitle) == false) { collateral.Attributes["msfsi_name"] = assertRequestResponse.CollateralAssetTitle; } return(collateral); }
public void Cds_entity_must_include_at_least_display_name() { var contact = new CdsEntity(); var validator = new CdsEntityValidator(); var result = validator.Validate(contact); result.IsValid.Should().Be(false, "display name is mandatory"); }
public Task <RecordCollateralAssetAdministrativePlanResponse> RecordCollateralAssetAdministrativePlanAsync(string cr_reference_id, RecordCollateralAssetAdministrativePlanRequest body) { return(Task.Run <RecordCollateralAssetAdministrativePlanResponse>(() => { var collateral = new CdsEntity(); if (Guid.TryParse(cr_reference_id, out Guid collateralId) == false) { throw new Exception(_invalidCrReferenceIdError); } else { collateral.Id = collateralId; } if (string.IsNullOrEmpty(body.EmpolyeeBusinessUnitReference) == false) { if (Guid.TryParse(body.EmpolyeeBusinessUnitReference, out var businessUnitId) == false) { throw new Exception("EmpolyeeBusinessUnitReference must be specified as a valid GUID"); } else { var businessUnit = _cdsWebApi.Retrieve("businessunits", businessUnitId, "name"); collateral.Attributes["msfsi_evaluatedby"] = $"{businessUnit.Attributes["name"]} Team"; } } if (string.IsNullOrEmpty(body.RecordingRecordDateTime) == false) { if (DateTime.TryParse(body.RecordingRecordDateTime, out var recordingDateTime) == false) { throw new Exception("RecordingRecordDateTime must be specified as a valid DateTime"); } else { collateral.Attributes["msfsi_dateofvaluation"] = recordingDateTime; collateral.Attributes["msfsi_nextdateofvaluation"] = recordingDateTime.AddYears(1); } } if (string.IsNullOrEmpty(body.RecordingRecordType) == false) { collateral.Attributes["msfsi_description"] = body.RecordingRecordType; } if (collateral.Attributes.Count > 0) { _cdsWebApi.Update("msfsi_collaterals", collateral); } return new RecordCollateralAssetAdministrativePlanResponse() { RecordingRecordReference = collateral.Id.ToString(), RecordingRecordStatus = "Applied" }; })); }
private Task <ExecuteConsumerLoanFulfillmentArrangementWithdrawalResponse> CreateUpdateWithdrawal(string cr_reference_id, ExecuteConsumerLoanFulfillmentArrangementWithdrawalRequest body, Func <Guid> retrieveWithdrawalId = null) { return(Task.Run(() => { if (body == null) { return new ExecuteConsumerLoanFulfillmentArrangementWithdrawalResponse(); } var loanId = ParseGuid(cr_reference_id, "cr_reference_id"); ValidateCurrencyIsUSD(body.Currency, body.Amount?.Currency); var disbursment = new CdsEntity() { Id = loanId, Attributes = { ["msfsi_loanid"] = new CdsEntityReference("msfsi_financialproducts", loanId) } }; if (retrieveWithdrawalId == null || string.IsNullOrEmpty(body.ValueDate) == false) { disbursment.Attributes["msfsi_name"] = $"Withdrawal - {body.ValueDate ?? DateTime.Now.ToString(_dateTimeFormat)}";; } SetDecimalField(disbursment, body?.Amount?.Value, "Amount Value", "msfsi_amount"); if (string.IsNullOrEmpty(body.PayeeBankReference) == false) { disbursment.Attributes["msfsi_bankid"] = FindBank(body.PayeeBankReference); } Guid id; if (retrieveWithdrawalId == null) { id = _cdsWebApi.Create("msfsi_syndicateses", disbursment); } else { id = retrieveWithdrawalId(); disbursment.Id = id; _cdsWebApi.Update("msfsi_syndicateses", disbursment); } return new ExecuteConsumerLoanFulfillmentArrangementWithdrawalResponse() { Amount = body.Amount, Currency = body.Currency, CustomerReference = body.CustomerReference, WithdrawlInstructionReference = id.ToString(), PayeeBankReference = body.PayeeBankReference, PayeeProductInstanceReference = body.PayeeProductInstanceReference, PayeeReference = body.PayeeReference, ValueDate = body.ValueDate }; })); }
public void Invalid_entity_should_return_false() { var contact = new CdsEntity() { DisplayName = "Contact" }; var validator = new CdsEntityValidator(); var result = validator.Validate(contact); result.IsValid.Should().Be(true); }
private string BuildValuationHistory(CdsEntity collateral) { var validValuationDate = DateTime.TryParse( collateral.Attributes["msfsi_dateofvaluation"]?.ToString(), out DateTime valuationDate); var validValue = decimal.TryParse( collateral.Attributes["msfsi_collateralvalue"]?.ToString(), out decimal valuation); return($"{(validValuationDate ? valuationDate.ToString("yyyy") : "Unknown Year")}-{(validValue ? $"${valuation}" : "Not Valued")}"); }
private void SetDatetimeField(CdsEntity record, string datetimeValue, string paramaterName, string fieldName) { if (string.IsNullOrEmpty(datetimeValue) == false) { if (DateTime.TryParse(datetimeValue, out var parsedValue) == false) { throw new Exception($"{paramaterName} must be a validate date/time"); } record.Attributes[fieldName] = parsedValue; } }
private void SetDecimalField(CdsEntity record, string decimalValue, string parameterName, string fieldName, params string[] additionalFieldNames) { if (string.IsNullOrEmpty(decimalValue) == false) { if (decimal.TryParse(decimalValue, out var parsedValue) == false) { throw new Exception($"{parameterName} must be a valid decimal number."); } record.Attributes[fieldName] = parsedValue; foreach (var additionalField in additionalFieldNames) { record.Attributes[additionalField] = parsedValue; } } }
private CdsEntity PrepareLoanForExecution(string cr_reference_id, ExecutionBase body, string dateField, string amountField, bool overwriteAmount = true) { var loanId = ParseGuid(cr_reference_id, "cr_reference_id"); ValidateCurrencyIsUSD(body.Currency, body.Amount?.Currency); var loan = new CdsEntity() { Id = loanId }; if (string.IsNullOrEmpty(dateField) == false) { SetDatetimeField(loan, body.ValueDate, "ValueDate", dateField); } if (string.IsNullOrEmpty(amountField) == false && string.IsNullOrEmpty(body?.Amount?.Value) == false) { if (decimal.TryParse(body.Amount.Value, out var amount) == false) { throw new Exception("Amount must be a valid decimal number."); } if (overwriteAmount == false) { var existingLoan = _cdsWebApi.Retrieve("msfsi_financialproducts", loanId, amountField); if (decimal.TryParse(existingLoan.Attributes[amountField]?.ToString(), out var currentAmount)) { amount += currentAmount; } } loan.Attributes[amountField] = amount; } return(loan); }
private Task <ConsumerLoanFulfillmentArrangementResponse> CreateUpdateLoan(InitiateConsumerLoanFulfillmentArrangementRequest body, string cr_reference_id = null) { return(Task.Run(() => { if (body == null) { return new ConsumerLoanFulfillmentArrangementResponse(); } var loan = new CdsEntity(); if (string.IsNullOrEmpty(cr_reference_id) == false) { loan.Id = ParseGuid(cr_reference_id, "cr_reference_id"); } if (string.IsNullOrEmpty(body.LoanType) == false) { int loanType; switch (body.LoanType.ToLower().Trim()) { case "new": loanType = 104800000; break; case "top-up": loanType = 104800001; break; case "buy-out": loanType = 104800002; break; default: throw new Exception($"Unknown Loan Type {body.LoanType}."); } loan.Attributes["msfsi_loantype"] = loanType; } if (string.IsNullOrEmpty(body.LoanApplicableRate) == false) { loan.Attributes["msfsi_interestrate"] = ParsePercentage(body.LoanApplicableRate, "LoanApplicableRate"); } if (string.IsNullOrEmpty(body.CustomerReference) == false) { var customerId = ParseGuid(body.CustomerReference, "CustomerReference"); var accounts = _cdsWebApi.RetrieveMultiple("accounts", $@"<fetch top='1'> <entity name='account'> <attribute name='accountid' /> <filter> <condition attribute='accountid' operator='eq' value='{customerId}' /> </filter> </entity> </fetch>"); string entitySetName; string entityName; if (accounts.Count() > 0) { entitySetName = "accounts"; entityName = "account"; } else { var contacts = _cdsWebApi.RetrieveMultiple("contacts", $@"<fetch top='1'> <entity name='contact'> <attribute name='contactid' /> <filter> <condition attribute='contactid' operator='eq' value='{customerId}' /> </filter> </entity> </fetch>"); if (contacts.Count() == 0) { throw new Exception($"Unknown CustomerReference {body.CustomerReference}"); } entitySetName = "contacts"; entityName = "contact"; } loan.Attributes[$"msfsi_customerid_{entityName}"] = new CdsEntityReference(entitySetName, customerId); } if (string.IsNullOrEmpty(cr_reference_id) == false) { SetDecimalField(loan, body.LoanOutstandingBalance, "LoanOutstandingBalance", "msfsi_principalamount", "msfsi_outstandingtotalamount"); } else { SetDecimalField(loan, body.LoanOutstandingBalance, "LoanOutstandingBalance", "msfsi_outstandingtotalamount"); } SetDatetimeField(loan, body.LoanMaturityDate, "LoanMaturityDate", "msfsi_loanmaturitydate"); SetDatetimeField(loan, body.LoanOriginationDate, "LoanOriginationDate", "msfsi_loanstartdate"); Guid loanId; if (string.IsNullOrEmpty(cr_reference_id)) { loan.Attributes.Add("msfsi_productfamilyid", new CdsEntityReference("products", _familyId)); JObject settings; var fileInfo = _environment.ContentRootFileProvider.GetFileInfo("appsettings.json"); using (var streamReader = new StreamReader(fileInfo.CreateReadStream())) { settings = JObject.Parse(streamReader.ReadToEnd()); } var loanNumber = int.Parse(settings.Property("LastLoanNumber").Value.ToString()) + 1; loan.Attributes["msfsi_number"] = loanNumber.ToString(); loanId = _cdsWebApi.Create("msfsi_financialproducts", loan); settings.Property("LastLoanNumber").Value = loanNumber; using (var streamWriter = new StreamWriter(fileInfo.PhysicalPath)) { streamWriter.Write(settings.ToString()); } } else { _cdsWebApi.Update("msfsi_financialproducts", loan); loanId = loan.Id; } return new ConsumerLoanFulfillmentArrangementResponse() { BankAccountingUnitReference = body.BankAccountingUnitReference, BankBranchLocationReference = body.BankBranchLocationReference, CollateralAllocation = body.CollateralAllocation, CollateralReference = body.CollateralReference, ConfigurationOptions = body.ConfigurationOptions, CustomerAgreementReference = body.CustomerAgreementReference, CustomerCommentary = body.CustomerCommentary, CustomerCreditAssessmentReference = body.CustomerCreditAssessmentReference, CustomerReference = body.CustomerReference, DelinquencyCollectionReference = body.DelinquencyCollectionReference, InsuranceReference = body.InsuranceReference, InterestAccrualMethod = body.InterestAccrualMethod, InterestType = body.InterestType, InvolvedPartyObligationEntitlement = body.InvolvedPartyObligationEntitlement, InvolvedPartyReference = body.InvolvedPartyReference, LoanAccessTerms = body.LoanAccessTerms, LoanAmount = body.LoanAmount, LoanApplicableRate = body.LoanApplicableRate, LoanCurrency = body.LoanCurrency, LoanMaturityDate = body.LoanMaturityDate, LoanOriginationDate = body.LoanOriginationDate, LoanOutstandingBalance = body.LoanOutstandingBalance, LoanRateType = body.LoanRateType, LoanRepaymentSchedule = body.LoanRepaymentSchedule, LoanStatus = "active", LoanType = body.LoanType, PartyReference = body.PartyReference, ProductInstanceReference = loanId.ToString(), RepaymentType = body.RepaymentType, StagedRepaymentStatement = body.StagedRepaymentStatement, TaxReference = body.TaxReference }; })); }