Beispiel #1
0
        public async Task Handle(DeleteCategoryProcessStartedEvent categoryDeletedEvent)
        {
            var canDeleteResult = await _deleteValidator.CanDelete(categoryDeletedEvent.Id);

            if (!canDeleteResult.Success)
            {
                var failedEvent = new DeletingCategoryFailedEvent(categoryDeletedEvent.Id, canDeleteResult.Status, categoryDeletedEvent.CorrelationId);
                await this.SaveAndDispatchEvent(categoryDeletedEvent.Id, failedEvent);

                _logger.LogProgress(OperationStatus.Failed, "Category is used", categoryDeletedEvent.CorrelationId);
                return;
            }

            var deleteResult = await _categoryIndexer.Delete(categoryDeletedEvent.Id);

            if (!deleteResult.Success)
            {
                var failedEvent = new DeletingCategoryFailedEvent(categoryDeletedEvent.Id, CategoryModificationStatus.UnexpectedProblem, categoryDeletedEvent.CorrelationId);
                await this.SaveAndDispatchEvent(categoryDeletedEvent.Id, failedEvent);

                _logger.LogProgress(OperationStatus.Failed, $"Problem occured during saving category {categoryDeletedEvent.Id}", categoryDeletedEvent.CorrelationId);
            }

            var successEvent = new CategoryDeletedEvent(categoryDeletedEvent.Id, categoryDeletedEvent.CorrelationId);

            _logger.LogProgress(OperationStatus.Finished, string.Empty, categoryDeletedEvent.CorrelationId);
            await this.SaveAndDispatchEvent(categoryDeletedEvent.Id, successEvent);
        }
Beispiel #2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, HttpMethods.Get, Route = "category/delete/{id:guid}")] HttpRequest req,
            string id)
        {
            var canBeDeleted = await _deleteValidator.CanDelete(id);

            if (!canBeDeleted.Success)
            {
                return(new BadRequestResult());
            }

            return(new NoContentResult());
        }