public async Task <bool> Handle(UpdateOrganisationApplicationDeterminedDateRequest request, CancellationToken cancellationToken)
        {
            if (!_validator.IsValidApplicationDeterminedDate(request.ApplicationDeterminedDate))
            {
                var invalidApplicationDeterminedDate = $@"Invalid Application Determined Date '{request.ApplicationDeterminedDate}'";
                _logger.LogInformation(invalidApplicationDeterminedDate);
                throw new BadRequestException(invalidApplicationDeterminedDate);
            }

            _logger.LogInformation($@"Handling Update '{FieldChanged}' for Organisation ID [{request.OrganisationId}]");

            var auditRecord = _auditLogService.AuditApplicationDeterminedDate(request.OrganisationId, request.UpdatedBy, request.ApplicationDeterminedDate);

            if (!auditRecord.ChangesMade)
            {
                return(await Task.FromResult(false));
            }

            var success = await _updateOrganisationRepository.UpdateApplicationDeterminedDate(request.OrganisationId, request.ApplicationDeterminedDate, request.UpdatedBy);

            if (!success)
            {
                return(await Task.FromResult(false));
            }

            return(await _updateOrganisationRepository.WriteFieldChangesToAuditLog(auditRecord));
        }
Esempio n. 2
0
        public async Task <bool> Handle(UpdateOrganisationApplicationDeterminedDateRequest request, CancellationToken cancellationToken)
        {
            if (!_validator.IsValidApplicationDeterminedDate(request.ApplicationDeterminedDate))
            {
                var invalidApplicationDeterminedDate = $@"Invalid Application Determined Date '{request.ApplicationDeterminedDate}'";
                _logger.LogInformation(invalidApplicationDeterminedDate);
                throw new BadRequestException(invalidApplicationDeterminedDate);
            }

            _logger.LogInformation($@"Handling Update '{FieldChanged}' for Organisation ID [{request.OrganisationId}]");

            var auditRecord = _auditLogService.AuditApplicationDeterminedDate(request.OrganisationId, request.UpdatedBy, request.ApplicationDeterminedDate);

            if (!auditRecord.ChangesMade)
            {
                _logger.LogInformation($@"Update organisation application determined date for Organisation ID [{request.OrganisationId}] not applied as no differences found between dates (date [{request.ApplicationDeterminedDate}])");
                return(await Task.FromResult(false));
            }

            var success = await _updateOrganisationRepository.UpdateApplicationDeterminedDate(request.OrganisationId, request.ApplicationDeterminedDate, request.UpdatedBy);

            if (!success)
            {
                _logger.LogInformation($@"Update organisation application determined date for Organisation ID [{request.OrganisationId}] not applied as no update made on an existing record");
                return(await Task.FromResult(false));
            }

            var fieldsAuditWritten = await _updateOrganisationRepository.WriteFieldChangesToAuditLog(auditRecord);

            if (!fieldsAuditWritten)
            {
                _logger.LogInformation($@"Update organisation application determined date audit for Organisation ID [{request.OrganisationId}] not applied as no insertion made on Audit table");
                return(await Task.FromResult(false));
            }

            return(true);
        }