public async Task <bool> Handle(UpdateOrganisationRequest request, CancellationToken cancellationToken) { request.LegalName = _textSanitiser.SanitiseInputText(request.LegalName); request.TradingName = _textSanitiser.SanitiseInputText(request.TradingName); var command = new UpdateOrganisationCommand { OrganisationId = request.OrganisationId, OrganisationTypeId = request.OrganisationTypeId, ApplicationDeterminedDate = request.ApplicationDeterminedDate, CharityNumber = request.CharityNumber, CompanyNumber = request.CompanyNumber, LegalName = request.LegalName, ProviderTypeId = request.ProviderTypeId, TradingName = request.TradingName, Username = request.Username }; _logger.LogInformation($@"Handling Update organisation for Organisation ID [{request.OrganisationId}]"); var errorMessage = _organisationValidator.ValidateOrganisation(command); if (!string.IsNullOrEmpty(errorMessage?.Message)) { _logger.LogInformation($@"Update organisation for Organisation ID [{request.OrganisationId}] failed validation because {errorMessage.Message}"); throw new BadRequestException(errorMessage.Message); } var auditChanges = _auditLogService.AuditOrganisation(command); if (auditChanges is null) { _logger.LogInformation($@"Update organisation for Organisation ID [{request.OrganisationId}] not applied as no differences found"); return(true); } var success = await _updateOrganisationRepository.UpdateOrganisation(command); if (!success) { _logger.LogInformation($@"Update organisation for Organisation ID [{request.OrganisationId}] not applied as no update made on an existing record"); return(false); } var fieldsAuditWritten = await _updateOrganisationRepository.WriteFieldChangesToAuditLog(auditChanges); if (!fieldsAuditWritten) { _logger.LogInformation($@"Update organisation audit for Organisation ID [{request.OrganisationId}] not applied as no insertion made on Audit table"); return(await Task.FromResult(false)); } return(true); }