public ActionResult <Environment> Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Environment env = _envService.FindById(id);

            if (env != null)
            {
                _context.Environments.Remove(env);
                var retorno = _envService.SaveOrUpdate(env);

                return(Ok(retorno));
            }
            else
            {
                object res = null;
                NotFoundObjectResult notfound = new NotFoundObjectResult(res);
                notfound.StatusCode = 404;

                notfound.Value = "O Environment " + id + " não foi encontrado!";
                return(NotFound(notfound));
            }
        }
Example #2
0
        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());
            }
        }