public async Task Handle(MessageEvent messageEvent)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var messageName = messageEvent.getStringProperty("messageName");
                // document uploaded event
                if (messageName.Equals("document-uploaded"))
                {
                    ContentDocumentMessage contentDocumentMessage;
                    try
                    {
                        contentDocumentMessage = GetContentDocumentMessage(messageEvent);
                        if (contentDocumentMessage == null)
                        {
                            _logger.LogWarning("Content Document Message is null. Aborting Content Message Handling");
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "An error occurred while getting content document message");
                        return;
                    }
                    var pathElements = contentDocumentMessage.Path.Trim('/').Split("/");
                    if (pathElements.Count() < 3)
                    {
                        return;
                    }
                    string applicationNumber = pathElements[1].ToString();
                    string documentId        = pathElements[2].ToString();
                    if (string.IsNullOrEmpty(documentId))
                    {
                        return;
                    }
                    List <int> documentIds = new List <int>()
                    {
                        Convert.ToInt32(documentId)
                    };

                    UpdateDocumentStatus(applicationNumber, documentIds, contentDocumentMessage);
                }

                // document deleted event
                if (messageName.Equals("document-deleted"))
                {
                    ContentDocumentMessage contentDocumentMessage = GetContentDocumentMessage(messageEvent);

                    var pathElements = contentDocumentMessage.Path.Trim('/').Split("/");
                    if (pathElements.Count() < 3)
                    {
                        return;
                    }
                    string applicationNumber = pathElements[1].ToString();
                    string documentId        = pathElements[2].ToString();

                    if (string.IsNullOrEmpty(documentId))
                    {
                        return;
                    }
                    List <int> documentIds = new List <int>()
                    {
                        Convert.ToInt32(documentId)
                    };
                    var document = _applicationDocumentRepository.GetApplicationDocumentsForIds(documentIds)?.FirstOrDefault();
                    if (document != null)
                    {
                        if (document.ApplicationNumber == applicationNumber)
                        {
                            var folderHasItems = await FolderHasItems(contentDocumentMessage.Path);

                            if (!folderHasItems)
                            {
                                contentDocumentMessage.FilingPurpose = DocumentStatus.EmptyEnum;
                                UpdateDocumentStatus(applicationNumber, documentIds, contentDocumentMessage);
                            }
                            else
                            {
                                _logger.LogInformation("Folder with path {Path} has items", contentDocumentMessage.Path);
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        _logger.LogError("An error occurred while trying to get app document for {ids}", documentIds);
                        return;
                    }
                }
            }
        }
        private void UpdateDocumentStatus(string applicationNumber, List <int> documentIds, ContentDocumentMessage contentDocumentMessage)
        {
            var updateApplicationDocumentsStatusCommand = new UpdateApplicationDocumentsStatusCommand
            {
                ApplicationId = long.Parse(applicationNumber),
                DocumentIds   = documentIds,
                Status        = contentDocumentMessage.FilingPurpose
            };

            var updateDocumentStatusCommand = new IdentifiedCommand <UpdateApplicationDocumentsStatusCommand, bool?>(updateApplicationDocumentsStatusCommand, new Guid());

            _mediator.Send(updateDocumentStatusCommand).Wait();
        }