private void PublishEvent(int objectId) { var integrationEvent = new ObjectDeletedIntegrationEvent { Id = Guid.NewGuid(), ObjectId = objectId, DeletedAtUtc = DateTime.UtcNow, OccuredAt = DateTime.UtcNow }; _eventBus.Publish(integrationEvent); }
public async Task <CommandResult> AuthorizedDelete(DeleteObjectDto objectDto) { if (objectDto is null) { return(new CommandResult(new ErrorMessage { ErrorCode = "CATALOG.OBJECT.DELETE.NULL", Message = "Please send a valid data", StatusCode = System.Net.HttpStatusCode.BadRequest })); } var objectToDelete = _objectRepository.Get(objectDto.ObjectId); if (objectToDelete is null || objectToDelete.ObjectStatus != ObjectStatus.Available) { return(new CommandResult(new ErrorMessage { ErrorCode = "CATALOG.OBJECT.DELETE.NOTFOUND", Message = "The obect you are trying to delete does not exists", StatusCode = System.Net.HttpStatusCode.BadRequest })); } objectToDelete.ObjectStatus = ObjectStatus.Deleted; try { await _objectRepository.SaveChangesAsync(); var integrationEvent = new ObjectDeletedIntegrationEvent { Id = Guid.NewGuid(), ObjectId = objectToDelete.OfferedObjectId, DeletedAtUtc = DateTime.UtcNow, OccuredAt = DateTime.UtcNow }; _eventBus.Publish(integrationEvent); return(new CommandResult()); } catch (Exception e) { _logger.LogError(e, $"There were a problem deleting the object:{objectDto.ObjectId}"); return(new CommandResult(new ErrorMessage { ErrorCode = "CATALOG.OBJECT.DELETE.INTERNAL.ERROR", Message = "There were an error deleting your object", StatusCode = System.Net.HttpStatusCode.InternalServerError })); } }