public async Task <IActionResult> UpdateArrangementRequestsForApplication([FromRoute] long applicationNumber, [FromRoute] int arrangementRequestId, [FromBody] ArrangementRequest command) { var updateArrangementRequest = new UpdateArrangementRequestCommand { ArrangementRequest = command, ApplicationNumber = applicationNumber, ArrangementRequestId = arrangementRequestId }; var updateCustomerCommand = new IdentifiedCommand <UpdateArrangementRequestCommand, CommandStatus <bool> >(updateArrangementRequest, new Guid()); var commandResult = await _mediator.Send(updateCustomerCommand); if (commandResult.CommandResult == StandardCommandResult.OK) { return(Ok()); } else if (commandResult.CommandResult == StandardCommandResult.NOT_FOUND) { return(NotFound()); } else if (commandResult.CommandResult == StandardCommandResult.BAD_REQUEST) { return(BadRequest(commandResult.Exception.Message)); } else { return(StatusCode(500)); } }
public async Task <CommandStatus> Handle(ContinueApplicationCommand request, CancellationToken cancellationToken) { var application = await _applicationRepository.GetAsync(request.ApplicationNumber, "involved-parties"); if (application == null) { return(new CommandStatus { CommandResult = StandardCommandResult.NOT_FOUND }); } application.CustomerApplied = true; _applicationRepository.Update(application); var result = await _applicationRepository.UnitOfWork.SaveEntitiesAsync(); if (request.ArrangementRequests != null) { foreach (var arrangementRequest in request.ArrangementRequests) { var updateArrangementRequest = new UpdateArrangementRequestCommand { ArrangementRequest = arrangementRequest, ApplicationNumber = request.ApplicationNumber, ArrangementRequestId = arrangementRequest.ArrangementRequestId }; var updateCustomerCommand = new IdentifiedCommand <UpdateArrangementRequestCommand, CommandStatus <bool> >(updateArrangementRequest, new Guid()); var commandResult = await _mediator.Send(updateCustomerCommand); if (commandResult.CommandResult != StandardCommandResult.OK) { _logger.LogWarning("Unsuccessfully update ArrangementRequest from continue application with application number: {0} and arrangement request id: {1}", request.ApplicationNumber, arrangementRequest.ArrangementRequestId); return(new CommandStatus { CommandResult = StandardCommandResult.BAD_REQUEST, CustomError = "Unsuccessfully update ArrangementRequest with application number: " + request.ApplicationNumber + " and arrangement request id: " + arrangementRequest.ArrangementRequestId }); } } } string activeStatuses = await _configurationService.GetEffective("offer/active-statuses", "draft,active,approved,accepted"); List <ApplicationStatus> statusList = null; if (!string.IsNullOrEmpty(activeStatuses)) { statusList = EnumUtils.GetEnumPropertiesForListString <ApplicationStatus>(activeStatuses); } var rolesList = EnumUtils.GetEnumPropertiesForListString <PartyRole>("customer"); Party party; if (!string.IsNullOrEmpty(application.CustomerNumber)) { long partyId = application.InvolvedParties.Where(p => p.CustomerNumber.Equals(application.CustomerNumber)).FirstOrDefault().PartyId; party = await _involvedPartyRepository.GetPartyGeneralInformation(application.ApplicationId, int.Parse(partyId.ToString())); } else { party = application.InvolvedParties.FirstOrDefault(); } int activeOffers = 0; if (party.Username != null) { activeOffers = _applicationRepository.CheckExistingOffersForProspect(party.Username, party.EmailAddress, statusList, rolesList).Count; } var messageObj = _messageEventFactory.CreateBuilder("offer", "offer-initiated"); messageObj = messageObj.AddBodyProperty("initiator", request.Username) .AddBodyProperty("channel", application.ChannelCode) .AddBodyProperty("product-code", application.ProductCode) .AddBodyProperty("product-name", application.ProductName) .AddBodyProperty("email", party.EmailAddress) .AddBodyProperty("active-offers", activeOffers) .AddBodyProperty("preferential-price", application.PreferencialPrice) .AddBodyProperty("term-limit-breached", application.TermLimitBreached) .AddBodyProperty("amount-limit-breached", application.AmountLimitBreached) .AddBodyProperty("originates-bundle", application.OriginatesBundle) .AddBodyProperty("party-id", application.InvolvedParties.Where(x => x.PartyRole == PartyRole.Customer).FirstOrDefault()?.PartyId); if (application.Status == ApplicationStatus.Approved) { messageObj.AddBodyProperty("initiation-point", "offered"); } else { messageObj.AddBodyProperty("initiation-point", "preapproved"); } if (application.LeadId != null) { var status = Enum.GetName(typeof(ApplicationStatus), application.Status); messageObj.AddBodyProperty("lead-id", application.LeadId) .AddBodyProperty("status", status); } var customerSegment = application.InvolvedParties.Where(x => x.PartyRole == PartyRole.Customer).FirstOrDefault()?.CustomerSegment; if (customerSegment == null) { customerSegment = await _configurationService.GetEffective("party/default-segment/individual", "professional"); } if (!string.IsNullOrEmpty(application.CustomerNumber)) { messageObj = messageObj.AddBodyProperty("customer-number", application.CustomerNumber) .AddBodyProperty("customer-segment", customerSegment); } else { if (party.PartyKind == PartyKind.Individual) { messageObj.AddBodyProperty("given-name", ((IndividualParty)party).GivenName) .AddBodyProperty("family-name", ((IndividualParty)party).Surname); } else { messageObj.AddBodyProperty("given-name", null) .AddBodyProperty("family-name", null); } messageObj = messageObj.AddBodyProperty("customer-name", party.CustomerName) .AddBodyProperty("personal-identification-number", party.IdentificationNumber) .AddBodyProperty("country-code", application.CountryCode) .AddBodyProperty("customer-segment", customerSegment); } messageObj = messageObj.AddHeaderProperty("application-number", application.ApplicationNumber); _logger.LogInformation("Sending offer initiated event to broker on topic {BrokerTopicName} for application: {ApplicationNumber}", "offer", application.ApplicationNumber); _eventBus.Publish(messageObj.Build()); if (request.AuditLog) { await _auditClient.WriteLogEntry(AuditLogEntryAction.Apply, AuditLogEntryStatus.Success, "application", application.ApplicationNumber, "Applied for application", new { }); } return(new CommandStatus { CommandResult = StandardCommandResult.OK }); }