public ActionResult <ErrorOccurrenceDTO> Post([FromBody] ErrorOccurrenceDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Montando as fk's var level = _levelService.FindByIdLevel(value.LevelId); var env = _environmentService.FindById(value.EnvironmentId); if (level != null && env != null) { var errorOcurrence = new ErrorOccurrence() { Title = value.Title, RegistrationDate = DateTime.Now, Origin = value.Origin, Filed = false, Details = value.Details, IdEvent = value.EventId, EnvironmentId = env.Id, LevelId = level.IdLevel, Username = value.Username, }; var registryError = _erroService.SaveOrUpdate(errorOcurrence); if (registryError != null) { return(Ok("Ocorrencia cadastrada com sucesso!")); } else { object res = null; NotFoundObjectResult notfound = new NotFoundObjectResult(res); notfound.StatusCode = 400; notfound.Value = "Erro ao registrar Ocorrencia!"; return(NotFound(notfound)); } } else { object res = null; NotFoundObjectResult notfound = new NotFoundObjectResult(res); notfound.StatusCode = 404; if (level == null) { } if (env == null) { notfound.Value = "O Environment informado não foi encontrado!"; return(NotFound(notfound)); } return(NotFound()); } }
public ActionResult <Level> Delete(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Level level = _levelService.FindByIdLevel(id); if (level != null) { _context.Levels.Remove(level); var retorno = _levelService.SaveOrUpdate(level); return(Ok(retorno)); } else { object res = null; NotFoundObjectResult notFound = new NotFoundObjectResult(res); notFound.StatusCode = 404; notFound.Value = "O Level " + id + " não foi encontrado!"; return(NotFound(notFound)); } }