private async void DeleteRelease(ReleaseDeletedEvent release) { var updatedEstablishment = new Establishment() { Id = release.Id }; await releaseService.RemoveById(updatedEstablishment.Id); }
public async Task <ActionResult <ResponseDetails> > Delete(string id) { if (id == null || !Regex.IsMatch(id, "^[0-9a-fA-F]{24}$")) { string errorMessage = responseMessages.IncorretIdFormat; logger.LogInformation("Error: " + errorMessage); return(httpResponseHelper.ErrorResponse(errorMessage, 400)); } try { logger.LogInformation("Trying to get a release with given id"); var actualRelease = await releasesService.GetById(id); if (actualRelease == null) { string errorMessage = responseMessages.NotFoundGivenId.Replace("$", "lançamento"); logger.LogInformation("Error: " + errorMessage); return(httpResponseHelper.ErrorResponse(errorMessage, 404)); } var deleteResult = await releasesService.RemoveById(id); if (!deleteResult.IsAcknowledged) { string errorMessage = responseMessages.CantRemove; logger.LogInformation("Error: " + errorMessage); return(httpResponseHelper.ErrorResponse(errorMessage, 406)); } //Send to RabbitMQ to event handler observer pattern Emitter.ReleaseDeleted(id, rabbitConnector.ConnectionString); } catch (Exception ex) { logger.LogInformation($"Message: {ex.Message}"); logger.LogTrace($"Stack Trace: {ex.StackTrace}"); throw; } logger.LogInformation("Action DELETE for /api/releases returns 200"); return(Ok(new ResponseDetails() { Message = responseMessages.DeletedSuccess.Replace("$", "lançamento"), StatusCode = 200 })); }