コード例 #1
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());
            }
        }
コード例 #2
0
        public ActionResult <ErrorOccurrence> FileErrorOccurrence([FromBody] ErrorOccurrenceDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_service.ConsultErrorOccurrenceById(value.ErrorOccurrenceId) == null)
            {
                return(BadRequest("400 BadRequest: ErrorOccurence does not exists."));
            }

            return(Ok(_mapper.Map <ErrorOccurrenceDTO>(_service.FileErrorOccurrence(_mapper.Map <ErrorOccurrence>(value)))));
        }
コード例 #3
0
        public ActionResult <ErrorOccurrence> PostErrorOccurrence([FromBody] ErrorOccurrenceDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_userService.UserExists(value.UserId))
            {
                return(BadRequest("400 BadRequest: User does not exists."));
            }

            if (!_errorService.ErrorExists(value.ErrorId))
            {
                return(BadRequest("400 BadRequest: Error does not exists."));
            }

            if (!_situationService.SituationExists(value.SituationId))
            {
                return(BadRequest("400 BadRequest: Situation does not exists."));
            }

            return(Ok(_mapper.Map <ErrorOccurrenceDTO>(_service.RegisterOrUpdateErrorOccurrence(_mapper.Map <ErrorOccurrence>(value)))));
        }