public LogErrorOccurrence RegisterOrUpdateErrorOccurrence(LogErrorOccurrence errorOccurrence)
        {
            var state = errorOccurrence.ErrorId == 0 ? EntityState.Added : EntityState.Modified;

            _context.LogErrorOccurrence.Add(errorOccurrence);
            _context.SaveChanges();

            return(errorOccurrence);
        }
Ejemplo n.º 2
0
        public ActionResult <LogErrorOccurrenceDTO> PutErrorOccurrence(int id, LogErrorOccurrence errorOccurrence)
        {
            if (id != errorOccurrence.ErrorId)
            {
                return(BadRequest());
            }

            try
            {
                return(Ok(_mapper.Map <LogErrorOccurrenceDTO>(_service.RegisterOrUpdateErrorOccurrence(errorOccurrence))));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_service.ErrorOccurrenceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
        public LogErrorOccurrence DeleteErrorOccurrence(LogErrorOccurrence errorOccurrence)
        {
            if (//_context.Users.Any(u => u.UserId == errorOccurrence.UserId) &&
                _context.LogErrorOccurrence.Any(e => e.ErrorId == errorOccurrence.ErrorId) &&
                _context.Situations.Any(s => s.SituationId == errorOccurrence.SituationId))
            {
                var state = errorOccurrence.ErrorId == 0 ? EntityState.Added : EntityState.Modified;
                var FileErrorOccurrence = errorOccurrence.SituationId;

                if (_situationService.ConsultSituationByName("Arquivado") == null)
                {
                    return(null);
                }

                errorOccurrence.Situation   = _situationService.ConsultSituationByName("Apagado (Inativo)");
                errorOccurrence.SituationId = _situationService.ConsultSituationByName("Apagado (Inativo)").SituationId;

                _context.Entry(errorOccurrence).State = state;
                _context.SaveChanges();
            }

            return(errorOccurrence);
        }