public IOWLevel InsertOrUpdateLevel(IOWLevel input) { // Validate information // Make sure criticality is in the proper range input.Criticality = input.Criticality.Clamp(minCriticality, maxCriticality); if (input.MetricType == MetricType.PercentLimitsInDeviation) input.GoodDirection = Direction.Low; else if (input.MetricType == MetricType.PercentTimeInDeviation) input.GoodDirection = Direction.Low; // If the good direction is down, then the warning level must be below the error level (going down: error, warning, good) if (input.GoodDirection == Direction.Low) { input.ErrorLevel = input.ErrorLevel.Clamp(minimumLevel, maximumLevel); input.WarningLevel = input.WarningLevel.Clamp(minimumLevel, input.ErrorLevel); } // If the good direction is up, then the warning level must be above the error level (going down: good, warning, error) else if (input.GoodDirection == Direction.High) { input.ErrorLevel = input.ErrorLevel.Clamp(minimumLevel, maximumLevel); input.WarningLevel = input.WarningLevel.Clamp(input.ErrorLevel, maximumLevel); } // Ignore other settings for good direction // Look to see if a level already exists. If so, fetch it. IOWLevel level = _iowLevelRepository.FirstOrDefault(input.Id); if( level == null ) level = _iowLevelRepository.FirstOrDefault(p => p.Name == input.Name ); if (level != null) { // Found a record. Use everything from the input except the Id and tenant. // level.TenantId = input.TenantId; level.Name = input.Name; level.Description = input.Description; level.Criticality = input.Criticality; level.ResponseGoal = input.ResponseGoal; level.MetricGoal = input.MetricGoal; level.MetricType = input.MetricType; level.GoodDirection = input.GoodDirection; level.WarningLevel = input.WarningLevel; level.ErrorLevel = input.ErrorLevel; } else { // Did not find a record. Use the input as is. level = input; } return _iowLevelRepository.InsertOrUpdate(level); }
public LevelDto UpdateLevel(UpdateLevelInput input) { //We can use Logger, it is defined in ApplicationService base class. Logger.Info("Updating an IOW level for input: " + input.Name); // All assets belong to a tenant. If not specified, put them in the default tenant. int tenantid = (AbpSession.TenantId != null) ? (int)AbpSession.TenantId : 1; IOWLevel level = new IOWLevel { Name = input.Name, Description = !string.IsNullOrEmpty(input.Description) ? input.Description : input.Name, Criticality = input.Criticality, ResponseGoal = !string.IsNullOrEmpty(input.ResponseGoal) ? input.ResponseGoal : "", MetricGoal = !string.IsNullOrEmpty(input.MetricGoal) ? input.MetricGoal : "", MetricType = input.MetricType, GoodDirection = input.GoodDirection, WarningLevel = input.WarningLevel, ErrorLevel = input.ErrorLevel, TenantId = tenantid }; if (input.Id.HasValue) level.Id = input.Id.Value; level = _iowManager.InsertOrUpdateLevel(level); return level.MapTo<LevelDto>(); }