Exemple #1
0
        public ThresholdDto Create(ThresholdDto input)
        {
            var thresholdQuery = _thresholdRepository.GetAll().Where(t => t.RuleName == input.RuleName);

            if ((thresholdQuery.Any()) && (thresholdQuery.FirstOrDefault().IsDeleted == true))
            {
                var entity = thresholdQuery.FirstOrDefault();
                entity.IsDeleted = false;
                var result_old = _thresholdRepository.Update(entity);
                CurrentUnitOfWork.SaveChanges();
                return(ObjectMapper.Map <ThresholdDto>(result_old));
            }
            if (thresholdQuery.Any())
            {
                throw new ApplicationException("threshold 已存在");
            }
            var fieldQuery = _fieldRepository.GetAll().Where(f => f.FieldName == input.FieldName);

            if (!fieldQuery.Any())
            {
                throw new ApplicationException("field 不存在");
            }

            var severityQuery = _severityRepository.GetAll().Where(s => s.SeverityName == input.SeverityName);

            if (!severityQuery.Any())
            {
                throw new ApplicationException("severity 不存在");
            }
            var field     = fieldQuery.FirstOrDefault();
            var severity  = severityQuery.FirstOrDefault();
            var threshold = new Threshold()
            {
                Field          = field,
                Operator       = input.Operator,
                RuleName       = input.RuleName,
                Severity       = severity,
                Id             = input.Id,
                ThresholdValue = input.ThresholdValue,
                Description    = input.Description
            };

            var result = _thresholdRepository.Insert(threshold);

            CurrentUnitOfWork.SaveChanges();
            return(ObjectMapper.Map <ThresholdDto>(result));
        }
 public Threshold Update(Threshold entity)
 {
     return(_thresholdRepositories.Update(entity));
 }