Пример #1
0
        public async Task <bool> Handle(UpdateOrganisationStatusRequest request, CancellationToken cancellationToken)
        {
            ValidateUpdateStatusRequest(request);

            var auditData = _auditLogService.AuditOrganisationStatus(request.OrganisationId, request.UpdatedBy,
                                                                     request.OrganisationStatusId, request.RemovedReasonId);

            var success = false;

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

            if (auditData.FieldChanges.Any(x => x.FieldChanged == AuditLogField.OrganisationStatus))
            {
                success = await _updateOrganisationRepository.UpdateOrganisationStatus(request.OrganisationId,
                                                                                       request.OrganisationStatusId, request.UpdatedBy);

                if (success)
                {
                    var providerTypeId = await _organisationRepository.GetProviderType(request.OrganisationId);

                    if (providerTypeId != ProviderType.SupportingProvider)
                    {
                        success = await _eventsRepository.AddOrganisationStatusEventsFromOrganisationId(
                            request.OrganisationId,
                            request.OrganisationStatusId,
                            DateTime.Now);
                    }
                }
            }

            if (auditData.FieldChanges.Any(x => x.FieldChanged == AuditLogField.RemovedReason))
            {
                success = await _updateOrganisationRepository.UpdateRemovedReason(request.OrganisationId,
                                                                                  request.RemovedReasonId, request.UpdatedBy);
            }

            if (success && auditData.FieldChanges.Any(x => x.FieldChanged == AuditLogField.StartDate))
            {
                success = await _updateOrganisationRepository.UpdateStartDate(request.OrganisationId, DateTime.Today, request.UpdatedBy);
            }

            if (success)
            {
                return(await _updateOrganisationRepository.WriteFieldChangesToAuditLog(auditData));
            }

            return(await Task.FromResult(false));
        }