public async Task <ArrangementRequest> SetAcceptedValues(long applicationNumber, int arrangementRequestId, AcceptedValues command, Application application) { var arrRequest = _context.ArrangementRequests.Include(ar => ar.ProductSnapshotDb).Where(p => p.ApplicationId == applicationNumber && p.ArrangementRequestId == arrangementRequestId).FirstOrDefault(); if (arrRequest == null) { throw new KeyNotFoundException("Requested arrangement does not exist for provided application."); } AcceptedValues acceptedValues = new AcceptedValues(); if (arrRequest is TermLoanRequest tlr) { acceptedValues.Annuity = command.Annuity; tlr.Annuity = command.Annuity; if (command.DownpaymentAmount != null) { tlr.DownpaymentAmount = command.DownpaymentAmount.Value; tlr.DownpaymentPercentage = command.DownpaymentPercentage.Value; tlr.InvoiceAmount = command.InvoiceAmount.Value; } } if (arrRequest is FinanceServiceArrangementRequest fsa) { acceptedValues.Amount = command.Amount; acceptedValues.Term = Utility.GetMonthsFromPeriod(command.Term).ToString(); acceptedValues.Napr = command.Napr; if (command.DownpaymentAmount != null) { acceptedValues.DownpaymentAmount = command.DownpaymentAmount.Value; acceptedValues.DownpaymentPercentage = command.DownpaymentPercentage.Value; acceptedValues.InvoiceAmount = command.InvoiceAmount.Value; } fsa.Amount = command.Amount; fsa.Term = Utility.GetMonthsFromPeriod(command.Term).ToString(); } arrRequest.AcceptedValues = acceptedValues; var conversionMethod = _configurationService.GetEffective("offer/fee-currency-conversion-method", "Buy to middle").Result; arrRequest.CalculateOffer(application, _priceCalculator, conversionMethod); var res = await _context.SaveEntitiesAsync(); var messageObj = _messageEventFactory.CreateBuilder("offer", "accepted-values-setted").Build(); _bus.Publish(messageObj); return(arrRequest); }
public override ValueTypeInterpreteResult Interprete(string param) => new ValueTypeInterpreteResult(AcceptedValues.Contains(param), param);
public async Task <IActionResult> SetAcceptedValues([FromRoute] long applicationNumber, [FromRoute] int arrangementRequestId, [FromBody] AcceptedValues command) { try { var application = await _applicationRepository.GetAsync(applicationNumber); if (application != null) { var setAcceptedValues = await _arrangementRequestRepository .SetAcceptedValues(applicationNumber, arrangementRequestId, command, application); if (setAcceptedValues == null) { return(NotFound()); } return(Ok()); } else { return(NotFound()); } } catch (KeyNotFoundException e) { this._logger.LogError(e, "An error occurred while updating Arrangement Request for arrangementRequestId {arrangementRequestId} on application {ApplicationNumber}", arrangementRequestId, applicationNumber); return(BadRequest(new { message = e.Message })); } catch (Exception e) { this._logger.LogError(e, "An error occurred while updating Arrangement Request for arrangementRequestId {arrangementRequestId} on application {ApplicationNumber}", arrangementRequestId, applicationNumber); return(StatusCode(500)); } }